Skip to content

Commit

Permalink
Added extra function typing
Browse files Browse the repository at this point in the history
  • Loading branch information
LobaDK committed Mar 21, 2024
1 parent 74f4d76 commit 85f1e69
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 40 deletions.
2 changes: 1 addition & 1 deletion QuantumKat.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def is_installed(executable: str) -> bool:
initial_extensions.append(f"cogs.{path.splitext(cog)[0]}")


async def setup(bot):
async def setup(bot: commands.Bot):
if not ignoreMissingExe:
for executable in executables:
if not is_installed(executable):
Expand Down
8 changes: 4 additions & 4 deletions cogs/Activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class Activity(commands.Cog):
def __init__(self, bot):
def __init__(self, bot: commands.Bot):

self.bot = bot

Expand Down Expand Up @@ -124,7 +124,7 @@ async def before_change_activity(self):
),
)
@commands.is_owner()
async def ActivityStop(self, ctx):
async def ActivityStop(self, ctx: commands.Context):
if self.change_activity.is_running():
self.change_activity.cancel()
await ctx.message.add_reaction("👌")
Expand All @@ -148,7 +148,7 @@ async def ActivityStop(self, ctx):
),
)
@commands.is_owner()
async def ActivityRestart(self, ctx):
async def ActivityRestart(self, ctx: commands.Context):
self.change_activity.restart()
await ctx.message.add_reaction("👌")

Expand All @@ -165,7 +165,7 @@ async def ActivityRestart(self, ctx):
),
)
@commands.is_owner()
async def ActivityStart(self, ctx):
async def ActivityStart(self, ctx: commands.Context):
if not self.change_activity.is_running():
self.change_activity.start()
await ctx.message.add_reaction("👌")
Expand Down
4 changes: 2 additions & 2 deletions cogs/Chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class Chat(commands.Cog):
def __init__(self, bot):
def __init__(self, bot: commands.Bot):
self.bot = bot

self.db_conn = bot.db_conn
Expand Down Expand Up @@ -485,5 +485,5 @@ async def ChatStatus(self, ctx: commands.Context):
print("Started Chat!")


async def setup(bot):
async def setup(bot: commands.Bot):
await bot.add_cog(Chat(bot))
17 changes: 9 additions & 8 deletions cogs/Control.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from random import choice
import logging
import discord

from discord.ext import commands


class Control(commands.Cog):
def __init__(self, bot):
def __init__(self, bot: commands.Bot):
self.bot = bot
self.locations = ["universe", "reality", "dimension", "timeline"]

Expand All @@ -26,7 +27,7 @@ def __init__(self, bot):
handler.setFormatter(formatter)
self.logger.addHandler(handler)

async def get_permissions(self, guild) -> list[str]:
async def get_permissions(self, guild: discord.Guild) -> list[str]:
permissions = []
for permission in guild.me.guild_permissions:
if permission[1] is True:
Expand All @@ -49,7 +50,7 @@ async def get_permissions(self, guild) -> list[str]:
)
@commands.is_owner()
@commands.dm_only()
async def ServerOwnerList(self, ctx):
async def ServerOwnerList(self, ctx: commands.Context):
servers_and_owners = []
for guild in self.bot.guilds:
servers_and_owners.append(
Expand All @@ -75,7 +76,7 @@ async def ServerOwnerList(self, ctx):
)
@commands.is_owner()
@commands.dm_only()
async def LeaveServer(self, ctx, Server_ID=""):
async def LeaveServer(self, ctx: commands.Context, Server_ID: str = ""):
if Server_ID:
if Server_ID.isnumeric():
guild = self.bot.get_guild(int(Server_ID))
Expand Down Expand Up @@ -109,7 +110,7 @@ async def LeaveServer(self, ctx, Server_ID=""):
"can do this. Supports no arguments."
),
)
async def Leave(self, ctx):
async def Leave(self, ctx: commands.Context):
if ctx.guild is not None:
application = await self.bot.application_info()
if (
Expand Down Expand Up @@ -137,7 +138,7 @@ async def Leave(self, ctx):
"optional argument as the server ID."
),
)
async def ListPermissions(self, ctx, Server_ID=""):
async def ListPermissions(self, ctx: commands.Context, Server_ID: str = ""):
guild = None
# If Server_ID is provided and the command was used in DM's
if Server_ID and ctx.guild is None:
Expand Down Expand Up @@ -179,11 +180,11 @@ async def ListPermissions(self, ctx, Server_ID=""):
)

@commands.command()
async def test(self, ctx):
async def test(self, ctx: commands.Context):
await ctx.send("*Meows*")

print("Started Control!")


async def setup(bot):
async def setup(bot: commands.Bot):
await bot.add_cog(Control(bot))
35 changes: 23 additions & 12 deletions cogs/Entanglement.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


class Entanglements(commands.Cog):
def __init__(self, bot):
def __init__(self, bot: commands.Bot):
self.bot = bot

if "discord.Entanglement" in logging.Logger.manager.loggerDict:
Expand Down Expand Up @@ -134,7 +134,7 @@ async def generatefilename(self) -> str:
description=("Stops and disconnects the bot. " "Supports no arguments."),
)
@commands.is_owner()
async def observe(self, ctx):
async def observe(self, ctx: commands.Context):
await ctx.reply("QuantumKat's superposition has collapsed!", silent=True)
await self.bot.close()

Expand All @@ -150,7 +150,7 @@ async def observe(self, ctx):
"to reload all.",
)
@commands.is_owner()
async def stabilise(self, ctx, *, module: str = ""):
async def stabilise(self, ctx: commands.Context, *, module: str = ""):
if module:
location = choice(["reality", "universe", "dimension", "timeline"])
if module == "*":
Expand Down Expand Up @@ -228,7 +228,7 @@ async def stabilise(self, ctx, *, module: str = ""):
),
)
@commands.is_owner()
async def entangle(self, ctx, *, module: str = ""):
async def entangle(self, ctx: commands.Context, *, module: str = ""):
if module:
cogs = module.split()
for cog in cogs:
Expand Down Expand Up @@ -268,7 +268,7 @@ async def entangle(self, ctx, *, module: str = ""):
),
)
@commands.is_owner()
async def unentangle(self, ctx, *, module: str = ""):
async def unentangle(self, ctx: commands.Context, *, module: str = ""):
if module:
cogs = module.split()
for cog in cogs:
Expand Down Expand Up @@ -312,7 +312,14 @@ async def unentangle(self, ctx, *, module: str = ""):
),
)
@commands.is_owner()
async def quantize(self, ctx, URL="", filename="", location="", mode=""):
async def quantize(
self,
ctx: commands.Context,
URL: str = "",
filename: str = "",
location: str = "",
mode: str = "",
):
oldfilename = filename

# Check if user has given all required inputs
Expand Down Expand Up @@ -628,7 +635,9 @@ async def quantize(self, ctx, URL="", filename="", location="", mode=""):
description="Renames the specified file. Requires and supports 2 arguments. Only alphanumeric, underscores and a single dot allowed, and at least one character must appear after the dot when choosing a new name.",
)
@commands.is_owner()
async def requantize(self, ctx, current_filename="", new_filename=""):
async def requantize(
self, ctx: commands.Context, current_filename: str = "", new_filename: str = ""
):
if current_filename and new_filename:

data_dir = self.aaaa_dir
Expand Down Expand Up @@ -680,7 +689,7 @@ async def requantize(self, ctx, current_filename="", new_filename=""):
description="Run any git command by passing along the arguments specified. Mainly used for updating the bot or swapping versions, but there is no limit.",
)
@commands.is_owner()
async def git(self, ctx, *, git_arguments=""):
async def git(self, ctx: commands.Context, *, git_arguments: str = ""):
if git_arguments:

# Only allow alphanumeric, underscores, hyphens and whitespaces
Expand Down Expand Up @@ -882,7 +891,9 @@ def check(m: Message): # m = discord.Message.
description="Attempts to delete the specified file. Supports and requires 2 arguments, being the filename, and location (aaaa|possum).",
)
@commands.is_owner()
async def dequantise(self, ctx, filename="", location=""):
async def dequantise(
self, ctx: commands.Context, filename: str = "", location: str = ""
):
if filename and location:

data_dir = ""
Expand Down Expand Up @@ -937,7 +948,7 @@ async def dequantise(self, ctx, filename="", location=""):

@commands.command()
@commands.is_owner()
async def status(self, ctx):
async def status(self, ctx: commands.Context):
await ctx.reply(
f"""
Current CPU Usage: {cpu_percent(1)}%
Expand All @@ -951,7 +962,7 @@ async def status(self, ctx):

@commands.command()
@commands.is_owner()
async def reboot(self, ctx):
async def reboot(self, ctx: commands.Context):
await ctx.send("Shutting down extensions and rebooting...")
for cog in listdir("./cogs"):
if cog.endswith(".py"):
Expand All @@ -967,5 +978,5 @@ async def reboot(self, ctx):
print("Started Entanglements!")


async def setup(bot):
async def setup(bot: commands.Bot):
await bot.add_cog(Entanglements(bot))
22 changes: 13 additions & 9 deletions cogs/Field.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ async def pr(self, ctx: commands.Context):
brief="Pets another user, the bot or themselves a random amount.",
description="Supports one argument, being whatever or whoever the user wants to pet. If no argument is included, the bot pets the user who ran the command. Does between a 1 and 20 long pet.",
)
async def pet(self, ctx: commands.Context, *, optional_user_or_object=""):
async def pet(self, ctx: commands.Context, *, optional_user_or_object: str = ""):
quantum_amount = randint(1, 20)
if quantum_amount == 1:
verb = "time"
Expand Down Expand Up @@ -164,7 +164,7 @@ async def quantumloop(self, ctx):
brief="Hugs another user, the bot or themselves a random amount.",
description="Supports one argument, being whatever or whoever the user wants to hug. If no argument is included, the bot hugs the user who ran the command. Does between a 1 and 20 long hug.",
)
async def hug(self, ctx: commands.Context, *, optional_user_or_object=""):
async def hug(self, ctx: commands.Context, *, optional_user_or_object: str = ""):
quantum_amount = randint(1, 20)
if quantum_amount == 1:
verb = "time"
Expand Down Expand Up @@ -212,7 +212,9 @@ async def hug(self, ctx: commands.Context, *, optional_user_or_object=""):
brief="Pets another user, the bot or themselves a large random amount.",
description="Supports one argument, being whatever or whoever the user wants to pet. If no argument is included, the bot pets the user who ran the command. Does between a 100 and 1000 long pet.",
)
async def quantumpet(self, ctx: commands.Context, *, optional_user_or_object=""):
async def quantumpet(
self, ctx: commands.Context, *, optional_user_or_object: str = ""
):
mention = f"<@{self.bot.user.id}>"
quantum_amount = randint(100, 1000)
qpets = "pe" + ("t" * int(str(quantum_amount)[:2])) + "s"
Expand Down Expand Up @@ -256,7 +258,9 @@ async def quantumpet(self, ctx: commands.Context, *, optional_user_or_object="")
brief="Hugs another user, the bot or themselves a large random amount.",
description="Supports one argument, being whatever or whoever the user wants to hug. If no argument is included, the bot hugs the user who ran the command. Does between a 100 and 1000 long hug.",
)
async def quantumhug(self, ctx: commands.Context, *, optional_user_or_object=""):
async def quantumhug(
self, ctx: commands.Context, *, optional_user_or_object: str = ""
):
mention = f"<@{self.bot.user.id}>"
quantum_amount = randint(100, 1000)
qhugs = "hu" + ("g" * int(str(quantum_amount)[:2])) + "s"
Expand Down Expand Up @@ -292,7 +296,7 @@ async def quantumhug(self, ctx: commands.Context, *, optional_user_or_object="")
brief="Rock, Paper, Scissors game.",
description="A Rock, Paper, Scissors game. Supports one argument, being the chosen gesture. Emote is also supported. Is not rigged.",
)
async def rps(self, ctx: commands.Context, *, item=""):
async def rps(self, ctx: commands.Context, *, item: str = ""):
substring = [
"rock",
"rocks",
Expand Down Expand Up @@ -331,7 +335,7 @@ async def rps(self, ctx: commands.Context, *, item=""):
brief="aaaa search function.",
description="Searches aaaa with the given argument and returns the results. Only takes one, and limited to a minimum of two characters, being alphanumeric as well as a dot.",
)
async def aaaasearch(self, ctx: commands.Context, search_keyword=""):
async def aaaasearch(self, ctx: commands.Context, search_keyword: str = ""):
if len(search_keyword) >= 2:
allowed = compile("^(\.?)[a-zA-Z0-9]+(\.?)$")
if allowed.match(search_keyword):
Expand Down Expand Up @@ -364,7 +368,7 @@ async def aaaasearch(self, ctx: commands.Context, search_keyword=""):
brief="Appends filename to aaaa.lobadk.com.",
description="Appends the provided filename to the end of aaaa.lobadk.com/, to quickly link the file. Only alphanumeric characters and a dot is allowed.",
)
async def a(self, ctx: commands.Context, filename=""):
async def a(self, ctx: commands.Context, filename: str = ""):
if filename:
allowed = compile("[^\w.\-]")
if not allowed.match(filename):
Expand Down Expand Up @@ -404,7 +408,7 @@ async def quantumjoke(self, ctx: commands.Context):
brief="Search aaaa.lobadk.com and return a random result.",
description="Queries aaaa.lobadk.com with the provided search, and returns a random file from it. Supports one argument",
)
async def arsearch(self, ctx: commands.Context, search_keyword=""):
async def arsearch(self, ctx: commands.Context, search_keyword: str = ""):
if search_keyword:
allowed = compile("[^\w.\-]")
if not allowed.match(search_keyword):
Expand All @@ -431,7 +435,7 @@ async def arsearch(self, ctx: commands.Context, search_keyword=""):
brief="Test if the bot works, and it's latency.",
description="Tests if the bot is seeing the command as well as capable of responding. Supports one, but not required, argument, as 'latency'. If latency argument is used, tests and displays the one-way latency from your home, to Discord, and then to the bot (with a multiplication of 2 to simulate round-trip), as well as the round-trip latency between the bot and Discord.",
)
async def ping(self, ctx: commands.Context, ping_mode=""):
async def ping(self, ctx: commands.Context, ping_mode: str = ""):
LatencyResponses = [
"Fiber is fast and all but they really should consider swapping to QuantumCables:tm:.",
"You know, I could've quantised *at least* 100x the amount of data in that time.",
Expand Down
10 changes: 6 additions & 4 deletions cogs/Tunnel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class Tunnel(commands.Cog):
def __init__(self, bot):
def __init__(self, bot: commands.Bot):
self.bot = bot

if "discord.Tunnel" in logging.Logger.manager.loggerDict:
Expand All @@ -29,7 +29,9 @@ def __init__(self, bot):
self.logger.addHandler(handler)

@commands.Cog.listener()
async def on_command_error(self, ctx, error):
async def on_command_error(
self, ctx: commands.Context, error: commands.CommandError
):
if hasattr(ctx.command, "on_error"):
return

Expand Down Expand Up @@ -69,13 +71,13 @@ async def on_command_error(self, ctx, error):
)

@commands.Cog.listener()
async def on_command_completion(self, ctx):
async def on_command_completion(self, ctx: commands.Context):
self.logger.info(
f"Command {ctx.command} completed by {ctx.author}, {ctx.author.id} Message ID: {ctx.message.id} Time: {datetime.now()}"
)

print("Started Tunnel!")


async def setup(bot):
async def setup(bot: commands.Bot):
await bot.add_cog(Tunnel(bot))

0 comments on commit 85f1e69

Please sign in to comment.