Skip to content

Commit

Permalink
Merge pull request #845 from Creatrix-Net/deepsource-transform-83d67ba5
Browse files Browse the repository at this point in the history
style: format code with Black
  • Loading branch information
Dhruvacube authored Nov 21, 2024
2 parents 1d0053c + 906aa51 commit d13e18a
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 37 deletions.
9 changes: 7 additions & 2 deletions minato_namikaze/cogs/dev/forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def __init__(self, bot):

async def _destination(self, msg: str = None, embed: discord.Embed = None):
await self.bot.wait_until_ready()
channel = self.bot.get_channel(ChannelAndMessageId.forward_dm_messages_channel_id.value)
channel = self.bot.get_channel(
ChannelAndMessageId.forward_dm_messages_channel_id.value
)
if channel is None:
await (await self.bot.fetch_user(self.bot.owner_id)).send(msg, embed=embed)
else:
Expand All @@ -34,7 +36,10 @@ async def _destination(self, msg: str = None, embed: discord.Embed = None):
def _append_attachements(message: discord.Message, embeds: list):
attachments_urls = []
for attachment in message.attachments:
if any(attachment.filename.endswith(imageext) for imageext in ["jpg", "png", "gif"]):
if any(
attachment.filename.endswith(imageext)
for imageext in ["jpg", "png", "gif"]
):
if embeds[0].image:
embed = discord.Embed()
embed.set_image(url=attachment.url)
Expand Down
28 changes: 22 additions & 6 deletions minato_namikaze/cogs/moderation/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def display_emoji(self) -> discord.PartialEmoji:
@tasks.loop(hours=1, reconnect=True)
async def cleanup(self):
"""Cleans the redunadant and useless backups"""
async for message in (await self.bot.fetch_channel(ChannelAndMessageId.backup_channel.value)).history(limit=None):
async for message in (
await self.bot.fetch_channel(ChannelAndMessageId.backup_channel.value)
).history(limit=None):
try:
await commands.GuildConverter().convert(
await self.bot.get_context(message),
Expand Down Expand Up @@ -117,8 +119,14 @@ async def channellogs(
}
for user in message.mentions
],
"channel_mentions": [{"name": channel.name, "id": channel.id} for channel in message.channel_mentions],
"role_mentions": [{"name": role.name, "id": role.id} for role in message.role_mentions],
"channel_mentions": [
{"name": channel.name, "id": channel.id}
for channel in message.channel_mentions
],
"role_mentions": [
{"name": role.name, "id": role.id}
for role in message.role_mentions
],
"id": message.id,
"pinned": message.pinned,
}
Expand Down Expand Up @@ -192,8 +200,14 @@ async def serverlogs(self, ctx: Context):
}
for user in message.mentions
],
"channel_mentions": [{"name": channel.name, "id": channel.id} for channel in message.channel_mentions],
"role_mentions": [{"name": role.name, "id": role.id} for role in message.role_mentions],
"channel_mentions": [
{"name": channel.name, "id": channel.id}
for channel in message.channel_mentions
],
"role_mentions": [
{"name": role.name, "id": role.id}
for role in message.role_mentions
],
"id": message.id,
"pinned": message.pinned,
}
Expand Down Expand Up @@ -305,7 +319,9 @@ async def delete(self, ctx: Context, *, args):
await ctx.send(
"If any backup(s) of the guild exists then it will be deleted.",
)
async for message in (await self.bot.fetch_channel(ChannelAndMessageId.backup_channel.value)).history(limit=None):
async for message in (
await self.bot.fetch_channel(ChannelAndMessageId.backup_channel.value)
).history(limit=None):
if int(message.content.strip()) == ctx.guild.id:
await message.delete()
return
Expand Down
40 changes: 31 additions & 9 deletions minato_namikaze/cogs/moderation/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,9 @@ async def tempban(
)

until = f'until {format_dt(duration.dt, "F")}'
heads_up_message = f"You have been banned from {ctx.guild.name} {until}. Reason: {reason}"
heads_up_message = (
f"You have been banned from {ctx.guild.name} {until}. Reason: {reason}"
)

try:
await member.send(heads_up_message) # type: ignore # Guarded by AttributeError
Expand Down Expand Up @@ -529,7 +531,9 @@ async def on_tempban_timer_complete(self, timer: Timer):
else:
moderator = f"{moderator} (ID: {mod_id})"

reason = f"Automatic unban from timer made on {timer.created_at} by {moderator}."
reason = (
f"Automatic unban from timer made on {timer.created_at} by {moderator}."
)
await guild.unban(discord.Object(id=member_id), reason=reason)

@commands.command()
Expand Down Expand Up @@ -659,7 +663,8 @@ async def massban(self, ctx: Context, *, args):

# member filters
predicates = [
lambda m: isinstance(m, discord.Member) and can_execute_action(ctx, author, m), # Only if applicable
lambda m: isinstance(m, discord.Member)
and can_execute_action(ctx, author, m), # Only if applicable
lambda m: not m.bot, # No bots
lambda m: m.discriminator != "0000", # No deleted users
]
Expand Down Expand Up @@ -703,7 +708,11 @@ def joined(member, *, offset=now - datetime.timedelta(minutes=args.joined)):
_joined_after_member = await converter.convert(ctx, str(args.joined_after))

def joined_after(member, *, _other=_joined_after_member):
return member.joined_at and _other.joined_at and member.joined_at > _other.joined_at
return (
member.joined_at
and _other.joined_at
and member.joined_at > _other.joined_at
)

predicates.append(joined_after)
if args.joined_before:
Expand All @@ -713,7 +722,11 @@ def joined_after(member, *, _other=_joined_after_member):
)

def joined_before(member, *, _other=_joined_before_member):
return member.joined_at and _other.joined_at and member.joined_at < _other.joined_at
return (
member.joined_at
and _other.joined_at
and member.joined_at < _other.joined_at
)

predicates.append(joined_before)

Expand All @@ -723,7 +736,10 @@ def joined_before(member, *, _other=_joined_before_member):

if args.show:
members = sorted(members, key=lambda m: m.joined_at or now)
fmt = "\n".join(f"{m.id}\tJoined: {m.joined_at}\tCreated: {m.created_at}\t{m}" for m in members)
fmt = "\n".join(
f"{m.id}\tJoined: {m.joined_at}\tCreated: {m.created_at}\t{m}"
for m in members
)
content = f"Current Time: {discord.utils.utcnow()}\nTotal members: {len(members)}\n{fmt}"
file = discord.File(
io.BytesIO(content.encode("utf-8")),
Expand Down Expand Up @@ -847,7 +863,9 @@ async def newusers(self, ctx: Context, *, count: int | None = 5):
if not ctx.guild.chunked:
members = await ctx.guild.chunk(cache=True)

members = sorted(ctx.guild.members, key=lambda m: m.joined_at, reverse=True)[:count]
members = sorted(ctx.guild.members, key=lambda m: m.joined_at, reverse=True)[
:count
]

embed = discord.Embed(title="New Members", colour=discord.Colour.green())

Expand Down Expand Up @@ -885,7 +903,9 @@ async def _regular_user_cleanup_strategy(self, ctx: Context, search):
prefixes = tuple(self.bot.get_guild_prefixes(ctx.guild))

def check(m):
return (m.author == ctx.me or m.content.startswith(prefixes)) and not (m.mentions or m.role_mentions)
return (m.author == ctx.me or m.content.startswith(prefixes)) and not (
m.mentions or m.role_mentions
)

deleted = await ctx.channel.purge(limit=search, check=check, before=ctx.message)
return Counter(m.author.display_name for m in deleted)
Expand Down Expand Up @@ -1065,7 +1085,9 @@ async def _bot(self, ctx: Context, prefix=None, search=100):
"""Removes a bot user's messages and messages with their optional prefix."""

def predicate(m):
return (m.webhook_id is None and m.author.bot) or (prefix and m.content.startswith(prefix))
return (m.webhook_id is None and m.author.bot) or (
prefix and m.content.startswith(prefix)
)

await self.do_removal(ctx, search, predicate)

Expand Down
12 changes: 9 additions & 3 deletions minato_namikaze/discordbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ def get_random_image_from_tag(tag_name: str) -> str | None:
return
api_model = TenGiphPy.Giphy(token=Tokens.giphy.value)
try:
return api_model.random(str(tag_name.lower()))["data"]["images"]["downsized_large"]["url"]
return api_model.random(str(tag_name.lower()))["data"]["images"][
"downsized_large"
]["url"]
except:
return

Expand All @@ -424,7 +426,9 @@ async def get_random_image_from_tag(tag_name: str) -> str | None:
return
api_model = TenGiphPy.Giphy(token=Tokens.giphy.value)
try:
return (await api_model.arandom(tag=str(tag_name.lower())))["data"]["images"]["downsized_large"]["url"]
return (await api_model.arandom(tag=str(tag_name.lower())))["data"][
"images"
]["downsized_large"]["url"]
except:
return

Expand All @@ -440,7 +444,9 @@ def tenor(tag_name: str) -> str | None:
async def giphy(tag_name: str) -> str | None:
api_model = TenGiphPy.Giphy(token=Tokens.giphy.value)
try:
return (await api_model.arandom(tag=str(tag_name.lower())))["data"]["images"]["downsized_large"]["url"]
return (await api_model.arandom(tag=str(tag_name.lower())))["data"][
"images"
]["downsized_large"]["url"]
except:
return

Expand Down
6 changes: 5 additions & 1 deletion minato_namikaze/lib/classes/converter_cache_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,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
8 changes: 6 additions & 2 deletions minato_namikaze/lib/util/vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,15 @@ class LinksAndVars(enum.Enum):
github = "https://github.com/The-4th-Hokage/yondaime-hokage"

bad_links = "https://raw.githubusercontent.com/The-4th-Hokage/bad-domains-list/master/bad-domains.txt"
listing = "https://raw.githubusercontent.com/The-4th-Hokage/listing/master/listing.json"
listing = (
"https://raw.githubusercontent.com/The-4th-Hokage/listing/master/listing.json"
)
character_data = "https://raw.githubusercontent.com/The-4th-Hokage/naruto-card-game-images/master/img_data.json"

statuspage_link = "https://minatonamikaze.statuspage.io"
mal_logo = "https://cdn.myanimelist.net/images/event/15th_anniversary/top_page/item7.png"
mal_logo = (
"https://cdn.myanimelist.net/images/event/15th_anniversary/top_page/item7.png"
)
giveaway_image = "https://i.imgur.com/efLKnlh.png"

invite_redirect_uri = "https://minatonamikaze-invites.herokuapp.com/invite"
Expand Down
7 changes: 4 additions & 3 deletions minato_namikaze/old_outdated/giftdrop.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ 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,
Expand Down
4 changes: 3 additions & 1 deletion minato_namikaze/old_outdated/giveaway.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ async def determine_winner(
lambda a: discord.utils.get(
a.roles,
id=int(
giveaway_config.role_required.lstrip("<@&").lstrip("<&").rstrip(">"),
giveaway_config.role_required.lstrip("<@&")
.lstrip("<&")
.rstrip(">"),
),
)
is not None,
Expand Down
4 changes: 3 additions & 1 deletion minato_namikaze/old_outdated/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
14 changes: 11 additions & 3 deletions minato_namikaze/old_outdated/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ async def support(self, ctx: Context):
delete_after=4,
)
return
if discord.utils.get(ctx.guild.roles, id=data.get("support")[-1]) in ctx.message.author.roles:
if (
discord.utils.get(ctx.guild.roles, id=data.get("support")[-1])
in ctx.message.author.roles
):
await ctx.send(
embed=ErrorEmbed(
description=f"{ctx.message.author.mention} you already applied for the support , please check the {channel.mention} channel.",
Expand Down Expand Up @@ -132,7 +135,10 @@ async def resolved(self, ctx: Context, member: MemberID | discord.Member):
embed=ErrorEmbed(description=f"{member.mention} is a bot! :robot:"),
)
return
if not discord.utils.get(ctx.guild.roles, id=data.get("support")[-1]) in member.roles:
if (
not discord.utils.get(ctx.guild.roles, id=data.get("support")[-1])
in member.roles
):
e = ErrorEmbed(
title="Sorry !",
description=f"{member.mention} has not requested any **support** !",
Expand Down Expand Up @@ -247,7 +253,9 @@ async def feedback(self, ctx: Context, *, feed):
e2 = discord.Embed(
title="New Feedback!",
description=feed,
colour=ctx.author.color or ctx.author.top_role.colour.value or discord.Color.random(),
colour=ctx.author.color
or ctx.author.top_role.colour.value
or discord.Color.random(),
)
e2.set_author(
name=ctx.author.display_name,
Expand Down
22 changes: 16 additions & 6 deletions minato_namikaze/slash_old/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ async def callback(self, response: discord.SlashCommandResponse):
if len(detected_urls) != 0:
embed = ErrorEmbed(title="SCAM/PHISHING/ADULT LINK(S) DETECTED")
detected_string = "\n".join([f"- ||{i}||" for i in set(detected_urls)])
embed.description = f"The following scam url(s) were detected:\n{detected_string}"
embed.description = (
f"The following scam url(s) were detected:\n{detected_string}"
)
embed.set_author(
name=response.interaction.user.display_name,
icon_url=response.interaction.user.display_avatar.url,
Expand All @@ -73,7 +75,9 @@ async def callback(self, response: discord.MessageCommandResponse):
if len(detected_urls) != 0:
embed = ErrorEmbed(title="SCAM/PHISHING/ADULT LINK(S) DETECTED")
detected_string = "\n".join([f"- ||{i}||" for i in set(detected_urls)])
embed.description = f"The following scam url(s) were detected:\n{detected_string}"
embed.description = (
f"The following scam url(s) were detected:\n{detected_string}"
)
embed.set_author(
name=response.target.author.display_name,
icon_url=response.target.author.display_avatar.url,
Expand Down Expand Up @@ -424,9 +428,11 @@ class BadLinks(discord.SlashCommand, parent=Setup):
description="Enable or Disable",
default=True,
)
action: None | (typing.Literal["ban", "mute", "timeout", "kick", "log"]) = discord.application_command_option(
description="What kind of action to take",
default=None,
action: None | (typing.Literal["ban", "mute", "timeout", "kick", "log"]) = (
discord.application_command_option(
description="What kind of action to take",
default=None,
)
)
channel: GuildChannel | None = discord.application_command_option(
channel_types=[discord.TextChannel],
Expand All @@ -449,7 +455,11 @@ async def callback(self, response: discord.SlashCommandResponse):
"badlinks": {
"option": response.options.option,
"action": response.options.action,
"logging_channel": (response.options.channel.id if response.options.channel is not None else response.options.channel),
"logging_channel": (
response.options.channel.id
if response.options.channel is not None
else response.options.channel
),
},
},
response.interaction.guild,
Expand Down

0 comments on commit d13e18a

Please sign in to comment.