-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore_cog.py
45 lines (34 loc) · 1.43 KB
/
core_cog.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
42
43
44
45
from datetime import datetime, timezone
import discord
from discord import app_commands
from discord.ext import commands
from bot import GwaffBot
from custom_logger import Logger
logger = Logger('gwaff.bot.core')
class Core_Cog(commands.Cog):
def __init__(self, bot: commands.Bot):
self.bot = bot
@app_commands.command(name="ping", description="Pong!")
async def ping(self, interaction: discord.Interaction):
now = datetime.now(timezone.utc)
msgtime = interaction.created_at
ping = (now - msgtime).total_seconds() * 2000.0
logger.info(f"Ping: {ping}")
await interaction.response.send_message(f"Pong!\n{round(ping)} ms",
ephemeral=True)
@app_commands.command(name="jobs", description="List all scheduled jobs")
async def list_jobs(self, interaction: discord.Interaction):
jobs = self.bot.scheduler.get_jobs()
job_str = "\n".join([f"{job.name:>30}: next run at {job.next_run_time}" for job in jobs])
await interaction.response.send_message(f"```{job_str}```", ephemeral=True)
@commands.Cog.listener()
async def on_ready(self):
await self.bot.send_message("I have rebooted!")
async def setup(bot: GwaffBot):
"""
Sets up the SpooncraftCog and adds it to the bot.
Args:
bot (GwaffBot): The bot instance.
"""
cog = Core_Cog(bot)
await bot.add_cog(cog, guilds=bot.guilds)