Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions the100/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
from redbot.core import commands
from .the100 import The100

__red_end_user_data_statement__ = (
"This cog does not store user-specific data."
)


def setup(bot: commands.Bot):
bot.add_cog(The100(bot))
32 changes: 24 additions & 8 deletions the100/info.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
{
"AUTHOR" : ["Aioxas"],
"INSTALL_MSG" : "Thanks for installing my cog. \n[p]help The100 to start using the cog.",
"NAME" : "the100",
"SHORT" : "Bringing the100.io API to Discord",
"REQUIREMENTS" : [],
"TAGS" : ["Fun"],
"DESCRIPTION" : "Allows players to access the100.io API through Discord"
}
"author": ["Aioxas"],
"description": "Allows players to access the100.io API through Discord",
"disabled": false,
"end_user_data_statement": "This cog does not persistently store data or metadata about users.",
"install_msg": "Thanks for installing my cog. \n[p]help The100 to start using the cog.",
"hidden": false,
"max_bot_version": "0.0.0",
"min_bot_version": "3.1.8",
"min_python_version": [
3,
7,
2
],
"name": "the100",
"permissions": [
"send_messages"
],
"requirements": [],
"required_cogs": {},
"short": "Bringing the100.io API to Discord",
"tags": [
"Fun"
]
}
53 changes: 22 additions & 31 deletions the100/the100.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ def __init__(self, bot: Red):
self.url = "https://www.the100.io/api/v1/groups"
self._the100.register_guild(**self.default_guild_settings)

def __unload(self):
self.session.close()
def cog_unload(self):
self.bot.loop.create_task(self.session.close())

__unload = cog_unload

async def permcheck(self, ctx):
author = ctx.message.author
Expand All @@ -43,7 +45,7 @@ async def permcheck(self, ctx):

@commands.group()
async def the100(self, ctx):
"""The100 settingS"""
"""The100 settings"""
if ctx.invoked_subcommand is None:
await ctx.send_cmd_help()
elif not (await self.permcheck(ctx)):
Expand All @@ -60,13 +62,8 @@ async def group(self, ctx, name: str):
data = await self._the100.guild(ctx.guild).all()
if not self.permcheck(ctx):
return
if data["token"]:
self.headers["Authorization"] = self.headers["Authorization"].format(data["token"])
headers = self.headers
else:
await ctx.send(
"Token has not been set, please set it using [p]the100 set token in a pm"
)
headers = self.token_retriever(data)
if headers == "":
return
async with self.session.get(url, headers=headers) as resp:
response = await resp.json()
Expand All @@ -84,13 +81,8 @@ async def users(self, ctx, name: str):
data = await self._the100.guild(ctx.guild).all()
if not self.permcheck(ctx):
return
if data["token"]:
self.headers["Authorization"] = self.headers["Authorization"].format(data["token"])
headers = self.headers
else:
await ctx.send(
"Token has not been set, please set it using [p]the100 set token in a pm"
)
headers = self.token_retriever(data)
if headers == "":
return
async with self.session.get(url, headers=headers) as resp:
response = await resp.json()
Expand All @@ -109,13 +101,8 @@ async def games(self, ctx, name: str):
data = await self._the100.guild(ctx.guild).all()
if not self.permcheck(ctx):
return
if data["token"]:
self.headers["Authorization"] = self.headers["Authorization"].format(data["token"])
headers = self.headers
else:
await ctx.send(
"Token has not been set, please set it using this command in a PM, [p]the100 set token"
)
headers = self.token_retriever(data)
if headers == "":
return
async with self.session.get(url, headers=headers) as resp:
response = await resp.json()
Expand Down Expand Up @@ -166,13 +153,8 @@ async def statuses(self, ctx, name: str):
data = await self._the100.guild(ctx.guild).all()
if not self.permcheck(ctx):
return
if data["token"]:
self.headers["Authorization"] = self.headers["Authorization"].format(data["token"])
headers = self.headers
else:
await ctx.send(
"Token has not been set, please set it using [p]the100 set token in a pm"
)
headers = self.token_retriever(data)
if headers == "":
return
async with self.session.get(url, headers=headers) as resp:
response = await resp.json()
Expand Down Expand Up @@ -256,3 +238,12 @@ def check(m):
data["role"] = role
await self._the100.guild(ctx.guild).set(data)
await ctx.send("Access role {} has been set".format(role))

def token_retriever(self, ctx, data: dict):
if data["token"]:
return self.headers["Authorization"].format(data["token"])
else:
await ctx.send(
"Token has not been set, please set it using this command in a PM, [p]the100 set token"
)
return ""