From 2b560c84bb1d502e6a4704fe76d66b39c4e79e93 Mon Sep 17 00:00:00 2001 From: ElBe <90863907+ElBe-Plaq@users.noreply.github.com> Date: Wed, 14 Sep 2022 13:09:07 +0200 Subject: [PATCH] Update bot.py --- Bot/bot.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 5 deletions(-) diff --git a/Bot/bot.py b/Bot/bot.py index 7e40e65..a537628 100644 --- a/Bot/bot.py +++ b/Bot/bot.py @@ -2,7 +2,7 @@ Bot from The Guardians. © by ElBe. -Version: 0.1.3 +Version: 0.1.5 ''' #Imports @@ -75,6 +75,8 @@ class TheGuardiansBot(discord.Client): await asyncio.sleep(10) await client.change_presence(activity=discord.Game(name=' with The Guardians on 6b6t.')) await asyncio.sleep(10) + await client.change_presence(activity=discord.Game(name=f'Version {version}')) + await asyncio.sleep(10) if credits: await client.change_presence(activity=discord.Game(name=' programmed by ElBe.')) await asyncio.sleep(10) @@ -83,7 +85,58 @@ class TheGuardiansBot(discord.Client): logging.info(str(datetime.datetime.now().strftime('%d.%m.%Y %T')) + ' -- Bot resumed seesion.') print(functions.console.log('Bot resumed a session.')) - #Commands + async def on_interaction(self, interaction): + async def log(text: str): + '''Log a text and save it in the logfile and the console.''' + logging.info(str(datetime.datetime.now().strftime('%d.%m.%Y %T')) + ' -- ' + str(text)) + print(functions.console.log(str(text))) + + if interaction.type == discord.InteractionType.application_command: + command_name = str(interaction.data['name']) + print(str(interaction.data)) #DEBUG + await log('Command /' + command_name + ' was used by @' + str(interaction.user) + '.') + + if command_name == 'ping': + pingEmbed = discord.Embed(title='Ping', description='Ping of the bot in ms.') + pingEmbed.add_field(name='Latency: ', value=str(round(client.latency * 1000)) + ' ms', inline=False) + pingEmbed.set_thumbnail(url=client.user.avatar.url) + pingEmbed.set_footer(text='Bot made by ElBe for The Guardians.') + await interaction.response.send_message(embed=pingEmbed, ephemeral=True) + + if command_name == 'info': + infoEmbed = discord.Embed(title='Information', description='Informations about the bot.') + infoEmbed.add_field(name='Running on: ', value=str(platform.system()) + ' ' + str(platform.release()), inline=False) + infoEmbed.add_field(name='CPU usage: ', value=str(psutil.cpu_percent(2)) + '%', inline=False) + infoEmbed.add_field(name='Uptime: ', value=str(datetime.timedelta(seconds=int(round(time.time()-starttime)))), inline=False) + infoEmbed.set_thumbnail(url=client.user.avatar.url) + infoEmbed.set_footer(text='Bot made by ElBe for The Guardians.') + await interaction.response.send_message(embed=infoEmbed, ephemeral=True) + + if command_name == 'stop': + await log('Client stoped.') + exit() + + if command_name == 'help': + helpEmbed = discord.Embed(title='Help', description='Help for commands and the usage of the bot.') + helpEmbed.add_field(name='Ping', value='Shows the ping of the bot in ms.', inline=True) + helpEmbed.add_field(name='Info', value='Shows information about the bot.', inline=True) + helpEmbed.add_field(name='Help', value='Shows you help for commands and the usage of the bot.', inline=True) + helpEmbed.add_field(name='Kick', value='Kicks a member from the server.', inline=True) + helpEmbed.add_field(name='Ban', value='Bans a member from the server.', inline=True) + helpEmbed.add_field(name='Unban', value='Unbans a member from the server.', inline=True) + helpEmbed.add_field(name='more', value='For more help write a direct message to <@!745695237380243457>.', inline=False) + helpEmbed.set_thumbnail(url=client.user.avatar.url) + helpEmbed.set_footer(text='Bot made by ElBe for The Guardians.') + await interaction.response.send_message(embed=helpEmbed, ephemeral=True) + + if command_name == ' kick': + MISSING + + if command_name == 'ban': + MISSING + + if command_name == 'unban': + MISSING async def on_member_join(self, member): async def log(text: str): @@ -92,12 +145,12 @@ class TheGuardiansBot(discord.Client): print(functions.console.log(str(text))) if not str(member) == client.user: - channel = discord.utils.get(member.guild.text_channels, name="hi") + channel = discord.utils.get(member.guild.text_channels, name='hi') joinEmbed = discord.Embed(title='Welcome!', description='Hello <@!' + str(member.id) + f'>! \nThank you for joining {member.guild.name}!') joinEmbed.set_thumbnail(url=member.avatar.url) joinEmbed.set_footer(text='Bot made by ElBe for The Guardians.') await channel.send(embed=joinEmbed) - await member.add_roles(discord.utils.get(member.guild.roles, name="member")) + await member.add_roles(discord.utils.get(member.guild.roles, name='member')) await log('@' + str(member) + ' joined to ' + str(member.guild.name) + '.') async def on_member_remove(self, member): @@ -107,7 +160,7 @@ class TheGuardiansBot(discord.Client): print(functions.console.log(str(text))) if not str(member) == client.user: - channel = discord.utils.get(member.guild.text_channels, name="bye") + channel = discord.utils.get(member.guild.text_channels, name='bye') joinEmbed = discord.Embed(title='Goodbye!', description='<@!' + str(member.id) + f'> left {member.guild.name}.') joinEmbed.set_thumbnail(url=member.avatar.url) joinEmbed.set_footer(text='Bot made by ElBe for The Guardians.')