伊地知ニジカ放送局だぬ゛ん゛. https://www.youtube.com/@deerjika
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.8 KiB

  1. import pygame
  2. from pygame.locals import *
  3. import sys
  4. import pytchat
  5. import time
  6. import random
  7. from talk import Talk
  8. YOUTUBE_ID: str = 'aq3QwuYz-KU'
  9. class Main:
  10. @classmethod
  11. def main (cls) -> None:
  12. pygame.init ()
  13. screen: pygame.Surface = pygame.display.set_mode ((1024, 768))
  14. balloon = pygame.transform.scale (pygame.image.load ('talking.png'),
  15. (1024, 384))
  16. pygame.mixer.init (frequency = 44100)
  17. noon = pygame.mixer.Sound ('noon.wav')
  18. live_chat = pytchat.create (video_id = YOUTUBE_ID)
  19. user_font = pygame.font.SysFont ('notosansjpregular', 32,
  20. italic = True)
  21. nizika_font = pygame.font.SysFont ('07にくまるフォント', 50)
  22. while (True):
  23. screen.fill ((0, 255, 0))
  24. if live_chat.is_alive ():
  25. messages: list[str] = [c.message
  26. for c in live_chat.get ().items]
  27. if messages:
  28. message: str = random.choice (messages)
  29. answer: str = Talk.main (message)
  30. screen.blit (balloon, (0, 0))
  31. screen.blit (user_font.render ('> ' + message, True,
  32. (0, 0, 0)),
  33. (120, 70))
  34. screen.blit (nizika_font.render (
  35. answer, True, (128, 0, 0)), (100, 150))
  36. noon.play ()
  37. pygame.display.update ()
  38. for event in pygame.event.get ():
  39. if event.type == QUIT:
  40. pygame.quit ()
  41. sys.exit ()
  42. time.sleep (10)
  43. if __name__ == '__main__':
  44. Main.main ()