Files
Discord-Radio-Bot/modules/WillieTimer/cog.py
Logan Cusano ba81d70669 Added new 'modules' folder for cogs (extensions)
Added 420 cog
Updated help menu
Updated README
2021-12-05 03:57:41 -05:00

71 lines
3.0 KiB
Python

import asyncio
import datetime
import discord
from discord.ext import commands
from discord.ext.tasks import loop
class WillieTimer(commands.Cog):
def __init__(self, bot, mention_group='Superadmins', channel_id=757379843792044102):
self.bot = bot
self.mention_group = str(mention_group)
self.channel_id = int(channel_id)
@loop(minutes=1)
async def bg_timer(self):
await self.bot.wait_until_ready()
seconds_until_next_minute = int(60 - int(datetime.datetime.now().strftime('%S')))
if not seconds_until_next_minute <= 2:
await asyncio.sleep(seconds_until_next_minute)
if datetime.datetime.now().strftime('%H:%M') in ("04:20", "16:20"):
print(f"It's {datetime.datetime.now().strftime('%H:%M:%S')}!")
channel = self.bot.get_channel(id=self.channel_id)
guild = channel.guild
role_id = discord.utils.get(guild.roles, name=self.mention_group)
print(role_id)
print(role_id.id)
await channel.send(f"<@&{role_id.id}> It's 4:20! It's time to light up!")
@commands.command(help="Use this command to start the background task to wait for 4:20",
brief="Starts the 4:20 clock")
async def start420(self, ctx, *, member: discord.Member = None):
member = member or ctx.author.display_name
await ctx.send(f"Thanks {member}, Willie will be in touch soon...")
self.bg_timer.start()
@commands.command(help="", brief="Stops the 4:20 clock")
async def stop420(self, ctx, *, member: discord.Member = None):
member = member or ctx.author.display_name
await ctx.send(f"Ok {member}, Willie will go back to writing music...")
self.bg_timer.stop()
@commands.command(help="Example '@Greada chchn 757379843792044102'",
brief="Change the channel the bot chats in at 4:20")
async def chchn(self, ctx, message, *, member: discord.Member = None):
member = member or ctx.author.display_name
try:
message = int(message)
if message and len(str(message)) == len(str(self.channel_id)):
self.channel_id = message
print(message)
except:
await ctx.send(f"{member}, {message} is not a valid channel ID, please try again")
pass
@commands.command(help="Example '@Greada chmtn 'Willies Friends'",
brief="Use this command to change who the bot mentions at 4:20")
async def chmtn(self, ctx, message, *, member: discord.Member = None):
member = member or ctx.author.display_name
try:
message = str(message)
if message and len(str(message)) == len(str(self.channel_id)):
self.mention_group = message
print(message)
except:
await ctx.send(f"{member}, {message} is not a valid role, please try again")
pass
def setup(bot: commands.Bot):
bot.add_cog(WillieTimer(bot))