Code Cleanup

This commit is contained in:
Robert 2020-01-08 02:26:36 +01:00
parent d2622e25e8
commit fa34f8510d
13 changed files with 98 additions and 50 deletions

View file

@ -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))

View file

@ -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))

View file

@ -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))