Skip to content

Commit

Permalink
change scheduler for msg limit
Browse files Browse the repository at this point in the history
  • Loading branch information
f1delius committed Apr 29, 2024
1 parent 02903c0 commit 55e1ac4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
11 changes: 3 additions & 8 deletions src/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,9 @@ async def close(self, task: asyncio.Task) -> None:
logger.info("Bot closed!")


async def periodic_task(self,interval):
while self.scheduler:
await asyncio.sleep(interval)
await self.my_periodic_function()


async def my_periodic_function(self):
# This is the function you want to run periodically
async def periodic_task(self,interval=None):
# while self.scheduler:
# await asyncio.sleep(interval)
self.msg_limit = {}

# message_callback RoomMessageText event
Expand Down
22 changes: 19 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
from datetime import timedelta
import json
import os
from pathlib import Path
Expand Down Expand Up @@ -82,9 +83,24 @@ async def main():
lambda: asyncio.create_task(matrix_bot.close(sync_task)),
)
#3* 60 * 60 = 10800 seconds = 3 hours
# await asyncio.create_task(
# matrix_bot.periodic_task(10800)
# )
five_hours = timedelta(hours=3).total_seconds()

periodic_task_handle = loop.call_later(five_hours, lambda: asyncio.create_task(matrix_bot.periodic_task()))


def reschedule_periodic():

nonlocal periodic_task_handle

periodic_task_handle = loop.call_later(five_hours, lambda: asyncio.create_task(matrix_bot.periodic_task()))

reschedule_periodic() # Reschedule the next execution


# Start the periodic task for the first time

reschedule_periodic()

if matrix_bot.client.should_upload_keys:
await matrix_bot.client.keys_upload()

Expand Down

0 comments on commit 55e1ac4

Please sign in to comment.