-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathautomessage.py
41 lines (32 loc) · 1.2 KB
/
automessage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# This plugin handles automatic sending of messages in channels on a specific time.
import hikari
import lightbulb
from lightbulb.ext import tasks
from apscheduler.triggers.cron import CronTrigger
import main
from scheduler import scheduler
plugin = lightbulb.Plugin("Auto Message", include_datastore=True)
async def send_message(channel_id: int, content: str):
await plugin.bot.cache.get_guild_channel(channel_id).send(content)
def load(bot):
bot.add_plugin(plugin)
main.load_plugin_configs("automessage", plugin.d)
plugin.d["tasks"] = []
for server in plugin.d["config"]:
for task in plugin.d["config"][server]:
task = scheduler.add_job(
send_message,
CronTrigger.from_crontab(task["crontab"]),
id=f"automessage_{server}_{task['channel']}_{task['message']}_{task['crontab']}",
replace_existing=True,
args=(
task["channel"],
task["message"],
),
misfire_grace_time=10,
)
plugin.d["tasks"].append(task)
def unload(bot):
for task in plugin.d["tasks"]:
task.remove()
bot.remove_plugin(plugin)