add sleep to avoid getting banned by the moderation bot

This commit is contained in:
Nils Büchner 2024-04-30 22:45:34 +02:00
parent 7b3fcdb9c1
commit c8229dd35f

View file

@ -45,9 +45,9 @@ class Queuebot(Plugin):
self.config.load_and_update() self.config.load_and_update()
self.flood_protection = FloodProtection() self.flood_protection = FloodProtection()
self.power_level_cache = {} self.power_level_cache = {}
#logger = logging.getLogger(self.id) logger = logging.getLogger(self.id)
#logger.setLevel(logging.INFO) logger.setLevel(logging.DEBUG)
#self.log = logger self.log = logger
if await self.resolve_room_aliases(): if await self.resolve_room_aliases():
self.poll_task = asyncio.create_task(self.poll_plugins()) self.poll_task = asyncio.create_task(self.poll_plugins())
self.log.info("Queuebot started") self.log.info("Queuebot started")
@ -204,6 +204,7 @@ class Queuebot(Plugin):
continue continue
notices = plugin_name.update() notices = plugin_name.update()
self.log.debug('update() function called on ' + str(plugin_name.name) + '.' + str(plugin_name.queue)) self.log.debug('update() function called on ' + str(plugin_name.name) + '.' + str(plugin_name.queue))
sent_count = 0
if notices: if notices:
self.log.debug(f"New notices available") self.log.debug(f"New notices available")
if await self.resolve_room_aliases(): if await self.resolve_room_aliases():
@ -215,7 +216,15 @@ class Queuebot(Plugin):
self.log.debug(f"Checking notices or {room_alias} ( {room_id} )") self.log.debug(f"Checking notices or {room_alias} ( {room_id} )")
if self.check_plugin_filter_mute(plugin_name=plugin_name.name,queue=plugin_name.queue, notice=notice[0], room_id=room_id, room_alias=room_alias): if self.check_plugin_filter_mute(plugin_name=plugin_name.name,queue=plugin_name.queue, notice=notice[0], room_id=room_id, room_alias=room_alias):
self.log.debug(f"new notice from {plugin_name.name}.{plugin_name.queue} to {room_alias}") self.log.debug(f"new notice from {plugin_name.name}.{plugin_name.queue} to {room_alias}")
self.log.debug(f"sent count: {sent_count}")
if sent_count >= 5:
self.log.debug(f"sent count reached: {sent_count} sleeping 60 secs")
if await asyncio.sleep(60):
sent_count = 0
await self.client.send_notice(room_id, notice[0]) await self.client.send_notice(room_id, notice[0])
else:
await self.client.send_notice(room_id, notice[0])
sent_count += 1
except Exception as e: except Exception as e:
self.log.debug(f"Error sending notice to {room_id}: {e}") self.log.debug(f"Error sending notice to {room_id}: {e}")
self.log.debug(traceback.format_exc()) self.log.debug(traceback.format_exc())