Merge branch 'main' of github.com:deflax/radiobot

This commit is contained in:
Daniel afx 2022-03-28 04:11:19 +03:00
commit 5926ef055a

69
main.py
View file

@ -26,45 +26,68 @@ isPlaying = False
@bot.event @bot.event
async def on_ready(): async def on_ready():
print('Logged in as') print('Logged in as ' + bot.user.name + ' #' + str(bot.user.id))
print(bot.user.name)
print(bot.user.id)
print('------')
# get channels # get channels
voice_channel = bot.get_channel(voice_channel_id) #voice_channel = bot.get_channel(voice_channel_id)
text_channel = bot.get_channel(text_channel_id) #text_channel = bot.get_channel(text_channel_id)
if not voice_channel: #if not voice_channel:
print("No voice channel " + voice_channel_id + " found!") # print("No voice channel " + voice_channel_id + " found!")
if not text_channel: #if not text_channel:
print("No text channel " + text_channel_id + " found!") # print("No text channel " + text_channel_id + " found!")
#voice_client = await bot.join_voice_channel(v_channel)
@bot.event @bot.event
async def on_message(ctx): async def on_message(message):
# don't respond to ourselves # don't respond to ourselves
if ctx.message.author == ctx.user: if message.author == bot.user:
return return
print ('<' + ctx.message.author.nick + '> ' + ctx.message.content) if not str(message.channel.id) == text_channel_id:
return
if ctx.message.content == '!version': print('<' + message.author.nick + '> ' + message.content)
await ctx.message.channel.send('] radiobot ' + bot_version + ' - python: ' + os.environ['PYTHON_VERSION'])
if message.content == '!version':
await message.channel.send('] radiobot ' + bot_version + ' - python ' + os.environ['PYTHON_VERSION'])
@bot.event @bot.event
async def on_voice_state_update(member, before, after): async def on_voice_state_update(member, before, after):
"""
Starts events when a user changes their voice state.
Such as connecting, disconnecting and moving between channels.
:type member: discord.Member
:type before: discord.VoiceState
:type after: discord.VoiceState
:param member: The member that changed their voice state.
:param before: The member as they were before the change.
:param after: The member as they are after the change.
:return:
"""
print('before: ' + str(before)) print('before: ' + str(before))
print('after: ' + str(after)) print('after: ' + str(after))
return return
clients_before = len(before.channel.members) clients_before = len(before.channel.members)
# If nobody in the channel based on before, invoke join the channel if member.bot:
if clients_before == 0: print("self event detection")
voiceChannel = await after.channel.connect() return
# if after join channel members > 0, join the channel if str(before.voice_channel) == "None":
if clients_before == 1: print(after.name + " joined " + str(after.voice_channel))
print("gg") if str(after.channel.id) == voice_channel_id:
print("Connecting to voice channel " + voice_channel_id)
voiceChannel = await after.channel.connect()
elif str(after.voice_channel) == "None":
print(after.name + " left " + str(before.voice_channel))
print("Disconnecting from voice channel " + voice_channel_id)
voiceChannel = await after.channel.connect()
await voiceChannel.disconnect() await voiceChannel.disconnect()
bot.run(login_token) # Get token for this shit # Start the bot with multiprocess compatiblity
if __name__ == "__main__":
try:
bot.loop.run_until_complete(bot.start(login_token))
finally:
bot.loop.close()