2 コミット

作成者 SHA1 メッセージ 日付
みてるぞ 98703409ef ぼちぼち ( #31 ) 2024-12-21 20:09:01 +09:00
みてるぞ 7289fe5812 nizika_ai をいったん除外 ( #31 ) 2024-12-21 18:51:44 +09:00
2個のファイルの変更49行の追加6行の削除
サブモジュール nizika_ai が更新されました: 3ca5f7c83f...8e1d305b4a
+48 -5
ファイルの表示
@@ -1,25 +1,30 @@
from __future__ import annotations from __future__ import annotations
import math import math
import random
import sys import sys
from datetime import datetime, timedelta from datetime import datetime, timedelta
from enum import Enum, auto from enum import Enum, auto
from typing import Callable, TypedDict from typing import Callable, TypedDict
import cv2 import cv2
import emoji
import ephem # type: ignore import ephem # type: ignore
import pygame import pygame
import pygame.gfxdraw import pygame.gfxdraw
import pytchat import pytchat # type: ignore
from cv2 import VideoCapture from cv2 import VideoCapture
from ephem import Moon, Observer, Sun # type: ignore from ephem import Moon, Observer, Sun # type: ignore
from pygame import Rect, Surface from pygame import Rect, Surface
from pygame.font import Font from pygame.font import Font
from pygame.mixer import Sound from pygame.mixer import Sound
from pygame.time import Clock 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 common_module import CommonModule
from nizika_ai.models import Answer, AnsweredFlag, Query, User
from nizika_ai.consts import Platform
pygame.init () pygame.init ()
@@ -29,16 +34,19 @@ SYSTEM_FONT = pygame.font.SysFont ('notosanscjkjp', 24, bold = True)
USER_FONT = pygame.font.SysFont ('notosanscjkjp', 32, italic = True) USER_FONT = pygame.font.SysFont ('notosanscjkjp', 32, italic = True)
DEERJIKA_FONT = pygame.font.SysFont ('07nikumarufont', 50) DEERJIKA_FONT = pygame.font.SysFont ('07nikumarufont', 50)
PYTCHAT = pytchat.create (os.environ['BROADCAST_CODE'])
def main ( def main (
) -> None: ) -> None:
game = Game () game = Game ()
Bg (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)
Deerjika (game, DeerjikaPattern.RELAXED, x = CWindow.WIDTH * 3 / 4, y = CWindow.HEIGHT - 120)
balloon = Balloon (game) balloon = Balloon (game)
CurrentTime (game, SYSTEM_FONT) CurrentTime (game, SYSTEM_FONT)
broadcast = Broadcast ()
try: try:
Sound ('assets/bgm.mp3').play (loops = -1) Sound ('assets/bgm.mp3').play (loops = -1)
except Exception: except Exception:
@@ -48,6 +56,14 @@ def main (
if event.type == pygame.QUIT: if event.type == pygame.QUIT:
pygame.quit () pygame.quit ()
sys.exit () sys.exit ()
chat = broadcast.fetch_chat ()
if chat is not None:
chat.message = emoji.emojize (chat.message)
message: str = chat.message
user = (User.where ('platform', Platform.YOUTUBE.value)
.where ('code', chat.author.channelId)
.get ())
# chat.author
game.redraw () game.redraw ()
@@ -132,6 +148,7 @@ class Game:
def __init__ ( def __init__ (
self, self,
): ):
self.now = datetime.now ()
self.screen = pygame.display.set_mode ((CWindow.WIDTH, CWindow.HEIGHT)) self.screen = pygame.display.set_mode ((CWindow.WIDTH, CWindow.HEIGHT))
self.clock = Clock () self.clock = Clock ()
self.frame = 0 self.frame = 0
@@ -323,6 +340,9 @@ class Deerjika (GameObject):
(self.width * self.scale, self.height * self.scale)) (self.width * self.scale, self.height * self.scale))
self.game.screen.blit (surface, surface.get_rect (center = (self.x, self.y))) self.game.screen.blit (surface, surface.get_rect (center = (self.x, self.y)))
super ().redraw () super ().redraw ()
self.x = random.randrange (CWindow.WIDTH)
self.y = random.randrange (CWindow.HEIGHT)
self.arg = math.radians (random.randrange (360))
class CurrentTime (GameObject): class CurrentTime (GameObject):
@@ -517,7 +537,7 @@ class Jojoko (GameObject):
def redraw ( def redraw (
self, self,
) -> None: ) -> None:
if self.frame % 300 == 0: if self.frame % (FPS * 3600) == 0:
self.surface = self._get_surface () self.surface = self._get_surface ()
surface = pygame.transform.rotate (self.surface, -(90 + math.degrees (self.arg))) surface = pygame.transform.rotate (self.surface, -(90 + math.degrees (self.arg)))
surface.set_colorkey ((0, 255, 0)) surface.set_colorkey ((0, 255, 0))
@@ -641,5 +661,28 @@ def get_surfaces_from_video (
return surfaces 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__': if __name__ == '__main__':
main () main ()