More Documentation

This commit is contained in:
Adriene Hutchins 2020-03-02 02:01:28 -05:00
parent 997030587c
commit 38829722d5
2 changed files with 72 additions and 36 deletions

View file

@ -16,13 +16,16 @@ class BotList(commands.Cog, name='Bot List'):
"""Provides various utilities for handling BotList stuff."""
def __init__(self, bot):
# Main Stuff
self.bot = bot
self.request = bot.request
# Tokens
# List Tokens
self.dbl_token = bot.config['DBL']
self.dbots_token = bot.config['DBOTS']
self.bod_token = bot.config['BOD']
self.dblcom_token = bot.config['DBLCOM']
# top.gg clent
self.dbl_client = dbl.DBLClient(
self.bot, self.dbots_token)
@ -36,13 +39,18 @@ class BotList(commands.Cog, name='Bot List'):
dblcom_call = "https://discordbotlist.com/api"
responses = {}
# Calls
# bots.discord.gg
if self.dbots_token != '':
# Call Prereqs
dbots_call += f"/bots/{self.bot.user.id}/stats"
dbots_data = {'guildCount': len(self.bot.guilds)}
dbots_headers = {'Authorization': self.dbots_token}
async with self.request.post(dbots_call,
json=dbots_data,
# Call Handling
async with self.request.post(dbots_call,
json=dbots_data,
headers=dbots_headers) as resp:
resp_json = await resp.json()
print(resp_json)
@ -50,10 +58,14 @@ class BotList(commands.Cog, name='Bot List'):
# bots.ondiscord.xyz
if self.bod_token != '':
# Call Prereqs
bod_call += f"/bots/{self.bot.user.id}/guilds"
bod_data = {'guildCount': len(self.bot.guilds)}
bod_headers = {'Authorization': self.bod_token}
async with self.request.post(bod_call,
# Call Handling
async with self.request.post(bod_call,
json=bod_data,
headers=bod_headers) as resp:
resp_json = await resp.json()
@ -62,10 +74,14 @@ class BotList(commands.Cog, name='Bot List'):
# discordbotlist.com
if self.dblcom_token != '':
# Call Prereqs
dblcom_call += f"/bots/{self.bot.user.id}/stats"
dblcom_data = {'guilds': len(self.bot.guilds)}
dblcom_headers = {'Authorization': self.dblcom_token}
async with self.request.post(dblcom_call,
# Call Handling
async with self.request.post(dblcom_call,
json=dblcom_data,
headers=dblcom_headers) as resp:
resp_json = await resp.json()
@ -74,13 +90,14 @@ class BotList(commands.Cog, name='Bot List'):
# top.gg
if self.dbl_token != '':
# NOTE top.gg has a lib so it gets different handling.
try:
resp = await self.dbl_client.post_guild_count()
responses['dbl'] = resp
except Exception as e:
responses['dbl'] = e
# Finishing up
# Finalization
return responses
# TODO Move to Core, hide behind check for any existing token
@ -88,11 +105,14 @@ class BotList(commands.Cog, name='Bot List'):
async def vote(self, ctx):
"""Review and vote for this bot on various botlists."""
# Header
msg = (
"**Thank you for wanting to help us out!**\n"
"You can find us on the following lists:\n\n"
)
# Links
# XXX This is really stupidly done, I'm going to find a way to redo it.
if self.dbots_token != '':
msg += f"_bots.discord.gg_ <https://bots.discord.gg/bots/{self.bot.user.id}/>\n"
if self.bod_token != '':
@ -102,6 +122,7 @@ class BotList(commands.Cog, name='Bot List'):
if self.dbl_token != '':
msg += f"_top.gg_ <https://top.gg/bot/{self.bot.user.id}/>\n"
# Sending
await ctx.send(msg)
@commands.command()
@ -111,16 +132,17 @@ class BotList(commands.Cog, name='Bot List'):
msg = await ctx.send("<a:loading:393852367751086090> **Updating...**")
responses = await self._update_logic()
print(responses) # TODO Look at responses and figure out error handling
print(responses) # TODO Look at responses and figure out error handling
await msg.edit(content="**Updated!**")
@tasks.loop(minutes=15.0)
async def update_stats(self):
"""Automatically updates statistics every 15 minutes."""
responses = await self._update_logic()
print(responses)
print(responses) # TODO See other todo
def setup(bot):
"""Adds the cog to the bot."""
bot.add_cog(BotList(bot))