Skip to content

Commit

Permalink
Add .env
Browse files Browse the repository at this point in the history
remove vars.py
  • Loading branch information
YonLiud committed Apr 23, 2021
1 parent a8dcd17 commit 25bf299
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 33 deletions.
8 changes: 8 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -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"
65 changes: 44 additions & 21 deletions app.py
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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 = []
Expand All @@ -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 = []
Expand All @@ -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")
Expand All @@ -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)
12 changes: 0 additions & 12 deletions vars.py

This file was deleted.

0 comments on commit 25bf299

Please sign in to comment.