Browse Source

#40

feature/040
みてるぞ 8 hours ago
parent
commit
1c61d90662
1 changed files with 5 additions and 1 deletions
  1. +5
    -1
      main.py

+ 5
- 1
main.py View File

@@ -63,6 +63,7 @@ def main (


waiting_balloon = (False, '', '') waiting_balloon = (False, '', '')
last_flags_poll: float = 0 last_flags_poll: float = 0
traced_af_ids: list[int] = []


while True: while True:
now_m = time.monotonic () now_m = time.monotonic ()
@@ -77,13 +78,14 @@ def main (
deerjika.talk (waiting_balloon[1], waiting_balloon[2]) deerjika.talk (waiting_balloon[1], waiting_balloon[2])
waiting_balloon = (False, '', '') waiting_balloon = (False, '', '')


if now_m - last_flags_poll >= 10:
if now_m - last_flags_poll >= 1:
last_flags_poll = now_m last_flags_poll = now_m
log (f"balloon: { balloon.enabled }, snack: { snack_time.enabled }") log (f"balloon: { balloon.enabled }, snack: { snack_time.enabled }")
try: try:
DB.begin_transaction () DB.begin_transaction ()
answer_flags = (AnsweredFlag.where ('platform', Platform.YOUTUBE.value) answer_flags = (AnsweredFlag.where ('platform', Platform.YOUTUBE.value)
.where ('answered', False) .where ('answered', False)
.where_not_in ('id', traced_af_ids)
.get ()) .get ())
log (f"pending: { len (answer_flags) }") log (f"pending: { len (answer_flags) }")
if answer_flags: if answer_flags:
@@ -102,6 +104,8 @@ def main (
waiting_balloon = (True, query.content, answer.content) waiting_balloon = (True, query.content, answer.content)
answer_flag.answered = True answer_flag.answered = True
answer_flag.save () answer_flag.save ()
case _:
traced_af_ids.append (answer_flag.id)
DB.commit () DB.commit ()
except Exception as ex: except Exception as ex:
DB.rollback () DB.rollback ()


Loading…
Cancel
Save