Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: format code with Black #841

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions minato_namikaze/cogs/dev/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ async def sharedservers(
user: Union[discord.Member, MemberID],
):
"""Get a list of servers the bot shares with the user."""
guilds = [f"{guild.name} `{guild.id}` ({guild.member_count} members)" for guild in list(user.mutual_guilds)]
guilds = [
f"{guild.name} `{guild.id}` ({guild.member_count} members)"
for guild in list(user.mutual_guilds)
]

await self._send_guilds(ctx, guilds, "Shared Servers")

Expand Down Expand Up @@ -320,7 +323,8 @@ async def sync(self, ctx: Context):
[f"**{g[0]}** ```diff\n- {g[1]}```" for g in error_collection],
)
return await ctx.send(
f"Attempted to reload all extensions, was able to reload, " f"however the following failed...\n\n{err}",
f"Attempted to reload all extensions, was able to reload, "
f"however the following failed...\n\n{err}",
)

await msg.edit(embed=embed)
Expand Down Expand Up @@ -438,7 +442,8 @@ async def on_message(self, message: discord.Message):
(
self.bot.user.mentioned_in(message)
and message.mention_everyone is False
and message.content.lower() in (f"<@!{self.bot.application_id}>", f"<@{self.bot.application_id}>")
and message.content.lower()
in (f"<@!{self.bot.application_id}>", f"<@{self.bot.application_id}>")
or message.content.lower()
in (
f"<@!{self.bot.application_id}> prefix",
Expand All @@ -458,7 +463,11 @@ async def on_message(self, message: discord.Message):
except:
pass

if link_res := INVITE_URL_RE.findall(message.content) and not message.author.bot and not message.guild:
if (
link_res := INVITE_URL_RE.findall(message.content)
and not message.author.bot
and not message.guild
):
msg = "Thank you for showing interest in me. If you want to add me to your server, please ask the server owner to add me to the server. If you are the server owner, please click on the link below to add me to your server.\n\n{link}"
if "{link}" in msg:
msg = msg.format(link=await self.bot.get_required_perms_invite_link)
Expand Down
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 self.bot.send_to_owners(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
40 changes: 31 additions & 9 deletions minato_namikaze/cogs/moderation/moderation.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,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 @@ -530,7 +532,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 @@ -660,7 +664,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 @@ -704,7 +709,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 @@ -714,7 +723,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 @@ -724,7 +737,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 @@ -848,7 +864,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 @@ -886,7 +904,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 @@ -1066,7 +1086,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
23 changes: 19 additions & 4 deletions minato_namikaze/lib/util/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ def humanize_attachments(attachments: list) -> list:


def format_character_name(character_name: str) -> str:
if character_name.split("(")[-1].strip(" ").strip(")").lower() in ChannelAndMessageId.character_side_exclude.name:
if (
character_name.split("(")[-1].strip(" ").strip(")").lower()
in ChannelAndMessageId.character_side_exclude.name
):
return character_name.split("(")[0].strip(" ").title()
return character_name.strip(" ").title()

Expand Down Expand Up @@ -222,7 +225,11 @@ async def detect_bad_domains(message_content: str) -> list:
if len(i.split("//")) != 0:
try:
parsed_url = urlparse(
(i.lower().strip("/") if i.split("://")[0].lower() in uses_netloc else f'//{i.strip("/")}'),
(
i.lower().strip("/")
if i.split("://")[0].lower() in uses_netloc
else f'//{i.strip("/")}'
),
)
if parsed_url.hostname in list_of_bad_domains:
detected_urls.append(parsed_url.hostname)
Expand All @@ -244,10 +251,18 @@ def return_all_cogs() -> list[str]:
for filename in list(set(os.listdir(cog_dir))):
if os.path.isdir(cog_dir / filename):
for i in os.listdir(cog_dir / filename):
if i.endswith(".py") and not i.startswith("__init__") and not i.endswith(".pyc"):
if (
i.endswith(".py")
and not i.startswith("__init__")
and not i.endswith(".pyc")
):
list_to_be_given.append(f'{filename.strip(" ")}.{i[:-3]}')
else:
if filename.endswith(".py") and not filename.startswith("__init__") and not filename.endswith(".pyc"):
if (
filename.endswith(".py")
and not filename.startswith("__init__")
and not filename.endswith(".pyc")
):
list_to_be_given.append(filename[:-3])

return list_to_be_given
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
Loading