From 08f015d694f2aace7654f1fcbc514554c57289ad Mon Sep 17 00:00:00 2001 From: turtlebasket Date: Tue, 5 May 2020 23:20:50 -0700 Subject: [PATCH] add DBL API & move token --- bot.py | 21 ++++++++++++++++++--- requirements.txt | 1 + tokens.json | 4 ++++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 tokens.json diff --git a/bot.py b/bot.py index 6a95e8f..d713e47 100644 --- a/bot.py +++ b/bot.py @@ -10,13 +10,16 @@ import random import discord from discord.ext import commands from os import environ +import dbl from bot_utils import * -# I know, config parsing is ugly and bad, I'll get around to refactoring later TwT - with open('config.json', 'r') as json_file: config = json.load(json_file) +with open('tokens.json', 'r') as tokens_file: + tokens = json.load(tokens_file) + +# Feeling cute, might refactor later MUTE_VOTE_TIME = config["MUTE_VOTE_TIME"] MIN_MUTE_VOTERS = config["MIN_MUTE_VOTERS"] # should be 3 MUTE_TIME = config["MUTE_TIME"] # 10 mins @@ -52,6 +55,18 @@ async def status_loop(): await bot.change_presence(activity=discord.Game(name="Proletarian Uprising 2: Electric Boogaloo")) await asyncio.sleep(STATUS_LOOP) + +# top.gg API interaction handling (boilerplate); +class TopGG(commands.Cog): + """Handles interactions with the top.gg API""" + + def __init__(self, bot): + self.bot = bot + self.token = tokens["dbl_token"] + self.dblpy = dbl.DBLClient(self.bot, self.token, autopost=True) # refresh guild count every 30 mins + +bot.add_cog(TopGG(bot)) + @bot.event async def on_ready(): # await bot.change_presence(activity=discord.Game(name='{} servers | >>help'.format(len(bot.guilds)))) @@ -250,4 +265,4 @@ async def ban(ctx, target_user:discord.User): banning_users.remove(target_user) -bot.run(open("token.txt").read().strip()) +bot.run(tokens["bot_token"]) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index f4367ca..055696b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ discord.py >= 1.2.0 +dblpy >= 0.3.4 \ No newline at end of file diff --git a/tokens.json b/tokens.json new file mode 100644 index 0000000..a734464 --- /dev/null +++ b/tokens.json @@ -0,0 +1,4 @@ +{ + "bot_token": "", + "dbl_token": "" +} \ No newline at end of file