Skip to content

Commit

Permalink
architecture update
Browse files Browse the repository at this point in the history
  • Loading branch information
DroidZed committed Jun 10, 2022
1 parent b294884 commit 6dc1b8b
Show file tree
Hide file tree
Showing 66 changed files with 1,129 additions and 1,109 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
repos:
- repo: https://github.com/psf/black
rev: 21.12b0
rev: 22.3.0
hooks:
- id: black
args: [--target-version=py310]
args: [ --target-version=py310 ]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.3.0
hooks:
- id: trailing-whitespace
args: [--markdown-linebreak-ext=md]
args: [ --markdown-linebreak-ext=md ]
46 changes: 35 additions & 11 deletions Cogs/Zed.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
from platform import python_version
from random import choice

from discord.ext.commands import Bot, Cog, Context, command, cooldown, BucketType
from discord import __version__
from discord.ext.commands import Bot, Cog, Context, command, cooldown, BucketType, CommandError, BadBoolArgument

from api.find_gif import find_gif
from config.embed.env_cfg import env_config
from api.images import find_gif
from classes.embed_factory import EmbedFactory
from config.colors import BOT_COLOR
from config.main import PREFIX, OWNER_ID
from functions.embed_factory import create_embed


class ZedCog(Cog, name="Zed-Domain[WIP]", description="⚡ Domain expansion !"):
def __init__(self, bot: Bot):
self.bot = bot

@command(
name="Z",
description="Calls the bot. This command is a work in progress.",
usage=f"{PREFIX}",
aliases=[""],
)
@command(name="Z", description="Calls the bot. This command is a work in progress.", usage=f"{PREFIX}")
@cooldown(1, 2.5, BucketType.user)
async def zed(self, ctx: Context):
replies = [
Expand All @@ -38,7 +35,25 @@ async def zed(self, ctx: Context):

@command(name="env", description="Displays the bot's environment", usage=f"{PREFIX}env")
async def env(self, ctx: Context):
await ctx.send(embed=create_embed(env_config()))

await ctx.send(
embed=EmbedFactory.create_embed(
EmbedFactory.create_config(
title="Working Environment",
description="I'm working under the **latest** and **greatest** of"
f"\n <:python:880768802885885973> `Python`: `{python_version()}`"
f"\n <:pycord:895264837284790283> `Pycord`: `{__version__}`",
color=BOT_COLOR,
author={
"name": "The Z Butler",
"icon_url": "https://cdn.discordapp.com/avatars/759844892443672586/bb7df4730c048faacd8db6dd99291cdb.jpg",
},
thumbnail={
"url": "https://64.media.tumblr.com/fbeaedb718f8f4c23d261b100bbf62cc/tumblr_onv6j3by9b1uql2i0o1_500.gif"
},
)
)
)

@command(name="say", description="Say something :/", usage=f"{PREFIX}say `True` | `False` `your message`")
async def say(self, ctx: Context, with_author: bool = False, *msg: str):
Expand Down Expand Up @@ -79,6 +94,15 @@ async def python(self, ctx: Context):
)
)

@say.error
async def say_handler(self, ctx: Context, error: CommandError) -> None:

if isinstance(error, BadBoolArgument):
await ctx.reply("Please provive the correct argument for writing the signature.")

else:
await ctx.reply("Check the command's help page for the correct syntax.")


def setup(bot: Bot):
bot.add_cog(ZedCog(bot))
127 changes: 83 additions & 44 deletions Cogs/event_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@
from discord.ext.commands import Bot, Cog, Context, MemberConverter
from discord.ext.commands.errors import (
CommandError,
MemberNotFound,
CommandNotFound,
CommandOnCooldown,
MissingRole,
MissingPermissions,
CommandInvokeError,
MemberNotFound,
MissingRequiredArgument,
)
from httpx import ReadTimeout

from classes.mongo_db_helper_client import MongoDBHelperClient
from config.embed.leave import leave_config
from config.embed.welcome import welcome_config
from classes.embed_factory import EmbedFactory
from classes.mongo_db_management import MongoDBHelperClient
from config.colors import BOT_COLOR
from config.main import GUILD_ID
from functions.create_welcome_image import create_picture
from functions.embed_factory import create_embed
from functions.image_manipulation import create_welcome_picture


class EventHandlers(
Expand All @@ -39,10 +38,11 @@ def __get_initial_roles(guild: Guild) -> list[Role]:
return [
guild.get_role(896349097391444029), # silenced role
guild.get_role(980527744062464030), # special roles
guild.get_role(898874934615482378), # community roles
guild.get_role(898874121222516736), # leveling roles
guild.get_role(898874934615482378), # default Seperator role 1
guild.get_role(983415194967490641), # default Seperator role 2
guild.get_role(898874121222516736), # community roles
guild.get_role(969706983777263677), # gaming roles
guild.get_role(969639120513163345), # other roles
guild.get_role(969639120513163345), # newspaper roles
]

@Cog.listener()
Expand All @@ -61,14 +61,33 @@ async def on_member_join(self, member: MemberConverter):

if channel:
with BytesIO() as image_binary:
create_picture(username=f"{member.name}", discriminator=f"{member.discriminator}").save(
create_welcome_picture(username=f"{member.name}", discriminator=f"{member.discriminator}").save(
image_binary, "PNG"
)

image_binary.seek(0)

try:
await member.send(embed=create_embed(welcome_config()))
await member.send(
embed=EmbedFactory.create_embed(
EmbedFactory.create_config(
title=f"Hello there fellow Dragon Warrior",
color=BOT_COLOR,
description="Welcome to **DRAGON'S HEART** !! Please open a ticket in <#778292937426731049> and a member of the staff team will be with you shortly",
author={
"name": "The Z Butler",
"icon_url": "https://cdn.discordapp.com/avatars/759844892443672586/bb7df4730c048faacd8db6dd99291cdb.jpg",
},
thumbnail={
"url": "https://64.media.tumblr.com/fbeaedb718f8f4c23d261b100bbf62cc/tumblr_onv6j3by9b1uql2i0o1_500.gif"
},
footer={
"text": "Your trusty bot Z 🔱",
"icon_url": "https://cdn.discordapp.com/avatars/759844892443672586/bb7df4730c048faacd8db6dd99291cdb.jpg",
},
)
)
)
except Forbidden:
pass

Expand All @@ -90,55 +109,75 @@ async def on_member_remove(self, member: MemberConverter):
if await client.query_collection({"uid": member.id}):
await client.delete_from_collection({"uid": member.id})

await channel.send(embed=create_embed(leave_config(member.name, member.id)))
await channel.send(
embed=EmbedFactory.create_embed(
EmbedFactory.create_config(
title=f"{member.name} Left us.",
color=BOT_COLOR,
description=f"<@{member.id}> "
"got sucked into a black hole <a:black_hole:796434656605765632>, long forgotten.",
author={
"name": "The Z Butler",
"icon_url": "https://cdn.discordapp.com/avatars/759844892443672586/bb7df4730c048faacd8db6dd99291cdb.jpg",
},
thumbnail={
"url": "https://64.media.tumblr.com/fbeaedb718f8f4c23d261b100bbf62cc/tumblr_onv6j3by9b1uql2i0o1_500.gif"
},
footer={
"text": "We shall never remember those who left our cause.",
"icon_url": "https://cdn.discordapp.com/avatars/759844892443672586/bb7df4730c048faacd8db6dd99291cdb.jpg",
},
)
)
)

@Cog.listener()
async def on_command_error(self, ctx: Context, error: CommandError):

if isinstance(error, MissingRole):
match error:

return

elif isinstance(error, MemberNotFound):
case MissingPermissions():
return

await ctx.reply(
\\_(ツ)_/¯ The user provided could not be found, try again...",
mention_author=True,
)
case MemberNotFound():
await ctx.reply(
\\_(ツ)_/¯ The user provided could not be found, try again...",
mention_author=True,
)

elif isinstance(error, CommandOnCooldown):
case CommandOnCooldown():

await ctx.reply(
f"⏳ Hold your horses, this command is on cooldown, you can use it in {round(error.retry_after, 2)}s",
mention_author=True,
)
await ctx.reply(
f"⏳ Hold your horses, this command is on cooldown, you can use it in {round(error.retry_after, 2)}s",
mention_author=True,
)

elif isinstance(error, CommandNotFound):
case CommandNotFound():

await ctx.reply("Nope, no such command was found *sight* 💨", mention_author=True)
await ctx.send("Nope, no such command was found *sight* 💨", mention_author=True)

elif isinstance(error, CommandInvokeError):
case CommandInvokeError():

await ctx.reply(
"❌ Internal anomaly, I wasn't able to handle your request invoker. Sorry for my incompetence.",
mention_author=True,
)
print_exception(type(error), error, error.__traceback__, file=stderr)
await ctx.send(
"❌ Internal anomaly, I wasn't able to handle your request invoker. Sorry for my incompetence.",
mention_author=True,
)
print_exception(type(error), error, error.__traceback__, file=stderr)

elif isinstance(error, MissingRequiredArgument):
case MissingRequiredArgument():

await ctx.reply(
"You __***IDIOT***__ !! Don't you know when typing this command, YOU **MUST** provide "
"ARGUMENTS ? I think you should go back to elementary school and learn how to read 🙄",
mention_author=True,
)
await ctx.reply(
"You __***IDIOT***__ !! Don't you know when typing this command, YOU **MUST** provide "
"ARGUMENTS ? I think you should go back to elementary school and learn how to read 🙄",
mention_author=True,
)

elif isinstance(error, ReadTimeout):
case ReadTimeout():

await ctx.reply("Command timed out, please try again ❌", mention_author=True)
await ctx.reply("Command timed out, please try again ❌", mention_author=True)

else:
print_exception(type(error), error, error.__traceback__, file=stderr)
case _:
print_exception(type(error), error, error.__traceback__, file=stderr)


def setup(bot: Bot):
Expand Down
Loading

0 comments on commit 6dc1b8b

Please sign in to comment.