From 1bc7dac66da1246395f448d8fe7aa13c2000452a Mon Sep 17 00:00:00 2001 From: Paul Maris <71769515+PaulMarisOUMary@users.noreply.github.com> Date: Mon, 21 Mar 2022 14:02:26 +0100 Subject: [PATCH 1/2] add guild_only protection --- cogs/admin.py | 2 ++ cogs/privatetextual.py | 4 ++++ cogs/usefull.py | 1 + cogs/views.py | 3 +++ 4 files changed, 10 insertions(+) diff --git a/cogs/admin.py b/cogs/admin.py index 61f7b3f..fdf8895 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -118,6 +118,7 @@ async def kill_loop(self, ctx, cog): @commands.command(name="deletechannel", aliases=["delc"], require_var_positional=True) @commands.is_owner() + @commands.guild_only() async def delete_channel(self, ctx, channel_name): """Delete the provided channel.""" channel = discord.utils.get(ctx.guild.channels, name=channel_name) @@ -128,6 +129,7 @@ async def delete_channel(self, ctx, channel_name): @commands.command(name="changeprefix", aliases=["cp"], require_var_positional=True) @commands.has_guild_permissions(administrator=True) + @commands.guild_only() async def change_guild_prefix(self, ctx, new_prefix): """Change the guild prefix.""" try: diff --git a/cogs/privatetextual.py b/cogs/privatetextual.py index ac76b48..e88d2ca 100644 --- a/cogs/privatetextual.py +++ b/cogs/privatetextual.py @@ -34,6 +34,7 @@ def help_custom(self): @commands.command(name="createprivate", aliases=["create", '+'], require_var_positional=True) @commands.cooldown(1, 10, commands.BucketType.user) + @commands.guild_only() async def create_private_channel(self, ctx, *members : discord.Member): """Create a private textual channel.""" users, mentions, down_role = [ctx.message.author], "", discord.utils.get(ctx.guild.roles, name="๐ŸŽ“Student") @@ -59,6 +60,7 @@ async def create_private_channel(self, ctx, *members : discord.Member): await ctx.message.add_reaction(emoji="") @commands.command(name="deleteprivate", aliases=["delete", '-']) + @commands.guild_only() async def delete_private_channel(self, ctx): """Delete your private textual channel.""" channel, roles = ctx.channel, get_created_roles(ctx) @@ -69,6 +71,7 @@ async def delete_private_channel(self, ctx): raise commands.CommandError("You can't delete a non-team channel.") @commands.command(name="renameprivate", aliases=["rename", '_'], require_var_positional=True) + @commands.guild_only() async def rename_private_channel(self, ctx, custom_name : str): """Rename your private textual channel.""" channel, roles = ctx.channel, get_created_roles(ctx) @@ -81,6 +84,7 @@ async def rename_private_channel(self, ctx, custom_name : str): if forbidden: raise commands.CommandError(f"You can't use `{forbidden}` to rename a channel.") @commands.command(name="addprivate", aliases=["add", '>'], require_var_positional=True) + @commands.guild_only() async def addd_to_private_channel(self, ctx, *members : discord.Member): """Join a specified member to your team channel.""" roles = get_created_roles(ctx) diff --git a/cogs/usefull.py b/cogs/usefull.py index 51153f8..3edd740 100644 --- a/cogs/usefull.py +++ b/cogs/usefull.py @@ -12,6 +12,7 @@ def help_custom(self): return emoji, label, description @commands.command(name="strawpoll", aliases=["straw", "stp", "sond", "sondage"], require_var_positional=True) + @commands.guild_only() async def strawpool(self, ctx, *, context): """Ask a sondage, and add 2 reactions to vote with your community.""" crossmark, checkmark = self.bot.get_emoji(842800737221607474), self.bot.get_emoji(842800730049871892) diff --git a/cogs/views.py b/cogs/views.py index 5803b05..31579ec 100644 --- a/cogs/views.py +++ b/cogs/views.py @@ -17,12 +17,14 @@ def help_custom(self): return emoji, label, description @commands.command(name="bool") + @commands.guild_only() async def boo(self, ctx): """Discover buttons feature with this command.""" view = bool.View(flabel="Agree", slabel="Disagree", sstyle=discord.ButtonStyle.red, emojis = True, source=ctx) await ctx.send("Buttons demo right there !", view=view) @commands.command(name="dropdown") + @commands.guild_only() async def dro(self, ctx): """Discover select menu feature with this command.""" options = [ @@ -54,6 +56,7 @@ async def dro(self, ctx): await ctx.send("Dropdown demo right there !", view=view) @commands.command(name="link") + @commands.guild_only() async def lin(self, ctx): """Discover button link with this feature.""" view = link.View(label="Source code on Github", url="https://github.com/PaulMarisOUMary/Algosup-Discord") From 37df02901b8afe9a0258625fc30bb5515dc70d85 Mon Sep 17 00:00:00 2001 From: Paul Maris <71769515+PaulMarisOUMary@users.noreply.github.com> Date: Mon, 21 Mar 2022 20:33:11 +0100 Subject: [PATCH 2/2] update return hint & syntax convention --- cogs/admin.py | 22 +++++++++++++------- cogs/basic.py | 5 +++-- cogs/birthday.py | 13 +++++++----- cogs/croissants.py | 12 ++++++----- cogs/dad.py | 4 ++-- cogs/errors.py | 7 +++++-- cogs/fridaycake.py | 18 +++++++++------- cogs/help.py | 9 ++++---- cogs/info.py | 47 +++++++++++++++++++++++++++--------------- cogs/me.py | 10 +++++---- cogs/privatetextual.py | 40 +++++++++++++++++++++-------------- cogs/spotify.py | 14 ++++++++----- cogs/status.py | 16 ++++++++------ cogs/traductor.py | 7 ++++--- cogs/usefull.py | 6 ++++-- cogs/views.py | 6 ++++-- 16 files changed, 146 insertions(+), 90 deletions(-) diff --git a/cogs/admin.py b/cogs/admin.py index fdf8895..e1776b7 100644 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -8,10 +8,10 @@ class Admin(commands.Cog, name="admin"): """Admin commands, you probably don't have the permission to use them.""" - def __init__(self, bot): + def __init__(self, bot) -> None: self.bot = bot - def help_custom(self): + def help_custom(self) -> tuple[str]: emoji = 'โš™๏ธ' label = "Admin" description = "Show the list of admin commands." @@ -28,7 +28,8 @@ async def reload_views(self) -> list[str]: if os.path.basename(os.path.dirname(module.__file__)) == "views": reload(module) infants.append(module.__name__) - except: pass + except: + pass return infants @@ -56,9 +57,11 @@ async def reload_all(self, ctx): await ctx.send(f"{e.__class__.__name__}: {e}") else: succes_text = f"๐Ÿ’ช All cogs reloaded ! | โ˜ ๏ธ __`{len(victims)} task(s) killed`__ : " - for victim in victims: succes_text += f"`{victim.replace('cogs.', '')}` " + for victim in victims: + succes_text += f"`{victim.replace('cogs.', '')}` " succes_text += f"| ๐Ÿ”„ __`{len(infants)} view(s) reloaded`__ : " - for infant in infants: succes_text += f"`{infant.replace('views.', '')}` " + for infant in infants: + succes_text += f"`{infant.replace('views.', '')}` " await ctx.send(succes_text) @commands.command(name="reload", aliases=["rel"], require_var_positional=True) @@ -84,7 +87,8 @@ async def reload_latest(self, ctx): if actual[1] == ".py": file_path = os.path.join(cogs_directory, file) latest_edit = os.path.getmtime(file_path) - if latest_edit > latest_cog[1]: latest_cog = (actual[0], latest_edit) + if latest_edit > latest_cog[1]: + latest_cog = (actual[0], latest_edit) try: victims = await self.reload_cogs([f"cogs.{latest_cog[0]}"]) @@ -103,7 +107,8 @@ async def reload_view(self, ctx): await ctx.send(f"{e.__class__.__name__}: {e}") else: succes_text = f"๐Ÿ‘Œ All views reloaded ! | ๐Ÿ”„ __`{len(infants)} view(s) reloaded`__ : " - for infant in infants: succes_text += f"`{infant.replace('views.', '')}` " + for infant in infants: + succes_text += f"`{infant.replace('views.', '')}` " await ctx.send(succes_text) @commands.command(name="killloop", aliases=["kill"], require_var_positional=True) @@ -114,7 +119,8 @@ async def kill_loop(self, ctx, cog): if "return_loop_task" in dir(cogs): cogs.return_loop_task().cancel() await ctx.send("Task successfully killed") - else : await ctx.send("Task not found..") + else: + await ctx.send("Task not found..") @commands.command(name="deletechannel", aliases=["delc"], require_var_positional=True) @commands.is_owner() diff --git a/cogs/basic.py b/cogs/basic.py index 542f544..ea2fd57 100644 --- a/cogs/basic.py +++ b/cogs/basic.py @@ -1,13 +1,14 @@ import time +from tkinter import NONE from discord.ext import commands class Basic(commands.Cog, name="basic"): """Basic commands, like ping.""" - def __init__(self, bot): + def __init__(self, bot) -> None: self.bot = bot - def help_custom(self): + def help_custom(self) -> tuple[str]: emoji = '๐Ÿ“™' label = "Basic" description = "Basic commands, like ping." diff --git a/cogs/birthday.py b/cogs/birthday.py index e5f25c2..f605833 100644 --- a/cogs/birthday.py +++ b/cogs/birthday.py @@ -8,14 +8,14 @@ class Birthday(commands.Cog, name="birthday"): """I'll wish you soon a happy birthday !""" - def __init__(self, bot): + def __init__(self, bot) -> None: self.bot = bot self.birthday_data = self.bot.database_data["birthday"] self.daily_birthday.start() - def help_custom(self): + def help_custom(self) -> tuple[str]: emoji = '๐ŸŽ' label = "Birthday" description = "Maybe I'll wish you soon a happy birthday !" @@ -42,7 +42,8 @@ async def daily_birthday(self): "https://sayingimages.com/wp-content/uploads/funny-birthday-and-believe-me-memes.jpg", "https://i.kym-cdn.com/photos/images/newsfeed/001/988/649/1e8.jpg", "https://winkgo.com/wp-content/uploads/2018/08/101-Best-Happy-Birthday-Memes-01-720x720.jpg", - "https://www.the-best-wishes.com/wp-content/uploads/2022/01/success-kid-cute-birthday-meme-for-her.jpg"] + "https://www.the-best-wishes.com/wp-content/uploads/2022/01/success-kid-cute-birthday-meme-for-her.jpg" + ] embed = discord.Embed(title="๐ŸŽ‰ Happy birthday !", description=message, colour=discord.Colour.dark_gold()) embed.set_image(url=images[random.randint(0, len(images)-1)]) @@ -60,7 +61,8 @@ async def birthday(self, ctx, date: str = None): if date: try: dataDate = datetime.strptime(date, "%d/%m/%Y").date() - if dataDate.year > datetime.now().year - 15 or dataDate.year < datetime.now().year - 99: raise commands.CommandError("Please provide your real year of birth.") + if dataDate.year > datetime.now().year - 15 or dataDate.year < datetime.now().year - 99: + raise commands.CommandError("Please provide your real year of birth.") # Insert await self.bot.database.insert(self.birthday_data["table"], {"user_id": ctx.author.id, "user_birth": dataDate}) # Update @@ -78,7 +80,8 @@ async def birthday(self, ctx, date: str = None): @commands.cooldown(1, 5, commands.BucketType.user) async def show_birthday(self, ctx, user: discord.Member = None): """Allows you to show the birthday of other users.""" - if not user: user = ctx.author + if not user: + user = ctx.author await self.show_birthday_message(ctx, user) async def show_birthday_message(self, ctx, user:discord.Member) -> None: diff --git a/cogs/croissants.py b/cogs/croissants.py index c1bc3f1..0a0ea2e 100644 --- a/cogs/croissants.py +++ b/cogs/croissants.py @@ -9,7 +9,7 @@ class Croissants(commands.Cog, name="croissants", command_attrs=dict(hidden=True)): """Don't leave your computer unlocked !""" - def __init__(self, bot): + def __init__(self, bot) -> None: self.bot = bot self.EMOJI = '๐Ÿฅ' @@ -19,7 +19,7 @@ def __init__(self, bot): self.croissants_data = self.bot.database_data["croissants"] - def help_custom(self): + def help_custom(self) -> tuple[str]: emoji = self.EMOJI label = "Croissants" description = "For when someone left their computer unlocked." @@ -80,8 +80,10 @@ def __get_screenshot(self, author : discord.Member, content : str) -> discord.Fi pfp_content = Image.open(BytesIO(requests.get(author.display_avatar.url).content)) images_sequence, duration_array = [], [] for frame in ImageSequence.Iterator(pfp_content): - try: duration_array.append(frame.info["duration"]) - except: duration_array.append(0) + try: + duration_array.append(frame.info["duration"]) + except: + duration_array.append(0) img = Image.new("RGBA", size=(500, 100), color=bg_color) resized_pfp = frame.resize(pfp_size) @@ -111,7 +113,7 @@ def __get_screenshot(self, author : discord.Member, content : str) -> discord.Fi def __is_on_cooldown(self, user) -> bool: return user.id in self.cooldown and datetime.now().timestamp() - self.cooldown[user.id].timestamp() < self.bot.database_data["croissants"]["cooldown"] - def __rank_emoji(self, rank): + def __rank_emoji(self, rank) -> str: if rank == 1: return '๐Ÿฅ‡' elif rank == 2: diff --git a/cogs/dad.py b/cogs/dad.py index 536ef86..099531a 100644 --- a/cogs/dad.py +++ b/cogs/dad.py @@ -6,7 +6,7 @@ class Dad(commands.Cog, name="dad", command_attrs=dict(hidden=True)): """Dad's jokes.""" - def __init__(self, bot): + def __init__(self, bot) -> None: self.bot = bot self.settings = bot.bot_data["dad"] self.pattern = re.compile(r""" @@ -15,7 +15,7 @@ def __init__(self, bot): (?P.+) # The name """, re.VERBOSE + re.IGNORECASE) - def help_custom(self): + def help_custom(self) -> tuple[str]: emoji = '๐Ÿ‘จโ€๐Ÿฆณ' label = "Dad's jokes" description = "Ahah, it was a good one!" diff --git a/cogs/errors.py b/cogs/errors.py index e817dfb..01d4cba 100644 --- a/cogs/errors.py +++ b/cogs/errors.py @@ -2,7 +2,7 @@ class Errors(commands.Cog, name="errors"): """Errors handler.""" - def __init__(self, bot): + def __init__(self, bot) -> None: self.bot = bot """def help_custom(self): @@ -31,7 +31,8 @@ async def get_command_error(self, ctx, error): await message.edit(f"๐Ÿ•ณ๏ธ Command is on cooldown, wait `{str(error).split(' ')[7]}` !") elif isinstance(error, commands.errors.MissingRequiredArgument): command, params = ctx.command, "" - for param in command.clean_params: params += " {"+str(param)+'}' + for param in command.clean_params: + params += " {"+str(param)+'}' await message.edit(f"๐Ÿ•ณ๏ธ Something is missing. `?{command}{params}`") elif isinstance(error, commands.errors.MemberNotFound): await message.edit(f"๐Ÿ•ณ๏ธ Member `{str(error).split(' ')[1]}` not found ! Don't hesitate to ping the requested member.") @@ -45,5 +46,7 @@ async def get_command_error(self, ctx, error): except Exception as e: print(f"! Cogs.errors get_command_error : {type(error).__name__} : {error}\n! Internal Error : {e}\n") + + def setup(bot): bot.add_cog(Errors(bot)) \ No newline at end of file diff --git a/cogs/fridaycake.py b/cogs/fridaycake.py index f5c9fe5..68ca4f7 100644 --- a/cogs/fridaycake.py +++ b/cogs/fridaycake.py @@ -43,7 +43,7 @@ def mix_participants(participants : list, seed : int, n_group : int) -> list[lis class FridayCake(commands.Cog, name="fridaycake", command_attrs=dict(hidden=False)): """FridayCake's event commands.""" - def __init__(self, bot): + def __init__(self, bot) -> None: self.bot = bot self.cakes = ['๐ŸŽ‚', '๐Ÿฅฎ', '๐Ÿฅง', '๐Ÿฅฏ', '๐Ÿง', '๐Ÿซ“', '๐Ÿง‡', '๐Ÿž', '๐Ÿฎ', '๐Ÿฐ', '๐Ÿฅ'] @@ -52,19 +52,19 @@ def __init__(self, bot): self.bot.loop.create_task(self.initFridaycake()) - async def initFridaycake(self): + async def initFridaycake(self) -> None: participants = await self.bot.database.select(self.fridaycake_data["table"], "user_id, user_name", "user_isin = 1", "user_name ASC") participants = [[*row] for row in participants] #convert tuple of tuples to list of lists self.participants = mix_participants(participants, self.seed, 2) self.nparticipants = len(participants) #mandatory in fridaycake view - def help_custom(self): + def help_custom(self) -> tuple[str]: emoji = random.choice(self.cakes) label = "FridayCake" description = "Commands relative to the FridayCake event !" return emoji, label, description - def all(self, ctx): + def all(self, ctx) -> discord.Embed: author = ctx.message.author embed = discord.Embed(title=f"{random.choice(self.cakes)} Fridaycake ยท All", description="`Show your personnal order of passage.`\n\u200b" ,colour=0xf7346b, url='https://github.com/PaulMarisOUMary/Algosup-Discord') embed.set_thumbnail(url="https://cdn.discordapp.com/attachments/332696002144501760/800791318200188998/fridaycake.png") @@ -76,7 +76,7 @@ def all(self, ctx): embed.add_field(name=f"Friday {_date.strftime('%d %B, %Y')}", value=f"~~{string[0:-4]}~~" if date.today() >= _date else f"{string[0:-4]}", inline=False) return embed - def next(self, ctx): + def next(self, ctx) -> discord.Embed: author, pin = ctx.message.author, [] for participants, _date in zip(self.participants, get_dates(start, holidays, len(self.participants))): if date.today() <= _date: @@ -94,11 +94,12 @@ def next(self, ctx): embed.add_field(name="๐Ÿ‘ฅ Participants :", value=participants, inline=False) return embed - def when(self, author): + def when(self, author) -> discord.Embed: pin = None for participants, _date in zip(self.participants, get_dates(start, holidays, len(self.participants))): for participant in participants: - if int(participant[0]) == author.id: pin = (participants, _date) + if int(participant[0]) == author.id: + pin = (participants, _date) if not pin: raise commands.CommandError("You are not registered for the FridayCake.") else: @@ -138,7 +139,8 @@ async def fridaycake(self, ctx): view.stop() await message.delete() await ctx.message.add_reaction("") - except: pass + except: + pass @commands.command(name='next', aliases=['n', 'fn']) async def next_cake(self, ctx): diff --git a/cogs/help.py b/cogs/help.py index 6dd41a6..a54381f 100644 --- a/cogs/help.py +++ b/cogs/help.py @@ -36,7 +36,8 @@ async def send_bot_help(self, mapping) -> None: view.stop() await message.delete() await self.context.message.add_reaction("") - except: pass + except: + pass async def send_command_help(self, command): cog = command.cog @@ -68,7 +69,7 @@ async def send_group_help(self, group): class Help(commands.Cog, name="help"): """Help commands.""" - def __init__(self, bot): + def __init__(self, bot) -> None: self._original_help_command = bot.help_command attributes = { @@ -80,10 +81,10 @@ def __init__(self, bot): bot.help_command = HelpCommand(command_attrs=attributes) bot.help_command.cog = self - def cog_unload(self): + def cog_unload(self) -> None: self.bot.help_command = self._original_help_command - def help_custom(self): + def help_custom(self) -> tuple[str]: emoji = '๐Ÿ†˜' label = "Help" description = "Help utilities." diff --git a/cogs/info.py b/cogs/info.py index 9dde3e9..f63e7c9 100644 --- a/cogs/info.py +++ b/cogs/info.py @@ -6,7 +6,7 @@ from datetime import datetime from discord.ext import commands -def statServer(guild): +def statServer(guild) -> dict: status = {} must = ["members", "bot", "streaming", "idle", "dnd", "online", "offline", "mobile"] for a in must: @@ -14,8 +14,10 @@ def statServer(guild): for member in guild: status["members"] += 1 status[str(member.status)] += 1 - if member.is_on_mobile(): status["mobile"] += 1 - if member.bot: status["bot"] += 1 + if member.is_on_mobile(): + status["mobile"] += 1 + if member.bot: + status["bot"] += 1 if member.activity or member.activities: for activity in member.activities: if activity.type == discord.ActivityType.streaming: @@ -25,10 +27,10 @@ def statServer(guild): class Info(commands.Cog, name="info"): """Info & statistics.""" - def __init__(self, bot): + def __init__(self, bot) -> None: self.bot = bot - def help_custom(self): + def help_custom(self) -> tuple[str]: emoji = '๐Ÿ“Š' label = "Info" description = "Commands about additionals informations such as stats." @@ -41,13 +43,15 @@ async def getcustomemojis(self, ctx): """Return a list of each cutom emojis from the current server.""" embed_list, embed = [], discord.Embed(title=f"Custom Emojis List ({len(ctx.guild.emojis)}) :") for i, emoji in enumerate(ctx.guild.emojis, start=1): - if i == 0 : i += 1 + if i == 0 : + i += 1 value = f"`<:{emoji.name}:{emoji.id}>`" if not emoji.animated else f"``" embed.add_field(name=f"{self.bot.get_emoji(emoji.id)} - **:{emoji.name}:** - (*{i}*)",value=value) if len(embed.fields) == 25: embed_list.append(embed) embed = discord.Embed() - if len(embed.fields) > 0: embed_list.append(embed) + if len(embed.fields) > 0: + embed_list.append(embed) for message in embed_list: await ctx.send(embed=message) @@ -75,13 +79,15 @@ async def stat(self, ctx): @commands.command(name="profilepicture", aliases=["pp"]) async def profilepicture(self, ctx, member : discord.Member = None): """Show the profile picture of the selected member.""" - if not member: member = ctx.author + if not member: + member = ctx.author await ctx.send(member.display_avatar.url) @commands.command(name="bannerpicture", aliases=["bp"]) async def bannerpicture(self, ctx, member : discord.Member = None): """Show the banner picture of the selected member.""" - if not member: member = ctx.author + if not member: + member = ctx.author user = await self.bot.fetch_user(member.id) try: await ctx.send(user.banner.url) @@ -93,12 +99,14 @@ async def bannerpicture(self, ctx, member : discord.Member = None): @commands.guild_only() async def lookup(self, ctx, member: discord.Member = None): """Show few information about a discord Member""" - if not member: member = ctx.author - + if not member: + member = ctx.author + try: user = await self.bot.fetch_user(member.id) user_banner = user.banner.url - except: user_banner = None + except: + user_banner = None yes = "" no = "" @@ -107,10 +115,14 @@ async def lookup(self, ctx, member: discord.Member = None): embed.set_author(name=f"Lookup: {member.display_name}", icon_url=member.default_avatar.url) embed.add_field(name="ID:", value=f"`{member.id}`", inline=True) embed.add_field(name="Display name:", value=f"`{member.name}#{member.discriminator}`", inline=True) - if member.status == discord.Status.online: embed.add_field(name="Status", value=f"<:online:698246924465340497> Online", inline=True) - elif member.status == discord.Status.idle: embed.add_field(name="Status", value=f"<:idle:698246924058361898> Idle", inline=True) - elif member.status == discord.Status.dnd: embed.add_field(name="Status", value=f"<:dnd:698246924528254986> Do not disturb", inline=True) - else: embed.add_field(name="Status", value=f"<:offline:698246924138184836> Offline", inline=True) + if member.status == discord.Status.online: + embed.add_field(name="Status", value=f"<:online:698246924465340497> Online", inline=True) + elif member.status == discord.Status.idle: + embed.add_field(name="Status", value=f"<:idle:698246924058361898> Idle", inline=True) + elif member.status == discord.Status.dnd: + embed.add_field(name="Status", value=f"<:dnd:698246924528254986> Do not disturb", inline=True) + else: + embed.add_field(name="Status", value=f"<:offline:698246924138184836> Offline", inline=True) embed.add_field(name="\u200b", value="\u200b", inline=False) embed.add_field(name="<:isbot:698250069165473852> Is a bot?", value=f"{yes if member.bot else no}", inline=True) embed.add_field(name="<:phone:948279755248111756> Is on mobile?", value=f"{yes if member.is_on_mobile() else no}", inline=True) @@ -119,7 +131,8 @@ async def lookup(self, ctx, member: discord.Member = None): embed.add_field(name="<:plus:948272417304883270> Account created at:", value=f"", inline=True) embed.add_field(name="<:join:948272122353057792> Joined the server at:", value=f"", inline=True) embed.set_thumbnail(url=member.display_avatar.url) - if user_banner: embed.set_image(url=user_banner) + if user_banner: + embed.set_image(url=user_banner) embed.set_footer(text=f"(The discord profile picture next to the 'lookup' text is your default profile picture.)\nRequested by : {ctx.message.author} at {time.strftime('%H:%M:%S')}", icon_url=ctx.message.author.display_avatar.url) await ctx.send(embed=embed) diff --git a/cogs/me.py b/cogs/me.py index 71a369f..81d2f5a 100644 --- a/cogs/me.py +++ b/cogs/me.py @@ -4,13 +4,13 @@ class Me(commands.Cog, name="me"): """Like minecraft set your own /me !""" - def __init__(self, bot): + def __init__(self, bot) -> None: self.bot = bot self.me_data = self.bot.database_data["me"] self.max_lenght_me = self.me_data["max_length"] - def help_custom(self): + def help_custom(self) -> tuple[str]: emoji = '๐Ÿค™' label = "Me" description = "Set and show a brief description of yourself." @@ -23,7 +23,8 @@ async def me(self, ctx, *args: str): if len(args): try: text = " ".join(args).replace("'", "''") - if len(text) > self.max_lenght_me: raise commands.CommandError(f"The max-lenght of your *me* is set to: __{self.max_lenght_me}__ (yours is {len(text)}).") + if len(text) > self.max_lenght_me: + raise commands.CommandError(f"The max-lenght of your *me* is set to: __{self.max_lenght_me}__ (yours is {len(text)}).") # Insert await self.bot.database.insert(self.me_data["table"], {"user_id": ctx.author.id, "user_me": text}) # Update @@ -38,7 +39,8 @@ async def me(self, ctx, *args: str): @commands.cooldown(1, 5, commands.BucketType.user) async def show_me(self, ctx, user: discord.Member = None): """Allows you to show the description of other users.""" - if not user: user = ctx.author + if not user: + user = ctx.author await self.show_me_message(ctx, user) async def show_me_message(self, ctx, user: discord.Member) -> None: diff --git a/cogs/privatetextual.py b/cogs/privatetextual.py index e88d2ca..fe4ee3a 100644 --- a/cogs/privatetextual.py +++ b/cogs/privatetextual.py @@ -2,7 +2,7 @@ from discord.ext import commands -def text_to_allowed(input): +def text_to_allowed(input) -> tuple[str, list]: out, forbidden, line = "", [], input.lower() for char in line: if not char in "abcdefghijklmnopqrstuvwxyz-_0123456789": @@ -12,7 +12,7 @@ def text_to_allowed(input): return out, forbidden -def get_created_roles(cont): +def get_created_roles(cont) -> list: wrong_roles = [] for role in cont.guild.roles: perm = cont.channel.overwrites_for(role) @@ -23,10 +23,10 @@ def get_created_roles(cont): class PrivateTextual(commands.Cog, name="privatetextual"): """Create and manage private textual channels.""" - def __init__(self, bot): + def __init__(self, bot) -> None: self.bot = bot - def help_custom(self): + def help_custom(self) -> tuple[str]: emoji = '๐Ÿ’ฌ' label = "Private Textual" description = "Add and edit textuals channels." @@ -40,16 +40,21 @@ async def create_private_channel(self, ctx, *members : discord.Member): users, mentions, down_role = [ctx.message.author], "", discord.utils.get(ctx.guild.roles, name="๐ŸŽ“Student") for g in members: - if g.bot: raise commands.CommandError("You can't invite bots in your team.") - else: users.append(g) + if g.bot: + raise commands.CommandError("You can't invite bots in your team.") + else: + users.append(g) users = list(set(users)) - if len(users) <= 1: raise commands.CommandError("You can't create a team alone.") + if len(users) <= 1: + raise commands.CommandError("You can't create a team alone.") role = await ctx.guild.create_role(name="team") team_channel = await ctx.guild.create_text_channel(name="_team_text", category=discord.utils.get(ctx.guild.categories, id=ctx.channel.category_id)) await team_channel.set_permissions(role, add_reactions=True, attach_files=True, embed_links=True, external_emojis=True, manage_messages=True, read_message_history=True, read_messages=True, send_messages=True, use_external_emojis=True, use_slash_commands=True, view_channel=True) - try: await team_channel.set_permissions(down_role, send_messages=False, view_channel=False) - except: pass + try: + await team_channel.set_permissions(down_role, send_messages=False, view_channel=False) + except: + pass for user in users: await user.add_roles(role) @@ -77,11 +82,12 @@ async def rename_private_channel(self, ctx, custom_name : str): channel, roles = ctx.channel, get_created_roles(ctx) normalize_cn, forbidden = text_to_allowed(custom_name) if '_' in channel.name and roles and len(normalize_cn) > 0: - await channel.edit(name='_'+normalize_cn) - await ctx.message.add_reaction(emoji="") + await channel.edit(name='_'+normalize_cn) + await ctx.message.add_reaction(emoji="") elif not '_' in channel.name: raise commands.CommandError("You can't rename a non-team channel.") - if forbidden: raise commands.CommandError(f"You can't use `{forbidden}` to rename a channel.") + if forbidden: + raise commands.CommandError(f"You can't use `{forbidden}` to rename a channel.") @commands.command(name="addprivate", aliases=["add", '>'], require_var_positional=True) @commands.guild_only() @@ -89,9 +95,13 @@ async def addd_to_private_channel(self, ctx, *members : discord.Member): """Join a specified member to your team channel.""" roles = get_created_roles(ctx) for member in members: - if not member.bot : await member.add_roles(roles[0]) - else : raise commands.CommandError("You can't invite bots in your team.") + if not member.bot : + await member.add_roles(roles[0]) + else : + raise commands.CommandError("You can't invite bots in your team.") await ctx.message.add_reaction(emoji="") + + def setup(bot): - bot.add_cog(PrivateTextual(bot)) + bot.add_cog(PrivateTextual(bot)) \ No newline at end of file diff --git a/cogs/spotify.py b/cogs/spotify.py index 9942b1e..c761794 100644 --- a/cogs/spotify.py +++ b/cogs/spotify.py @@ -5,10 +5,10 @@ class Spotify(commands.Cog, name="spotify"): """Show Spotify songs.""" - def __init__(self, bot): + def __init__(self, bot) -> None: self.bot = bot - def help_custom(self): + def help_custom(self) -> tuple[str]: emoji = "<:spotify:880896591756656641>" label = "Spotify" description = "Spotify status commands." @@ -18,7 +18,8 @@ def help_custom(self): async def actual_calendar(self, ctx, user: discord.Member = None): """Show the current Spotify song.""" keeper = True - if not user: user = ctx.author + if not user: + user = ctx.author for activity in user.activities: if str(activity) == "Spotify": embed, keeper = discord.Embed(colour=activity.colour), False @@ -27,7 +28,10 @@ async def actual_calendar(self, ctx, user: discord.Member = None): embed.set_thumbnail(url=activity.album_cover_url) embed.set_footer(text=f"{str(activity.duration)[2:-7]} | Requested by : {ctx.message.author.name} at {time.strftime('%H:%M:%S')}", icon_url=ctx.message.author.display_avatar.url) await ctx.send(embed=embed) - if keeper: await ctx.send(f"{user.name} is not currently listening to Spotify") + if keeper: + await ctx.send(f"{user.name} is not currently listening to Spotify") + + def setup(bot): - bot.add_cog(Spotify(bot)) + bot.add_cog(Spotify(bot)) \ No newline at end of file diff --git a/cogs/status.py b/cogs/status.py index 3474334..513f220 100644 --- a/cogs/status.py +++ b/cogs/status.py @@ -5,27 +5,31 @@ class Status(commands.Cog, name="status"): """A loop to set the current status of the bot.""" - def __init__(self, bot): + def __init__(self, bot) -> None: self.bot = bot self.task_change_status = self.bot.loop.create_task(self.loop_change_status()) - """def help_custom(self): + """def help_custom(self) -> tuple[str]: emoji = '๐Ÿท๏ธ' label = "Status" description = "Setup the status of the bot." return emoji, label, description""" - def return_loop_task(self): + def return_loop_task(self) -> asyncio.Task: return self.task_change_status - async def loop_change_status(self): + async def loop_change_status(self) -> None: await self.bot.wait_until_ready() status_message, reset = ["?help", "?help basic", "?link"], 0 while not self.bot.is_closed(): await self.bot.change_presence(activity=discord.Activity(type=discord.ActivityType.streaming, name=status_message[reset], url="https://www.twitch.tv/warriormachine_"), status=discord.Status.dnd) await asyncio.sleep(10) - if reset >= len(status_message)-1: reset = 0 - else: reset += 1 + if reset >= len(status_message)-1: + reset = 0 + else: + reset += 1 + + def setup(bot): bot.add_cog(Status(bot)) \ No newline at end of file diff --git a/cogs/traductor.py b/cogs/traductor.py index f866737..9dccd1d 100644 --- a/cogs/traductor.py +++ b/cogs/traductor.py @@ -7,10 +7,10 @@ class Traductor(commands.Cog, name="traductor"): """A Cog to translate each non-English messages.""" - def __init__(self, bot): + def __init__(self, bot) -> None: self.bot = bot - """def help_custom(self): + """def help_custom(self) -> tuple[str]: emoji = '<:Gtranslate:807986736663101440>' label = "Traductor" description = "Informations about the Traductor." @@ -56,7 +56,8 @@ def check(reaction, user) -> bool: await message.clear_reaction(convert_emoji) await message.add_reaction(converted_emoji) - except: pass + except: + pass diff --git a/cogs/usefull.py b/cogs/usefull.py index 3edd740..b92ecef 100644 --- a/cogs/usefull.py +++ b/cogs/usefull.py @@ -2,10 +2,10 @@ class Usefull(commands.Cog, name="usefull"): """Usefull commands for Devs & more.""" - def __init__(self, bot): + def __init__(self, bot) -> None: self.bot = bot - def help_custom(self): + def help_custom(self) -> tuple[str]: emoji = '๐Ÿšฉ' label = "Usefull" description = "Usefull commands." @@ -21,5 +21,7 @@ async def strawpool(self, ctx, *, context): await message.add_reaction(emoji=checkmark) await message.add_reaction(emoji=crossmark) + + def setup(bot): bot.add_cog(Usefull(bot)) diff --git a/cogs/views.py b/cogs/views.py index 31579ec..a3451fb 100644 --- a/cogs/views.py +++ b/cogs/views.py @@ -7,10 +7,10 @@ class Views(commands.Cog, name="views"): """Experimental cog, new features such buttons, dropdown or whispering.""" - def __init__(self, bot): + def __init__(self, bot) -> None: self.bot = bot - def help_custom(self): + def help_custom(self) -> tuple[str]: emoji = '๐Ÿ”˜' label = "Views" description = "Demo : New discord features." @@ -62,5 +62,7 @@ async def lin(self, ctx): view = link.View(label="Source code on Github", url="https://github.com/PaulMarisOUMary/Algosup-Discord") await ctx.send("Find out what is behind Algobot !", view=view) + + def setup(bot): bot.add_cog(Views(bot)) \ No newline at end of file