diff --git a/.gitignore b/.gitignore index 8a22514..daa5fc1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /connection.py -/__pycache__ +__pycache__ /nizika_talking.wav /youtube.py /log.txt diff --git a/__init__.py b/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..d787271 --- /dev/null +++ b/mypy.ini @@ -0,0 +1,2 @@ +[mypy] +disable_error_code = import-untyped diff --git a/nizika_ai b/nizika_ai index 662b7d6..ed10855 160000 --- a/nizika_ai +++ b/nizika_ai @@ -1 +1 @@ -Subproject commit 662b7d69de66bb8c09f8297817449179166c0f3d +Subproject commit ed1085535e2c05b04f31b0d0ff933152b47bf5b5 diff --git a/test.py b/test.py index 302b0d9..8edc2c4 100644 --- a/test.py +++ b/test.py @@ -10,21 +10,22 @@ from typing import Callable, TypedDict import cv2 import emoji -import ephem # type: ignore +import ephem import pygame import pygame.gfxdraw -import pytchat # type: ignore +import pytchat import requests from cv2 import VideoCapture -from ephem import Moon, Observer, Sun # type: ignore +from ephem import Moon, Observer, Sun 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 # type: ignore -from pytchat.processors.default.processor import Chat # type: ignore +from pytchat.core.pytchat import PytchatCore +from pytchat.processors.default.processor import Chat from common_module import CommonModule +from nizika_ai.config import DB from nizika_ai.models import Answer, AnsweredFlag, Query, User from nizika_ai.consts import AnswerType, Character, GPTModel, Platform, QueryType @@ -58,16 +59,18 @@ def main ( if event.type == pygame.QUIT: pygame.quit () sys.exit () - answer_flags = (AnsweredFlag.where ('platform', Platform.YOUTUBE.value) - .where ('answered', False) - .get ()) if not balloon.enabled: + answer_flags = (AnsweredFlag.where ('platform', Platform.YOUTUBE.value) + .where ('answered', False) + .get ()) if answer_flags: - answer_id: int = random.choice (answer_flags).answer_id - answer = Answer.find (answer_id) + answer_flag = random.choice (answer_flags) + answer = Answer.find (answer_flag.answer_id) if answer.answer_type == AnswerType.YOUTUBE_REPLY.value: query = Query.find (answer.query_id) balloon.talk (query.content, answer.content) + answer_flag.answered = True + answer_flag.save () add_query (broadcast) game.redraw () @@ -705,6 +708,7 @@ def add_query ( chat = broadcast.fetch_chat () if chat is None: return + DB.begin_transaction () chat.message = emoji.emojize (chat.message) message: str = chat.message user = (User.where ('platform', Platform.YOUTUBE.value) @@ -726,6 +730,8 @@ def add_query ( query.sent_at = datetime.now () query.answerd = False query.save () + DB.commit () + if __name__ == '__main__': main ()