From 7289fe581206ee81ac2813f9b7bc1df678a06596 Mon Sep 17 00:00:00 2001 From: miteruzo Date: Sat, 21 Dec 2024 18:49:10 +0900 Subject: [PATCH] =?UTF-8?q?nizika=5Fai=20=E3=82=92=E3=81=84=E3=81=A3?= =?UTF-8?q?=E3=81=9F=E3=82=93=E9=99=A4=E5=A4=96=20(=20#31=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitmodules | 3 --- nizika_ai | 1 - test.py | 48 +++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 43 insertions(+), 9 deletions(-) delete mode 100644 .gitmodules delete mode 160000 nizika_ai diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 6cd7edd..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "nizika_ai"] - path = nizika_ai - url = https://git.miteruzo.com/miteruzo/nizika_ai diff --git a/nizika_ai b/nizika_ai deleted file mode 160000 index 3ca5f7c..0000000 --- a/nizika_ai +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 3ca5f7c83f5f23ece55de18d626aca3f4648502b diff --git a/test.py b/test.py index 0fc6a08..1d009fc 100644 --- a/test.py +++ b/test.py @@ -1,6 +1,7 @@ from __future__ import annotations import math +import random import sys from datetime import datetime, timedelta from enum import Enum, auto @@ -10,16 +11,18 @@ import cv2 import ephem # type: ignore import pygame import pygame.gfxdraw -import pytchat +import pytchat # type: ignore from cv2 import VideoCapture from ephem import Moon, Observer, Sun # type: ignore from pygame import Rect, Surface from pygame.font import Font from pygame.mixer import Sound from pygame.time import Clock -from pytchat.core.pytchat import PytchatCore +from pytchat.core.pytchat import PytchatCore # type: ignore +from pytchat.processors.default.processor import Chat # type: ignore from common_module import CommonModule +from nizika_ai.models import Answer, AnsweredFlag, Query, User pygame.init () @@ -29,16 +32,19 @@ SYSTEM_FONT = pygame.font.SysFont ('notosanscjkjp', 24, bold = True) USER_FONT = pygame.font.SysFont ('notosanscjkjp', 32, italic = True) DEERJIKA_FONT = pygame.font.SysFont ('07nikumarufont', 50) -PYTCHAT = pytchat.create (os.environ['BROADCAST_CODE']) - def main ( ) -> None: game = Game () Bg (game) Deerjika (game, DeerjikaPattern.RELAXED, x = CWindow.WIDTH * 3 / 4, y = CWindow.HEIGHT - 120) + Deerjika (game, DeerjikaPattern.RELAXED, x = CWindow.WIDTH * 3 / 4, y = CWindow.HEIGHT - 120) + Deerjika (game, DeerjikaPattern.RELAXED, x = CWindow.WIDTH * 3 / 4, y = CWindow.HEIGHT - 120) + Deerjika (game, DeerjikaPattern.RELAXED, x = CWindow.WIDTH * 3 / 4, y = CWindow.HEIGHT - 120) + Deerjika (game, DeerjikaPattern.RELAXED, x = CWindow.WIDTH * 3 / 4, y = CWindow.HEIGHT - 120) balloon = Balloon (game) CurrentTime (game, SYSTEM_FONT) + broadcast = Broadcast () try: Sound ('assets/bgm.mp3').play (loops = -1) except Exception: @@ -48,6 +54,11 @@ def main ( if event.type == pygame.QUIT: pygame.quit () sys.exit () + chat = broadcast.fetch_chat () + chat.message = emoji.emojize (chat.message) + message: str = chat.message + if where chat.author.channelId + # chat.author game.redraw () @@ -132,6 +143,7 @@ class Game: def __init__ ( self, ): + self.now = datetime.now () self.screen = pygame.display.set_mode ((CWindow.WIDTH, CWindow.HEIGHT)) self.clock = Clock () self.frame = 0 @@ -323,6 +335,9 @@ class Deerjika (GameObject): (self.width * self.scale, self.height * self.scale)) self.game.screen.blit (surface, surface.get_rect (center = (self.x, self.y))) super ().redraw () + self.x = random.randrange (CWindow.WIDTH) + self.y = random.randrange (CWindow.HEIGHT) + self.arg = math.radians (random.randrange (360)) class CurrentTime (GameObject): @@ -517,7 +532,7 @@ class Jojoko (GameObject): def redraw ( self, ) -> None: - if self.frame % 300 == 0: + if self.frame % (FPS * 3600) == 0: self.surface = self._get_surface () surface = pygame.transform.rotate (self.surface, -(90 + math.degrees (self.arg))) surface.set_colorkey ((0, 255, 0)) @@ -641,5 +656,28 @@ def get_surfaces_from_video ( return surfaces +class Broadcast: + chat: PytchatCore + + def __init__ ( + self, + ): + self.chat = pytchat.create (os.environ['BROADCAST_CODE']) + + def fetch_chat ( + self, + ) -> Chat | None: + if not self.chat.is_alive (): + return None + chats = self.chat.get ().items + if not chats: + return None + return random.choice (chats) + + +class Log: + ... + + if __name__ == '__main__': main ()