61 行
1.8 KiB
Python
61 行
1.8 KiB
Python
import pygame
|
|
from pygame.locals import *
|
|
import sys
|
|
import pytchat
|
|
import time
|
|
import random
|
|
from talk import Talk
|
|
|
|
|
|
YOUTUBE_ID: str = 'aq3QwuYz-KU'
|
|
|
|
|
|
class Main:
|
|
@classmethod
|
|
def main (cls) -> None:
|
|
pygame.init ()
|
|
screen: pygame.Surface = pygame.display.set_mode ((1024, 768))
|
|
balloon = pygame.transform.scale (pygame.image.load ('talking.png'),
|
|
(1024, 384))
|
|
pygame.mixer.init (frequency = 44100)
|
|
noon = pygame.mixer.Sound ('noon.wav')
|
|
|
|
live_chat = pytchat.create (video_id = YOUTUBE_ID)
|
|
|
|
user_font = pygame.font.SysFont ('notosansjpregular', 32,
|
|
italic = True)
|
|
nizika_font = pygame.font.SysFont ('07にくまるフォント', 50)
|
|
|
|
while (True):
|
|
screen.fill ((0, 255, 0))
|
|
|
|
if live_chat.is_alive ():
|
|
messages: list[str] = [c.message
|
|
for c in live_chat.get ().items]
|
|
|
|
if messages:
|
|
message: str = random.choice (messages)
|
|
answer: str = Talk.main (message)
|
|
|
|
screen.blit (balloon, (0, 0))
|
|
screen.blit (user_font.render ('> ' + message, True,
|
|
(0, 0, 0)),
|
|
(120, 70))
|
|
screen.blit (nizika_font.render (
|
|
answer, True, (192, 0, 0)), (100, 150))
|
|
|
|
noon.play ()
|
|
|
|
pygame.display.update ()
|
|
|
|
for event in pygame.event.get ():
|
|
if event.type == QUIT:
|
|
pygame.quit ()
|
|
sys.exit ()
|
|
|
|
time.sleep (10)
|
|
|
|
if __name__ == '__main__':
|
|
Main.main ()
|
|
|