Skip to content

Commit

Permalink
fixed developer cogs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhruva Shaw committed Sep 27, 2024
2 parents d274cff + d994f77 commit 6673097
Show file tree
Hide file tree
Showing 12 changed files with 419 additions and 279 deletions.
3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright [yyyy] [name of copyright owner]

Copyright 2024 Dhruva Shaw
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
11 changes: 9 additions & 2 deletions minato_namikaze/cogs/badges.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ def make_template(
) -> Image:
"""Build the base template before determining animated or not"""
if hasattr(user, "roles"):
department = "GENERAL SUPPORT" if user.top_role.name == "@everyone" else user.top_role.name.upper()
department = (
"GENERAL SUPPORT"
if user.top_role.name == "@everyone"
else user.top_role.name.upper()
)
status = user.status
level = str(len(user.roles))
else:
Expand Down Expand Up @@ -360,7 +364,10 @@ async def get_badge(badge_name: str, ctx: Context) -> Badge:
all_badges = await BadgesDBHandler(ctx).get_all_badges()
to_return = None
for badge in all_badges:
if badge_name.lower() in badge["badge_name"].lower() or badge_name.lower() in badge["code"].lower():
if (
badge_name.lower() in badge["badge_name"].lower()
or badge_name.lower() in badge["code"].lower()
):
to_return = await Badge.from_json(badge)
return to_return

Expand Down
5 changes: 4 additions & 1 deletion minato_namikaze/cogs/dev/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ async def on_message_without_command(self, message):
msg += f"\n**Message Content**: {message.content}"
embeds = [
discord.Embed.from_dict(
{**message.embeds[0].to_dict(), "timestamp": str(message.created_at)},
{
**message.embeds[0].to_dict(),
"timestamp": str(message.created_at),
},
),
]
else:
Expand Down
98 changes: 98 additions & 0 deletions minato_namikaze/cogs/dminvites.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from __future__ import annotations

import discord
from discord.ext import commands

from minato_namikaze.lib import INVITE_URL_RE


class DmInvite(commands.Cog):
"""Respond to invites send in DMs."""

def __init__(self, bot):
self.bot = bot

@commands.group()
@commands.is_owner()
async def dminvite(self, ctx):
"""Group Commands for DM Invites."""

@dminvite.command()
@commands.is_owner()
async def settings(self, ctx):
"""DM Invite Settings."""
embed = discord.Embed(title="DM Invite Settings", color=discord.Color.red())
embed.add_field(
name="Tracking Invites",
value="Yes" if await self.config.toggle() else "No",
)
embed.add_field(
name="Embeds",
value="Yes" if await self.config.embed() else "No",
)
msg = await self.config.message()
embed.add_field(name="Message", value=msg)
embed.add_field(
name="Permissions Value",
value=await self.bot._config.invite_perm(),
)
if "{link}" in msg:
embed.add_field(
name="Link",
value=f"[Click Here]({self.bot.get_required_perms_invite_link})",
)
await ctx.send(embed=embed)

# @dminvite.command()
# @commands.is_owner()
# async def toggle(self, ctx, toggle: bool = None):
# """Turn DM responding on/off."""
# toggle = toggle or await self.config.toggle()
# if toggle:
# await self.config.toggle.set(False)
# await ctx.send(f"{ctx.me.name} will no longer auto-respond to invites sent in DMs.")

# else:
# await self.config.toggle.set(True)
# await ctx.send(f"{ctx.me.name} will auto-respond to invites sent in DMs.")

# @dminvite.command()
# @commands.is_owner()
# async def embeds(self, ctx, toggle: bool = None):
# """Toggle whether the message is an embed or not."""
# toggle = toggle or await self.config.embed()
# if toggle:
# await self.config.embed.set(False)
# await ctx.send("Responses will no longer be sent as an embed.")
# else:
# await self.config.embed.set(True)
# await ctx.send(
# "Responses will now be sent as an embed. You can now use other markdown such as link masking etc.",
# )

@dminvite.command()
@commands.is_owner()
async def message(self, ctx, *, message: str):
"""Set the message that the bot will respond with.
**Available Parameters**:
{link} - return the bots oauth url with the permissions you've set with the core inviteset.
"""
await self.config.message.set(message)
await ctx.tick()

@commands.Cog.listener()
async def on_message(self, message):
if message.guild:
return
if message.author.bot:
return
if link_res := INVITE_URL_RE.findall(message.content):
msg = await self.config.message()
if "{link}" in msg:
msg = msg.format(link=await self.bot.get_required_perms_invite_link)
if await self.config.embed():
embed = discord.Embed(color=discord.Color.red(), description=msg)
await message.author.send(embed=embed)
return
await message.author.send(msg)
15 changes: 10 additions & 5 deletions minato_namikaze/cogs/giftdrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ async def on_message(self, message):
self.cache[message.guild.id]["timestamp"] = datetime.datetime.now(
tz=datetime.timezone.utc,
)
if (datetime.datetime.now(tz=datetime.timezone.utc) - self.cache[message.guild.id]["timestamp"]).total_seconds() < self.cache[
message.guild.id
]["interval"]:
if (
datetime.datetime.now(tz=datetime.timezone.utc)
- self.cache[message.guild.id]["timestamp"]
).total_seconds() < self.cache[message.guild.id]["interval"]:
return
self.cache[message.guild.id]["timestamp"] = datetime.datetime.now(tz=datetime.timezone.utc)
self.cache[message.guild.id]["timestamp"] = datetime.datetime.now(
tz=datetime.timezone.utc
)
if self.cache[message.guild.id]["channel"] is not None:
channel = message.guild.get_channel(self.cache[message.guild.id]["channel"])
if channel is None:
Expand All @@ -87,7 +90,9 @@ async def on_message(self, message):
string, answer = self.random_calc()
msg = await channel.send(string)
try:
pred = MessagePredicate.equal_to(str(answer), channel=channel, user=None)
pred = MessagePredicate.equal_to(
str(answer), channel=channel, user=None
)
answer_msg: discord.Message = await self.bot.wait_for(
"message",
check=pred,
Expand Down
10 changes: 8 additions & 2 deletions minato_namikaze/cogs/reminder.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,17 @@ async def on_reminder_timer_complete(self, timer: Timer):
author_id, channel_id, message = timer.args

try:
channel = self.bot.get_channel(channel_id) or (await self.bot.fetch_channel(channel_id))
channel = self.bot.get_channel(channel_id) or (
await self.bot.fetch_channel(channel_id)
)
except discord.HTTPException:
return

guild_id = channel.guild.id if isinstance(channel, (discord.TextChannel, discord.Thread)) else "@me"
guild_id = (
channel.guild.id
if isinstance(channel, (discord.TextChannel, discord.Thread))
else "@me"
)
message_id = timer.kwargs.get("message_id")
msg = f"<@{author_id}>, {timer.human_delta}: {message}"
view = discord.utils.MISSING
Expand Down
4 changes: 3 additions & 1 deletion minato_namikaze/cogs/shinobi_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ async def characters_data(ctx: Context) -> list[Characters]:
LinksAndVars.character_data.value,
) as resp:
character_data: dict = orjson.loads(await resp.text())
return [Characters.from_record(character_data[i], ctx, i) for i in character_data]
return [
Characters.from_record(character_data[i], ctx, i) for i in character_data
]

@classmethod
async def return_random_characters(self, ctx: Context) -> list[Characters]:
Expand Down
12 changes: 9 additions & 3 deletions minato_namikaze/lib/classes/barcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ def create_svg_object():
MIN_QUIET_ZONE = 2.54

# Charsets for code 39
REF = tuple(string.digits) + tuple(string.ascii_uppercase) + ("-", ".", " ", "$", "/", "+", "%")
REF = (
tuple(string.digits)
+ tuple(string.ascii_uppercase)
+ ("-", ".", " ", "$", "/", "+", "%")
)
B = "1"
E = "0"
CODES = (
Expand Down Expand Up @@ -420,7 +424,8 @@ def _create_text(self, xpos: int, ypos: int):
attributes = dict(
x=SIZE.format(xpos),
y=SIZE.format(ypos),
style="fill:{};font-size:{}pt;text-anchor:" "middle;".format(self.foreground, self.font_size),
style="fill:{};font-size:{}pt;text-anchor:"
"middle;".format(self.foreground, self.font_size),
)
_set_attributes(element, **attributes)
# check option to override self.text with self.human (barcode as human readable data, can be used to print own formats)
Expand Down Expand Up @@ -680,7 +685,8 @@ def check_code(
wrong.append(char)
if wrong:
raise IllegalCharacterError(
"The following characters are not " "valid for {name}: {wrong}".format(name=name, wrong=", ".join(wrong)),
"The following characters are not "
"valid for {name}: {wrong}".format(name=name, wrong=", ".join(wrong)),
)


Expand Down
14 changes: 11 additions & 3 deletions minato_namikaze/lib/classes/converter_cache_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ def error(self, message):


def can_execute_action(ctx, user, target):
return user.id == ctx.bot.owner_id or user == ctx.guild.owner or user.top_role > target.top_role
return (
user.id == ctx.bot.owner_id
or user == ctx.guild.owner
or user.top_role > target.top_role
)


class MemberID(commands.Converter):
Expand Down Expand Up @@ -191,7 +195,9 @@ async def from_record(cls, record: discord.Message, bot: commands.Bot):
lambda a: a["name"].lower() == "Role Required".lower(),
self.embed_dict["fields"],
)
self.role_required = role_required["value"] if role_required is not None else None
self.role_required = (
role_required["value"] if role_required is not None else None
)

tasks = discord.utils.find(
lambda a: a["name"].lower() == "\U0001f3c1 Tasks".lower(),
Expand Down Expand Up @@ -357,7 +363,9 @@ class Characters:

def __init__(self, **kwargs):
self.name: str | None = kwargs.get("name")
self.id: str | int | None = "".join(self.name.split()).upper() if self.name is not None else None
self.id: str | int | None = (
"".join(self.name.split()).upper() if self.name is not None else None
)
self.images: list | None = kwargs.get("images")
self.category: str | None = kwargs.get("category")
self.emoji: discord.Emoji | discord.PartialEmoji | None = kwargs.get(
Expand Down
Loading

0 comments on commit 6673097

Please sign in to comment.