Skip to content

Commit

Permalink
⚗️ Scheduling test for Talkytrend
Browse files Browse the repository at this point in the history
  • Loading branch information
mraniki committed Jul 23, 2023
1 parent 59c3c58 commit 159ab79
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 38 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -144,8 +144,8 @@ major_tags = [
]
minor_tags = ["feat",
"🥚",":egg:",
"🚀",":rocket:",
"💄",":lipstick:",
"🚀",":rocket:",
"",":sparkles:",
]

Expand Down
33 changes: 16 additions & 17 deletions tt/plugins/default_plugins/talkytrend_plugin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os

from asyncz.schedulers.asyncio import AsyncIOScheduler
from asyncz.triggers import IntervalTrigger
from talkytrend import TalkyTrend

Expand All @@ -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"""
Expand All @@ -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(" ")
Expand All @@ -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
)
28 changes: 9 additions & 19 deletions tt/plugins/plugin_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import importlib
import pkgutil

from asyncz.schedulers.asyncio import AsyncIOScheduler

from tt.config import logger, settings


Expand All @@ -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 """
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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 {}

0 comments on commit 159ab79

Please sign in to comment.