It is now modular and can be used on any machine. Still TODO- - 420 Timer - SDR built into bot
75 lines
2.3 KiB
Python
75 lines
2.3 KiB
Python
import discord
|
|
import sound
|
|
from discord.ext import commands
|
|
|
|
# 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)
|
|
|
|
|
|
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()
|
|
|
|
self.add_commands()
|
|
|
|
def start_bot(self):
|
|
self.run(self.BOT_TOKEN)
|
|
|
|
def add_commands(self):
|
|
@self.command()
|
|
async def ping(ctx):
|
|
await ctx.send('pong')
|
|
|
|
@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
|
|
|
|
stream.change_device(self.DEVICE_ID)
|
|
|
|
voice_connection = await channel.connect()
|
|
voice_connection.play(discord.PCMAudio(stream))
|
|
|
|
else:
|
|
await ctx.send("Opus won't load")
|
|
|
|
@self.command()
|
|
async def leave(ctx):
|
|
await ctx.voice_client.disconnect()
|
|
|
|
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
|
|
|
|
for device, index in self.Devices_List:
|
|
if str(device) == self.DEVICE_NAME:
|
|
self.DEVICE_ID = int(index)
|
|
return True
|
|
|
|
else:
|
|
return False
|