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

Format code with black, yapf, autopep8 and isort #376

Merged
merged 1 commit into from
Dec 21, 2021
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
160 changes: 72 additions & 88 deletions minato_namikaze/bot_files/cogs/developer/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ def owners(ctx):

async def _send_guilds(self, ctx, guilds, title):
if len(guilds) == 0:
await ctx.send(embed=ErrorEmbed(description="No such guild was found."))
await ctx.send(embed=ErrorEmbed(
description="No such guild was found."))
return

all_pages = []

for chunk in [guilds[i: i + 20] for i in range(0, len(guilds), 20)]:
for chunk in [guilds[i:i + 20] for i in range(0, len(guilds), 20)]:
page = Embed(title=title)

for guild in chunk:
Expand Down Expand Up @@ -70,17 +71,15 @@ async def dev(self, ctx, command=None):
else:
pass

@dev.group(
name="postcommand", alisases=["postfates", "post_commands_to_fates_list"]
)
@dev.group(name="postcommand",
alisases=["postfates", "post_commands_to_fates_list"])
async def post_commands_to_fates_list(self, ctx):
"""Post all the commands to FATES LIST"""
start_time = time.time()
await self.bot.change_presence(
status=discord.Status.dnd,
activity=discord.Activity(
type=discord.ActivityType.watching, name="over Naruto"
),
activity=discord.Activity(type=discord.ActivityType.watching,
name="over Naruto"),
)
post_start = await ctx.send("Posting :outbox_tray:")
await PostStats(self.bot).post_commands()
Expand All @@ -95,12 +94,12 @@ async def post_commands_to_fates_list(self, ctx):
)
await self.bot.change_presence(
status=discord.Status.idle,
activity=discord.Activity(
type=discord.ActivityType.watching, name="over Naruto"
),
activity=discord.Activity(type=discord.ActivityType.watching,
name="over Naruto"),
)

@dev.group(name="deletecommand", alisases=["postfates", "deletefateslistcommand"])
@dev.group(name="deletecommand",
alisases=["postfates", "deletefateslistcommand"])
async def deletefateslistcommand(self, ctx):
"""Deletes all the commands from FATES LIST"""
start_time = time.time()
Expand All @@ -124,9 +123,8 @@ async def deletefateslistcommand(self, ctx):
)
await self.bot.change_presence(
status=discord.Status.idle,
activity=discord.Activity(
type=discord.ActivityType.watching, name="over Naruto"
),
activity=discord.Activity(type=discord.ActivityType.watching,
name="over Naruto"),
)

@dev.group(name="sharedservers", usage="<user>")
Expand All @@ -152,26 +150,20 @@ async def createinvite(self, ctx, *, argument: int):
invite = (await guild.invites())[0]
except:
try:
invite = (await guild.text_channels())[0].create_invite(max_age=120)
invite = (await guild.text_channels())[0].create_invite(
max_age=120)
except:
await ctx.send(
embed=ErrorEmbed(
description="No permissions to create an invite link."
)
await ctx.send(embed=ErrorEmbed(
description="No permissions to create an invite link.")
)
return

await ctx.send(
embed=Embed(
description=f"Here is the invite link: {invite.url}")
)
await ctx.send(embed=Embed(
description=f"Here is the invite link: {invite.url}"))
except:
await ctx.send(
embed=ErrorEmbed(
description="Sorry! This is not possible for this server!"
)
)

await ctx.send(embed=ErrorEmbed(
description="Sorry! This is not possible for this server!"))

@dev.group(invoke_without_command=True, name="eval")
@commands.check(owners)
async def _eval(self, ctx, *, body):
Expand Down Expand Up @@ -231,7 +223,8 @@ def paginate(text: str):
ret = await func()
except Exception as e:
value = stdout.getvalue()
err = await ctx.send(f"```py\n{value}{traceback.format_exc()}\n```")
err = await ctx.send(f"```py\n{value}{traceback.format_exc()}\n```"
)
else:
value = stdout.getvalue()
if ret is None:
Expand Down Expand Up @@ -264,7 +257,6 @@ def paginate(text: str):
else:
await ctx.message.add_reaction("\u2705")


@dev.group(invoke_without_command=True)
@commands.check(owners)
async def get_all_cogs(self, ctx):
Expand Down Expand Up @@ -297,7 +289,8 @@ async def reload(self, ctx, name: str):
"""Reloads an extension."""
try:
self.bot.reload_extension(f"bot_files.cogs.{name}")
await ctx.message.add_reaction(discord.PartialEmoji(name="\U0001f504"))
await ctx.message.add_reaction(
discord.PartialEmoji(name="\U0001f504"))

except Exception as e:
return await ctx.send(f"```py\n{e}```")
Expand All @@ -324,8 +317,7 @@ async def reloadall(self, ctx):
if i.endswith(".py"):
try:
self.bot.reload_extension(
f"bot_files.cogs.{file.strip(' ')}.{i[:-3]}"
)
f"bot_files.cogs.{file.strip(' ')}.{i[:-3]}")
except Exception as e:
return await ctx.send(f"```py\n{e}```")
else:
Expand All @@ -338,29 +330,26 @@ async def reloadall(self, ctx):

if error_collection:
output = "\n".join(
[f"**{g[0]}** ```diff\n- {g[1]}```" for g in error_collection]
)
[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{output}"
)
f"however the following failed...\n\n{output}")

await ctx.send("**`Reloaded All Extentions`**")

@dev.group(invoke_without_command=True)
@commands.check(owners)
async def sync(self, ctx):
"""Sync with GitHub and reload all the cogs"""
embed = Embed(
title="Syncing...", description=":joy: Syncing and reloading cogs."
)
embed = Embed(title="Syncing...",
description=":joy: Syncing and reloading cogs.")
embed.set_footer(text=f"{ctx.author} | Minato Namikaze")
msg = await ctx.send(embed=embed)
async with ctx.channel.typing():
output = sp.getoutput("git pull")
embed = Embed(
title="Synced", description="Synced with GitHub and reloaded all the cogs."
)
title="Synced",
description="Synced with GitHub and reloaded all the cogs.")
# Reload Cogs as well
cog_dir = Path(__file__).resolve(strict=True).parent.parent
error_collection = []
Expand All @@ -370,8 +359,7 @@ async def sync(self, ctx):
if i.endswith(".py"):
try:
self.bot.reload_extension(
f"bot_files.cogs.{file.strip(' ')}.{i[:-3]}"
)
f"bot_files.cogs.{file.strip(' ')}.{i[:-3]}")
except Exception as e:
return await ctx.send(f"```py\n{e}```")
else:
Expand All @@ -384,20 +372,17 @@ async def sync(self, ctx):

if error_collection:
err = "\n".join(
[f"**{g[0]}** ```diff\n- {g[1]}```" for g in error_collection]
)
[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"however the following failed...\n\n{err}")

await msg.edit(embed=embed)

@dev.group(name="pretend")
@commands.check(owners)
async def pretend(
self, ctx: commands.Context, target: discord.User, *, command_string: str
):
async def pretend(self, ctx: commands.Context, target: discord.User, *,
command_string: str):
"""Execute my commands pretending as others | usage: <member.mention> <command.name> eg: )own as @Minato angel"""
if ctx.guild:
# Try to upgrade to a Member instance
Expand All @@ -407,21 +392,20 @@ async def pretend(

with contextlib.suppress(discord.HTTPException):
target_member = ctx.guild.get_member(
target.id
) or await ctx.guild.fetch_member(target.id)
target.id) or await ctx.guild.fetch_member(target.id)

target = target_member or target

alt_ctx = await copy_context_with(
ctx, author=target, content=ctx.prefix + command_string
)
alt_ctx = await copy_context_with(ctx,
author=target,
content=ctx.prefix + command_string)

if alt_ctx.command is None:
if alt_ctx.invoked_with is None:
return await ctx.send(
"This bot has been hard-configured to ignore this user."
)
return await ctx.send(f'Command "{alt_ctx.invoked_with}" is not found')
"This bot has been hard-configured to ignore this user.")
return await ctx.send(
f'Command "{alt_ctx.invoked_with}" is not found')

return await alt_ctx.command.invoke(alt_ctx)

Expand All @@ -435,13 +419,11 @@ async def changestat(self, ctx):
@commands.check(owners)
async def stream(self, ctx, *, activity="placeholder (owner to lazy lol)"):
"""Streaming Activity"""
await self.bot.change_presence(
activity=discord.Streaming(
status=discord.Status.idle,
name=activity,
url="https://www.twitch.tv/dhruvacube",
)
)
await self.bot.change_presence(activity=discord.Streaming(
status=discord.Status.idle,
name=activity,
url="https://www.twitch.tv/dhruvacube",
))
await ctx.send(
f"```diff\n- Changed activity to {activity} using Stream status.```"
)
Expand All @@ -450,37 +432,39 @@ async def stream(self, ctx, *, activity="placeholder (owner to lazy lol)"):
@commands.check(owners)
async def game(self, ctx, *, activity="placeholder (owner to lazy lol)"):
"""Game Activity"""
await self.bot.change_presence(
status=discord.Status.idle, activity=discord.Game(name=activity)
)
await ctx.send(f"```md\n# Changed activity to {activity} using Game status.```")
await self.bot.change_presence(status=discord.Status.idle,
activity=discord.Game(name=activity))
await ctx.send(
f"```md\n# Changed activity to {activity} using Game status.```")

@changestat.group(invoke_without_command=True)
@commands.check(owners)
async def watching(self, ctx, *, activity="placeholder (owner to lazy lol)"):
async def watching(self,
ctx,
*,
activity="placeholder (owner to lazy lol)"):
"""Watching activity"""
await self.bot.change_presence(
activity=discord.Activity(
status=discord.Status.idle,
type=discord.ActivityType.watching,
name=activity,
)
)
await self.bot.change_presence(activity=discord.Activity(
status=discord.Status.idle,
type=discord.ActivityType.watching,
name=activity,
))
await ctx.send(
f"```arm\nChanged activity to {activity} using Watching status.```"
)

@changestat.group(invoke_without_command=True)
@commands.check(owners)
async def listening(self, ctx, *, activity="placeholder (owner to lazy lol)"):
async def listening(self,
ctx,
*,
activity="placeholder (owner to lazy lol)"):
"""Listenting Activity"""
await self.bot.change_presence(
activity=discord.Activity(
status=discord.Status.idle,
type=discord.ActivityType.listening,
name=activity,
)
)
await self.bot.change_presence(activity=discord.Activity(
status=discord.Status.idle,
type=discord.ActivityType.listening,
name=activity,
))
await ctx.send(
f"```fix\nChanged activity to {activity} using Listening status.```"
)
Expand Down
12 changes: 7 additions & 5 deletions minato_namikaze/bot_files/lib/functions/tools.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import datetime
import time
import pytz
from typing import Optional, Union, Literal
from typing import Literal, Optional, Union

import discord
import pytz


def check_if_user_joined_a_channel(ctx):
Expand Down Expand Up @@ -60,12 +60,14 @@ def human_join(seq, delim=", ", final="or"):


# R.Danny Code
def format_dt(dt, style: Optional[str] = None, ist: Optional[Union[bool, Literal[False]]] = False):
def format_dt(dt,
style: Optional[str] = None,
ist: Optional[Union[bool, Literal[False]]] = False):
if dt.tzinfo is None and not ist:
dt = dt.replace(tzinfo=datetime.timezone.utc)
if ist:
timezone = datetime.timezone(datetime.timedelta(hours=5,minutes=30))
dt = dt.replace(tzinfo=timezone)
timezone = datetime.timezone(datetime.timedelta(hours=5, minutes=30))
dt = dt.replace(tzinfo=timezone)

if style is None:
return f"<t:{int(dt.timestamp())}>"
Expand Down
Loading