Better credentials

This commit is contained in:
NikolajDanger
2020-08-09 13:02:04 +02:00
parent 9f683034c5
commit 84e332fa68
8 changed files with 56 additions and 49 deletions

View File

@ -1,11 +1,32 @@
import discord, os
import discord, os, finnhub
from discord.ext import commands
from funcs import logThis, makeFiles
commandPrefix = "!"
client = commands.Bot(command_prefix=commandPrefix, case_insensitive=True)
class Credentials():
def __init__(self):
with open("credentials.txt","r") as f:
data = f.read().splitlines()
self.token = data[0][10:].replace(" ","")
self.finnhubKey = data[1][16:].replace(" ","")
self.wordnikKey = data[2][16:].replace(" ","")
class Gwendolyn(commands.Bot):
def __init__(self):
self.credentials = Credentials()
self.finnhubClient = finnhub.Client(api_key = self.credentials.finnhubKey)
super().__init__(command_prefix=commandPrefix, case_insensitive=True)
# Creates the required files
makeFiles()
# Creates the Bot
client = Gwendolyn()
# Logs in
@client.event
@ -14,16 +35,7 @@ async def on_ready():
game = discord.Game("Some weeb shit")
await client.change_presence(activity=game)
# Loads and unloads cogs
@client.command()
async def load(ctx,extension):
client.load_extension(f"cogs.{extension}")
@client.command()
async def unload(ctx,extension):
client.unload_extension(f"cogs.{extension}")
# Logs when user sends a command
@client.event
async def on_command(ctx):
logThis(f"{ctx.message.author.display_name} ran {ctx.message.content}")
@ -37,16 +49,13 @@ async def on_command_error(ctx, error):
logThis(f"Something went wrong, {error}",str(ctx.message.channel.id))
await ctx.send("Something went wrong (error code 000)")
#Loads cogs
for filename in os.listdir("./cogs"):
if filename.endswith(".py"):
client.load_extension(f"cogs.{filename[:-3]}")
# Creates the required files
makeFiles()
# Gets secret bot token
with open("token.txt","r") as f:
token = f.read().replace("\n","")
# Runs the whole shabang
client.run(token)
try:
# Runs the whole shabang
client.run(client.credentials.token)
except:
logThis("Could not log in. Remember to write your bot token in the credentials.txt file")