added a function for stopping the bot

Signed-off-by: SpagettiFisch <johmewu@gmail.com>
This commit is contained in:
SpagettiFisch 2024-06-12 18:59:54 +02:00
parent 3641acf94a
commit 8d0aa8b8af
4 changed files with 34 additions and 2 deletions

View file

@ -11,6 +11,7 @@ from discord.ext import slash
token = init.config().get_token()
domain = init.config().get_pterodactyl_domain()
apikey = init.config().get_pterodactyl_apikey()
guild_id = init.config().get_guild_id()
bot = slash.SlashBot(command_prefix='!', help_command=None)
# msg_opt = slash.Option(description="Dein Minecraft Name", , required=True)
@ -35,4 +36,9 @@ async def mcname(ctx:slash.Context):
"Gibt deinen aktuellen Minecraft Namen an"
await functions.cmdmcname(ctx)
@bot.slash_cmd(guild_id=guild_id, hidden=True)
async def shutdown(ctx:slash.Context):
"Will shutdown the bot if you are mighty enough."
await functions.cmdshutdown(ctx, bot)
bot.run(token)

View file

@ -58,6 +58,17 @@ async def cmdmcname(ctx:slash.Context):
else:
await ctx.respond('Du hast deinen Minecraftnamen noch nicht hinzugefügt. Nutze `/mc [name]` um ihn hinzuzufügen.', ephemeral=True)
async def cmdshutdown(ctx:slash.Context, bot):
if str(ctx.channel.id) == str(init.config().get_guild_admin_id()):
await ctx.respond('Logging out and initiating shutdown', ephemeral=True)
print('Start logging out')
await bot.logout()
bot.clear()
print('Log Out succesful\nExiting')
exit()
else:
await ctx.respond('You are not as mighty as you may think you are.')
async def syncWhitelist():
results = cur.execute("SELECT mcname, uuid, iswhitelisted FROM user")
results = cur.fetchall()

View file

@ -11,6 +11,8 @@ class config():
self.token = p['token']
self.pterodactyl_domain = p['pterodactyl_domain']
self.pterodactyl_apikey = p['pterodactyl_apikey']
self.guild_id = p['guild_id']
self.guild_admin_id = p['guild_admin_id']
def get_token(self):
return self.token
@ -18,6 +20,11 @@ class config():
return self.pterodactyl_domain
def get_pterodactyl_apikey(self):
return self.pterodactyl_apikey
def get_guild_id(self):
return self.guild_id
def get_guild_admin_id(self):
return self.guild_admin_id
con = sqlite3.connect('data/database.sqlite')
cur = con.cursor()

View file

@ -23,11 +23,17 @@ if not path.exists('config/config.json'):
pterodactyl_domain = input()
print("Bitte geben Sie den Pterodactyl API Key ein (optional):")
pterodactyl_api_key = input()
print("Bitte geben Sie die Guild ID ein:")
guild_id = input()
print("Bitte geben Sie die ID des Admin Channels ein:")
guild_admin_id = input()
jsonstructure['discord'].append({
'token': token,
'pterodactyl_domain': pterodactyl_domain,
'pterodactyl_apikey': pterodactyl_api_key
'pterodactyl_apikey': pterodactyl_api_key,
'guild_id': guild_id,
'guild_admin_id': guild_admin_id
})
elif input1.lower().strip() == 'n':
@ -35,7 +41,9 @@ if not path.exists('config/config.json'):
jsonstructure['discord'].append({
'token': 'Platzhalter',
'pterodactyl_domain': '',
'pterodactyl_apikey': ''
'pterodactyl_apikey': '',
'guild_id': '',
'guild_admin_id': ''
})
else: