diff --git a/pyproject.toml b/pyproject.toml index 0176cb385..6dbbe088d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -54,7 +54,7 @@ talkytrend = "^1.10.0" [tool.poetry.group.dev.dependencies] -#python-semantic-release = "^8.0.3" +python-semantic-release = "^8.0.3" ruff = "^0.0.280" [tool.ruff] @@ -144,8 +144,8 @@ major_tags = [ ] minor_tags = ["feat", "🥚",":egg:", - "🚀",":rocket:", "💄",":lipstick:", + "🚀",":rocket:", "✨",":sparkles:", ] diff --git a/tt/plugins/default_plugins/talkytrend_plugin.py b/tt/plugins/default_plugins/talkytrend_plugin.py index 9edf2b8bb..1e86e9bfc 100644 --- a/tt/plugins/default_plugins/talkytrend_plugin.py +++ b/tt/plugins/default_plugins/talkytrend_plugin.py @@ -1,5 +1,6 @@ import os +from asyncz.schedulers.asyncio import AsyncIOScheduler from asyncz.triggers import IntervalTrigger from talkytrend import TalkyTrend @@ -14,19 +15,14 @@ def __init__(self): super().__init__() self.enabled = settings.talkytrend_enabled if self.enabled: + self.scheduler = AsyncIOScheduler() self.trend = TalkyTrend() async def start(self): """Starts the TalkyTrend plugin""" if self.enabled: await self.plugin_schedule_task() - - # while True: - # logger.debug("scheduler setup") - # run_pending() - # time.sleep(10) - # async for message in self.trend.scanner(): - # await self.send_notification(message) + self.scheduler.start() async def stop(self): """Stops the TalkyTrend plugin""" @@ -36,15 +32,13 @@ async def send_notification(self, message): if self.enabled: await send_notification(message) - def should_handle(self, message): - """Returns plugin status""" - return self.enabled - async def handle_message(self, msg): """Handles incoming messages""" - if not self.enabled: - return - if msg.startswith(settings.bot_ignore): + # if not self.enabled: + # return + # if msg.startswith(settings.bot_ignore): + # return + if not self.should_handle(msg): return if msg.startswith(settings.bot_prefix): command, *args = msg.split(" ") @@ -62,13 +56,18 @@ async def handle_message(self, msg): function = command_mapping[command] await self.send_notification(f"{await function()}") + async def send_news(self): + """News""" + await self.send_notification(f"{await self.trend.fetch_key_feed()}") + async def plugin_schedule_task(self): """Handles task scheduling""" self.scheduler.add_task( - fn=self.trend.fetch_key_feed, - trigger=IntervalTrigger(minutes=4), + fn=self.send_news, + trigger=IntervalTrigger(minutes=60), max_instances=1, replace_existing=True, - coalesce=False, + coalesce=True, + is_enabled=True ) diff --git a/tt/plugins/plugin_manager.py b/tt/plugins/plugin_manager.py index ed547f408..bef110733 100644 --- a/tt/plugins/plugin_manager.py +++ b/tt/plugins/plugin_manager.py @@ -2,8 +2,6 @@ import importlib import pkgutil -from asyncz.schedulers.asyncio import AsyncIOScheduler - from tt.config import logger, settings @@ -12,7 +10,6 @@ class PluginManager: def __init__(self, plugin_directory=None): self.plugin_directory = plugin_directory or settings.plugin_directory self.plugins = [] - self.scheduler = None def load_plugins(self): """ Load plugins from directory """ @@ -68,12 +65,10 @@ class BasePlugin: ⚡ Base Plugin Class """ def __init__(self): - self.scheduler = AsyncIOScheduler() self.enabled = False # Default value - async def start(self): - self.scheduler.start() + pass async def stop(self): pass @@ -82,20 +77,18 @@ async def send_notification(self, message): pass def should_handle(self, message): - pass - - async def handle_message(self, msg): - pass + if not self.enabled: + return False + if message.startswith(settings.bot_ignore): + return False + return True async def plugin_schedule_task(self): pass - # def should_handle(self, message): - # if not self.enabled: - # return False - # if message.startswith(settings.bot_ignore): - # return False - # return True + + async def handle_message(self, msg): + pass # async def handle_message(self, msg): # if not self.should_handle(msg): @@ -109,6 +102,3 @@ async def plugin_schedule_task(self): # if command in command_mapping: # function = command_mapping[command] # await self.send_notification(f"{await function()}") - - # def get_command_mapping(self): - # return {} \ No newline at end of file