diff --git a/.env b/.env new file mode 100644 index 0000000..041af4e --- /dev/null +++ b/.env @@ -0,0 +1,8 @@ +WHITELIST_IDS = [477870815581569034, 271714102647324676, 347668690973753345] #? Place wanted whitelisted IDs in here as shown here + +TOKEN='TOKEN HERE' +SYNTAX='%>' +HOSTNAME="127.0.0.1" +USERNAME="remoteuser" +PASSWORD="Pa$$sw0rd" +DATABASE="mysql" \ No newline at end of file diff --git a/app.py b/app.py index 1b6a4cb..3ab4cb6 100644 --- a/app.py +++ b/app.py @@ -1,21 +1,23 @@ from columnar import columnar -import os import mysql.connector import discord -import vars -whitelisted = vars.WHITELIST_IDS -syntax = vars.SYNTAX -TOKEN = vars.TOKEN +from dotenv import dotenv_values + +vars = dotenv_values(".env") + +whitelisted = vars["WHITELIST_IDS"] +syntax = vars["SYNTAX"] +TOKEN = vars["TOKEN"] client = discord.Client() config = { - 'user': vars.USERNAME, - 'password': vars.PASSWORD, - 'host': vars.HOSTNAME, - 'database': vars.DATABASE, - 'raise_on_warnings': True + 'user': vars["USERNAME"], + 'password': vars["PASSWORD"], + 'host': vars["HOSTNAME"], + 'database': vars["DATABASE"], + 'raise_on_warnings': True } try: @@ -29,13 +31,16 @@ print("Exiting...") exit() + def exec(query): try: cursor.execute(query) return cursor.fetchall() except Exception as e: return str(e) - #return ['ERR', e] + # return ['ERR', e] + + @client.event async def on_message(message): data = [] @@ -44,21 +49,33 @@ async def on_message(message): return if message.content.startswith(syntax): if message.author.id not in whitelisted: - await message.channel.send(embed=discord.Embed(title="You are not authorized to use this bot", description='Please contact the bot hoster to add you to the whitelisted members list', color=discord.Color.red())) + await message.channel.send(embed=discord.Embed(title="You are not authorized to use this bot", + description='Please contact the bot hoster to add you to ' + 'the whitelisted members list', + color=discord.Color.red())) return - if message.content==syntax+"help": - await message.channel.send(embed=discord.Embed(title=client.user.name, description='https://devhints.io/mysql', color=discord.Color.purple())) + if message.content == syntax + "help": + await message.channel.send( + embed=discord.Embed(title=client.user.name, description='https://devhints.io/mysql', + color=discord.Color.purple())) return for word in message.content.split(): query += word + " " query = query.replace(syntax, '') - if(query == " "): - await message.channel.send(embed=discord.Embed(title=client.user.name, description='Arguments are missing for the query', color=discord.Color.red())) + + if query == " ": + await message.channel.send( + embed=discord.Embed(title=client.user.name, description='Arguments are missing for the query', + color=discord.Color.red())) return + output = exec(query) - if output == []: - msg = await message.channel.send(embed=discord.Embed(description="Empty list returned", color=discord.Color.blue())) + + if not output: + msg = await message.channel.send( + embed=discord.Embed(description="Empty list returned", color=discord.Color.blue())) return + if isinstance(output, list): for result in output: sub_data = [] @@ -69,9 +86,12 @@ async def on_message(message): # await message.channel.send(output) return else: - msg = await message.channel.send(embed=discord.Embed(title="MySQL Returned an Error", description=output, color=discord.Color.orange())) + msg = await message.channel.send( + embed=discord.Embed(title="MySQL Returned an Error", description=output, color=discord.Color.orange())) await msg.add_reaction("⚠️") return + + @client.event async def on_ready(): print(f"Bot | Status: Operational") @@ -80,6 +100,9 @@ async def on_ready(): print(f"Bot | Guilds: {len(client.guilds)}") print(f"Bot Configurations set to:\n{config}") print(f"Bot is ready to use") - #? Custom Activity - await client.change_presence(activity=discord.Activity(type=discord.ActivityType.listening, name="Syntax = " + syntax)) + # ? Custom Activity + await client.change_presence( + activity=discord.Activity(type=discord.ActivityType.listening, name="Syntax = " + syntax)) + + client.run(TOKEN) diff --git a/vars.py b/vars.py deleted file mode 100644 index 181bcaa..0000000 --- a/vars.py +++ /dev/null @@ -1,12 +0,0 @@ -#! Caution!!! -#! DO NOT RENAME THIS FILE - - -WHITELIST_IDS = [477870815581569034, 271714102647324676, 347668690973753345] #? Place wanted whitelisted IDs in here as shown here - -TOKEN = 'TOKEN HERE' #? Place token inside ' ' -SYNTAX ='%>' #? Place wanted syntax/prefix inside ' ' -HOSTNAME = "127.0.0.1" #? Your's server IP -USERNAME = "remoteuser" #? Remote user for the database -PASSWORD = "Pa$$sw0rd" #? Password for database user -DATABASE = "mysql" #? Database Name