|
@@ -1,6 +1,7 @@ |
|
|
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 |
|
@@ -10,16 +11,18 @@ import cv2 |
|
|
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 |
|
|
|
|
|
|
|
|
pygame.init () |
|
|
pygame.init () |
|
|
|
|
|
|
|
@@ -29,16 +32,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 +54,11 @@ def main ( |
|
|
if event.type == pygame.QUIT: |
|
|
if event.type == pygame.QUIT: |
|
|
pygame.quit () |
|
|
pygame.quit () |
|
|
sys.exit () |
|
|
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 () |
|
|
game.redraw () |
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -132,6 +143,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 +335,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 +532,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 +656,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 () |