2022-03-23 19:45:22 -04:00
|
|
|
import os
|
2022-03-23 19:27:00 -04:00
|
|
|
import discord
|
|
|
|
from discord.ext.commands import Bot
|
|
|
|
|
2022-03-23 19:45:22 -04:00
|
|
|
bot_version = os.environ['version']
|
2022-03-23 20:13:18 -04:00
|
|
|
print('radiobot ' + bot_version + ' starting')
|
2022-03-23 19:27:00 -04:00
|
|
|
|
2022-03-23 19:59:21 -04:00
|
|
|
bot_token = os.environ['token']
|
2022-03-23 19:56:13 -04:00
|
|
|
|
2022-03-23 19:27:00 -04:00
|
|
|
client = Bot(command_prefix="!")
|
2022-03-23 19:59:21 -04:00
|
|
|
|
2022-03-23 19:27:00 -04:00
|
|
|
isPlaying = False
|
2022-03-23 20:13:18 -04:00
|
|
|
class Radio(discord.Client):
|
2022-03-23 19:27:00 -04:00
|
|
|
|
|
|
|
async def on_ready(self):
|
|
|
|
print('Logged on as', self.user)
|
|
|
|
|
|
|
|
async def on_message(self, message):
|
|
|
|
# don't respond to ourselves
|
|
|
|
if message.author == self.user:
|
|
|
|
return
|
|
|
|
|
2022-03-23 20:13:18 -04:00
|
|
|
print ('<' + message.author.nick + '> ' + message.content)
|
|
|
|
|
|
|
|
if message.content == '!version':
|
2022-03-23 19:59:21 -04:00
|
|
|
await message.channel.send('] radiobot ' + bot_version)
|
2022-03-23 19:27:00 -04:00
|
|
|
|
|
|
|
@client.event
|
|
|
|
async def on_voice_state_update(self, member, before, after):
|
|
|
|
clients_before = len(before.channel.members)
|
|
|
|
|
|
|
|
# If nobody in the channel based on before, invoke join the channel
|
|
|
|
if clients_before == 0:
|
|
|
|
self.voiceChannel = await after.channel.connect()
|
|
|
|
|
|
|
|
# if after join channel members > 0, join the channel
|
|
|
|
if clients_before == 1:
|
|
|
|
print("gg")
|
|
|
|
await self.voiceChannel.disconnect()
|
|
|
|
|
2022-03-23 20:13:18 -04:00
|
|
|
client = Radio()
|
|
|
|
client.run(bot_token) # Get tokeun for this shit
|