Major update to UI and bot code. Added config file.
It is now modular and can be used on any machine. Still TODO- - 420 Timer - SDR built into bot
This commit is contained in:
104
bot.py
104
bot.py
@@ -1,64 +1,74 @@
|
||||
import discord
|
||||
import sound
|
||||
import asyncio
|
||||
import datetime
|
||||
from discord.ext import commands
|
||||
|
||||
|
||||
DEVICE_NAME = "VoiceMeeter Output"
|
||||
BOT_TOKEN = 'OTE1MDY0OTk2OTk0NjMzNzI5.YaWKsA.Y9yaCGg_VXRL_qQVbs05vo7gSAc'
|
||||
# For Alex's use
|
||||
#async def bg_timer():
|
||||
# await bot.wait_until_ready()
|
||||
# channel = bot.get_channel(id=757379843792044102)
|
||||
# while not bot.is_closed():
|
||||
# guild = channel.guild
|
||||
# role_id = discord.utils.get(guild.roles, name='Superadmins').id
|
||||
# willie_time = ("04:20:00", "00:16:00")
|
||||
# print(guild.roles)
|
||||
# time_now = datetime.datetime.now()
|
||||
# time_now_str = f"{time_now.strftime('%H:%M')}:00"
|
||||
# print(role_id)
|
||||
# if 1: #time_now_str in willie_time:
|
||||
# await channel.send(f"<@{role_id}> hello")
|
||||
# print("yes")
|
||||
#
|
||||
# await asyncio.sleep(30)
|
||||
|
||||
|
||||
bot = commands.Bot(command_prefix='>')
|
||||
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))
|
||||
self.DEVICE_ID = int(device_id)
|
||||
self.DEVICE_NAME = str(device_name)
|
||||
self.BOT_TOKEN = str(bot_token)
|
||||
self.Devices_List = sound.query_devices().items()
|
||||
|
||||
async def bg_timer():
|
||||
await bot.wait_until_ready()
|
||||
channel = bot.get_channel(id=757379843792044102)
|
||||
while not bot.is_closed():
|
||||
guild = channel.guild
|
||||
role_id = discord.utils.get(guild.roles, name='Superadmins').id
|
||||
willie_time = ("04:20:00", "00:16:00")
|
||||
print(guild.roles)
|
||||
time_now = datetime.datetime.now()
|
||||
time_now_str = f"{time_now.strftime('%H:%M')}:00"
|
||||
print(role_id)
|
||||
if 1: #time_now_str in willie_time:
|
||||
await channel.send(f"<@{role_id}> hello")
|
||||
print("yes")
|
||||
self.add_commands()
|
||||
|
||||
await asyncio.sleep(30)
|
||||
def start_bot(self):
|
||||
self.run(self.BOT_TOKEN)
|
||||
|
||||
@bot.command()
|
||||
async def ping(ctx):
|
||||
await ctx.send('pong')
|
||||
def add_commands(self):
|
||||
@self.command()
|
||||
async def ping(ctx):
|
||||
await ctx.send('pong')
|
||||
|
||||
@bot.command()
|
||||
async def join(ctx):
|
||||
await bot.wait_until_ready()
|
||||
discord.opus.load_opus('./opus/libopus.dll')
|
||||
@self.command()
|
||||
async def join(ctx):
|
||||
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
|
||||
for device, index in sound.query_devices().items():
|
||||
print(index, device)
|
||||
if DEVICE_NAME in device:
|
||||
stream.change_device(index)
|
||||
break
|
||||
if discord.opus.is_loaded():
|
||||
stream = sound.PCMStream()
|
||||
channel = ctx.author.voice.channel
|
||||
|
||||
voice_connection = await channel.connect()
|
||||
voice_connection.play(discord.PCMAudio(stream))
|
||||
stream.change_device(self.DEVICE_ID)
|
||||
|
||||
else:
|
||||
await ctx.send("Opus won't load")
|
||||
voice_connection = await channel.connect()
|
||||
voice_connection.play(discord.PCMAudio(stream))
|
||||
|
||||
@bot.command()
|
||||
async def leave(ctx):
|
||||
await ctx.voice_client.disconnect()
|
||||
else:
|
||||
await ctx.send("Opus won't load")
|
||||
|
||||
@self.command()
|
||||
async def leave(ctx):
|
||||
await ctx.voice_client.disconnect()
|
||||
|
||||
#Enable below for 420 timer
|
||||
#bot.loop.create_task(bg_timer())
|
||||
bot.run(BOT_TOKEN)
|
||||
def check_device(self):
|
||||
for device, index in self.Devices_List:
|
||||
if int(index) == self.DEVICE_ID and str(device) == self.DEVICE_NAME:
|
||||
return True
|
||||
|
||||
# Testing fetch
|
||||
for device, index in self.Devices_List:
|
||||
if str(device) == self.DEVICE_NAME:
|
||||
self.DEVICE_ID = int(index)
|
||||
return True
|
||||
|
||||
else:
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user