Added 'Requirements.txt' for easy install.
Updated bot with 420 timer and better messaging.
This commit is contained in:
67
bot.py
67
bot.py
@@ -1,7 +1,9 @@
|
||||
import discord
|
||||
import sound
|
||||
import asyncio
|
||||
import datetime
|
||||
from discord.ext import commands
|
||||
|
||||
from discord.ext.tasks import loop
|
||||
# For Alex's use
|
||||
#async def bg_timer():
|
||||
# await bot.wait_until_ready()
|
||||
@@ -21,6 +23,64 @@ from discord.ext import commands
|
||||
# await asyncio.sleep(30)
|
||||
|
||||
|
||||
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()
|
||||
async def start420(self, ctx, *, member: discord.Member = None):
|
||||
member = member or ctx.author.display_name
|
||||
await ctx.send(f"Thanks {member.display_name}, Willie will be in touch soon...")
|
||||
self.bg_timer.start()
|
||||
|
||||
@commands.command()
|
||||
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()
|
||||
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()
|
||||
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
|
||||
|
||||
|
||||
class Bot(commands.Bot):
|
||||
def __init__(self, bot_token, device_id, device_name, command_prefix='>!'):
|
||||
commands.Bot.__init__(self, command_prefix=commands.when_mentioned_or(command_prefix))
|
||||
@@ -32,6 +92,7 @@ class Bot(commands.Bot):
|
||||
self.add_commands()
|
||||
|
||||
def start_bot(self):
|
||||
self.add_cog(WillieTimer(self))
|
||||
self.run(self.BOT_TOKEN)
|
||||
|
||||
def add_commands(self):
|
||||
@@ -40,13 +101,15 @@ class Bot(commands.Bot):
|
||||
await ctx.send('pong')
|
||||
|
||||
@self.command()
|
||||
async def join(ctx):
|
||||
async def join(ctx, *, member: discord.Member = None):
|
||||
member = member or ctx.author.display_name
|
||||
await self.wait_until_ready()
|
||||
discord.opus.load_opus('./opus/libopus.dll')
|
||||
|
||||
if discord.opus.is_loaded():
|
||||
stream = sound.PCMStream()
|
||||
channel = ctx.author.voice.channel
|
||||
await ctx.send(f"Ok {member}, I'm joining {channel}")
|
||||
|
||||
stream.change_device(self.DEVICE_ID)
|
||||
|
||||
|
||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
discord~=1.7.3
|
||||
sounddevice~=0.4.3
|
||||
Reference in New Issue
Block a user