Code Cleanup
This commit is contained in:
parent
d2622e25e8
commit
fa34f8510d
13 changed files with 98 additions and 50 deletions
|
@ -1,3 +1,8 @@
|
|||
'''
|
||||
This is the cog that allows users to
|
||||
fetch an AI-generated inspirational quote
|
||||
made by Inspirobot
|
||||
'''
|
||||
import discord
|
||||
|
||||
from discord.ext import commands
|
||||
|
@ -6,12 +11,12 @@ from util import config
|
|||
|
||||
class Inspirobot(commands.Cog):
|
||||
|
||||
def __init__(self, client):
|
||||
def __init__(self, client : discord.Client):
|
||||
self.client = client
|
||||
|
||||
@commands.command(name="Inspirobot", description="Sends a randomly generated inspirational quote", aliases=["inspiration", "inspiro"])
|
||||
@commands.cooldown(1, 5)
|
||||
async def inspirobot(self, ctx):
|
||||
async def inspirobot(self, ctx : commands.Context):
|
||||
image = inspirobot.get_inspirational_quote()
|
||||
if image is None:
|
||||
await ctx.message.add_reaction("⚠️")
|
||||
|
@ -20,5 +25,5 @@ class Inspirobot(commands.Cog):
|
|||
embed.set_image(url=image)
|
||||
await ctx.send(embed=embed)
|
||||
|
||||
def setup(client):
|
||||
def setup(client : discord.Client):
|
||||
client.add_cog(Inspirobot(client))
|
|
@ -1,3 +1,7 @@
|
|||
'''
|
||||
This cog is capable of communicating with the
|
||||
NASA API
|
||||
'''
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from api import nasa
|
||||
|
@ -5,12 +9,12 @@ from util import config
|
|||
|
||||
class Nasa(commands.Cog):
|
||||
|
||||
def __init__(self, client):
|
||||
def __init__(self, client: discord.Client):
|
||||
self.client = client
|
||||
|
||||
@commands.command(name="APOD", description="Posts NASA's picture of the day.")
|
||||
@commands.cooldown(1, 30)
|
||||
async def apod(self, ctx):
|
||||
async def apod(self, ctx: commands.Context):
|
||||
url = nasa.image_of_the_day()
|
||||
embed = discord.Embed(title="Astronomy Picture of the day", color=int(config.settings["color"], 16))
|
||||
embed.set_image(url=url)
|
||||
|
@ -18,5 +22,5 @@ class Nasa(commands.Cog):
|
|||
await ctx.send(embed=embed)
|
||||
|
||||
|
||||
def setup(client):
|
||||
def setup(client: discord.Client):
|
||||
client.add_cog(Nasa(client))
|
|
@ -1,15 +1,19 @@
|
|||
'''
|
||||
This cog can fetch data from the
|
||||
Steam WebAPI
|
||||
'''
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from api import steam
|
||||
|
||||
class Steam(commands.Cog):
|
||||
|
||||
def __init__(self, client):
|
||||
def __init__(self, client: discord.Client):
|
||||
self.client = client
|
||||
|
||||
@commands.command(name="SteamLevel", description="Finds the steam level of a user", usage="SteamLevel <Vanity URL>", aliases=["level"])
|
||||
@commands.cooldown(1, 2)
|
||||
async def SteamLevel(self, ctx, vanity_url):
|
||||
async def SteamLevel(self, ctx: commands.Context, vanity_url: str):
|
||||
level = steam.get_steam_level(vanity_url)
|
||||
|
||||
if level is None:
|
||||
|
@ -17,9 +21,7 @@ class Steam(commands.Cog):
|
|||
else:
|
||||
percentile = round(float(steam.get_steam_level_distribution(level)), 2)
|
||||
await ctx.send(f"{vanity_url} is level {level}! This makes him better than {percentile}% of Steam users!")
|
||||
|
||||
|
||||
|
||||
|
||||
def setup(client):
|
||||
def setup(client: discord.Client):
|
||||
client.add_cog(Steam(client))
|
|
@ -1,3 +1,8 @@
|
|||
'''
|
||||
Listens for certain keywords in messages and
|
||||
then provides conversion charts that might be
|
||||
useful.
|
||||
'''
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
from util import logging, checking, config
|
||||
|
@ -5,7 +10,7 @@ import re
|
|||
|
||||
class AutoConvert(commands.Cog):
|
||||
|
||||
def __init__(self, client):
|
||||
def __init__(self, client: discord.Client):
|
||||
self.client = client
|
||||
self.currencies = ['€', '$', '£']
|
||||
self.currency_conversion = {
|
||||
|
@ -33,7 +38,7 @@ class AutoConvert(commands.Cog):
|
|||
|
||||
return prices
|
||||
|
||||
def convert_currency(self, _from, to, value):
|
||||
def convert_currency(self, _from: str, to: str, value: float) -> float:
|
||||
if _from == '€':
|
||||
conversion_rate = self.currency_conversion[_from + to]
|
||||
elif to == '€':
|
||||
|
@ -44,7 +49,7 @@ class AutoConvert(commands.Cog):
|
|||
return round(value * conversion_rate, 2)
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message(self, message):
|
||||
async def on_message(self, message: discord.Message):
|
||||
if message.author.bot:
|
||||
return
|
||||
|
||||
|
@ -63,13 +68,9 @@ class AutoConvert(commands.Cog):
|
|||
currency_string += f"{self.convert_currency(element[1], currency, element[0])}{currency}, "
|
||||
embed.add_field(name=str(element[0])+element[1], value=currency_string[:-2])
|
||||
|
||||
|
||||
|
||||
if not empty:
|
||||
await message.channel.send(embed=embed)
|
||||
|
||||
|
||||
|
||||
|
||||
def setup(client):
|
||||
def setup(client: discord.Client):
|
||||
client.add_cog(AutoConvert(client))
|
|
@ -1,18 +1,23 @@
|
|||
'''
|
||||
Flips a coin.
|
||||
Will probably reworked into a "games" cog to
|
||||
hold more interactive commands
|
||||
'''
|
||||
import discord
|
||||
import random
|
||||
from discord.ext import commands
|
||||
|
||||
class Coinflip(commands.Cog):
|
||||
|
||||
def __init__(self, client):
|
||||
def __init__(self, client: discord.Client):
|
||||
self.client = client
|
||||
|
||||
@commands.command(name="coinflip", description="Flips a coin and reacts with the result", aliases=["coin", "flip"])
|
||||
async def coinflip(self, ctx):
|
||||
async def coinflip(self, ctx: commands.Context):
|
||||
if random.randint(0, 1) == 0:
|
||||
await ctx.message.add_reaction("🌑")
|
||||
else:
|
||||
await ctx.message.add_reaction("🌕")
|
||||
|
||||
def setup(client):
|
||||
def setup(client: discord.Client):
|
||||
client.add_cog(Coinflip(client))
|
|
@ -1,16 +1,21 @@
|
|||
'''
|
||||
Listens to keywords in messages and
|
||||
reacts accordingly
|
||||
'''
|
||||
import discord
|
||||
from discord.ext import commands
|
||||
|
||||
class Reactions(commands.Cog):
|
||||
|
||||
def __init__(self, client):
|
||||
def __init__(self, client: discord.Client):
|
||||
self.client = client
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message(self, message : discord.Message):
|
||||
async def on_message(self, message: discord.Message):
|
||||
if message.author.bot:
|
||||
return
|
||||
|
||||
# Flags
|
||||
if "canada" in message.content.lower():
|
||||
await message.add_reaction("🇨🇦")
|
||||
|
||||
|
@ -28,9 +33,10 @@ class Reactions(commands.Cog):
|
|||
await message.add_reaction("🇦")
|
||||
await message.add_reaction("🇾")
|
||||
|
||||
if "extremejoy" in str(message):
|
||||
message.add_reaction(664251611765407745)
|
||||
|
||||
if "extremejoy" in message.content.lower():
|
||||
await message.add_reaction("<:extremejoy:612424729969819648>")
|
||||
|
||||
|
||||
def setup(client):
|
||||
def setup(client: discord.Client):
|
||||
client.add_cog(Reactions(client))
|
Loading…
Add table
Add a link
Reference in a new issue