Skip to content

Commit

Permalink
Refactor code and add license
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver-ni committed Jul 19, 2020
1 parent 34ea1f7 commit bf2a270
Show file tree
Hide file tree
Showing 17 changed files with 862 additions and 211 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,20 @@ verify_ssl = true
black = "*"

[packages]
discord-py = "*"
pillow = "*"
pymongo = {extras = ["tls"],version = "*"}
python-dotenv = "*"
dnspython = "*"
discord-flags = "*"
unidecode = "*"
humanfriendly = "*"
motor = "*"
umongo = "==3.0.0b7"
flask = "*"
requests = "*"
gunicorn = "*"
dblpy = "*"
jishaku = "*"
pytz = "*"
"discord.py" = "*"
pokedex = {git = "https://github.com/veekun/pokedex.git"}
discord = {git = "https://github.com/Rapptz/discord.py.git", ref = "sharding-rework"}

[requires]
python_version = "3.8"
Expand Down
107 changes: 28 additions & 79 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO switch to an async thing here.

import asyncio
import hmac
import os
Expand All @@ -14,8 +16,6 @@

@app.route("/dbl", methods=["POST"])
def dbl():
print(request.json)

res = db.member.find_one({"_id": int(request.json["user"])})

streak = res.get("vote_streak", 0)
Expand Down Expand Up @@ -44,6 +44,8 @@ def dbl():
return "Success", 200


# TODO implement patreon webhooks that actually work

# @app.route("/patreon", methods=["POST"])
# def patreon():
# if "delete" in request.headers.get("X-Patreon-Event"):
Expand Down
4 changes: 3 additions & 1 deletion cogs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def giveredeem(
"""Give a redeem."""

await self.db.update_member(
user, {"$inc": {"redeems": num},},
user, {"$inc": {"redeems": num}},
)

await ctx.send(f"Gave {user.mention} {num} redeems.")
Expand Down Expand Up @@ -76,6 +76,8 @@ async def give(self, ctx: commands.Context, user: discord.Member, *, species: st
async def setup(self, ctx: commands.Context, user: discord.Member, num: int = 100):
"""Test setup pokémon."""

# This is for development purposes.

member = await self.db.fetch_member_info(user)

pokemon = []
Expand Down
5 changes: 5 additions & 0 deletions cogs/battling.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
"""
The code in here is shit. I know.
I'm working on rewriting this file with better code that actually works.
"""

import asyncio
import math
import random
Expand Down
58 changes: 33 additions & 25 deletions cogs/bot.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import random
import sys
import traceback
from datetime import datetime
from functools import cached_property

Expand Down Expand Up @@ -60,47 +62,51 @@ async def determine_prefix(self, guild):

@commands.Cog.listener()
async def on_command_error(self, ctx, error):
if isinstance(error, discord.Forbidden):
return

if isinstance(error, commands.MissingRequiredArgument):
return await ctx.send_help(ctx.command)

if isinstance(error, checks.MustHaveStarted):
return await ctx.send(
f"Please pick a starter pokémon by typing `{ctx.prefix}start` before using this command!"
)

if isinstance(error, flags.ArgumentParsingError):
return await ctx.send(error)

if isinstance(error, commands.BadArgument):
return await ctx.send(f"Bad argument: {error}")
if isinstance(error, commands.NoPrivateMessage):
await ctx.send("This command cannot be used in private messages.")

if isinstance(error, converters.PokemonConversionError):
return await ctx.send(error)
elif isinstance(error, commands.DisabledCommand):
await ctx.send("Sorry. This command is disabled and cannot be used.")

if isinstance(error, commands.BotMissingPermissions):
elif isinstance(error, commands.BotMissingPermissions):
missing = [
"`" + perm.replace("_", " ").replace("guild", "server").title() + "`"
for perm in error.missing_perms
]

if len(missing) > 2:
fmt = "{}, and {}".format(", ".join(missing[:-1]), missing[-1])
else:
fmt = " and ".join(missing)

message = f"💥 Err, I need the following permissions to run this command:\n{fmt}\nPlease fix this and try again."
return await ctx.send(message)
await ctx.send(message)

if isinstance(error, commands.CheckFailure):
return await ctx.send(error)
elif isinstance(error, commands.CheckFailure):
await ctx.send(error)

if isinstance(error, commands.CommandNotFound):
elif isinstance(error, converters.PokemonConversionError):
await ctx.send(error)

elif isinstance(error, commands.MissingRequiredArgument):
await ctx.send_help(ctx.command)

elif isinstance(error, commands.UserInputError):
await ctx.send(error)

elif isinstance(error, flags.ArgumentParsingError):
await ctx.send(error)

elif isinstance(error, discord.errors.Forbidden):
return

raise error
elif isinstance(error, commands.CommandNotFound):
return

else:
print(f"Ignoring exception in command {ctx.command}:", file=sys.stderr)
traceback.print_exception(
type(error), error, error.__traceback__, file=sys.stderr
)

@commands.command()
async def invite(self, ctx: commands.Context):
Expand Down Expand Up @@ -229,6 +235,8 @@ async def profile(self, ctx: commands.Context):
@checks.has_started()
@commands.command()
async def healschema(self, ctx: commands.Context, member: discord.User = None):
"""Fix database schema if broken."""

await self.db.update_member(
member or ctx.author,
{"$pull": {f"pokemon": {"species_id": {"$exists": False}}}},
Expand Down
4 changes: 2 additions & 2 deletions cogs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async def prefix(self, ctx: commands.Context, *, prefix: str = None):
current = current[0]
return await ctx.send(f"My prefix is `{current}` in this server.")

if prefix == "reset" or prefix == "p!":
if prefix in ("reset", "p!", "P!"):
await self.db.update_guild(ctx.guild, {"$set": {"prefix": None}})
self.bot.prefixes[ctx.guild.id] = None

Expand Down Expand Up @@ -64,7 +64,7 @@ async def silence(self, ctx: commands.Context):
await ctx.send(f"Reverting to normal level up behavior.")
else:
await ctx.send(
f"I'll no longer send level up messages. You'll receive a DM when your pokémon evolves or reaches level 100."
"I'll no longer send level up messages. You'll receive a DM when your pokémon evolves or reaches level 100."
)

@checks.is_admin()
Expand Down
Loading

0 comments on commit bf2a270

Please sign in to comment.