From 42cf2734635d62bf34aba5ab8d43b5629036171b Mon Sep 17 00:00:00 2001 From: drawbu <69208565+drawbu@users.noreply.github.com> Date: Thu, 8 Sep 2022 23:51:08 +0200 Subject: [PATCH 1/9] :zap: Implement chunked embed message. --- drawbot/cogs/pronote_loop.py | 45 ++++++++++++++++++------------------ drawbot/utils/pronote.py | 6 +++++ 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/drawbot/cogs/pronote_loop.py b/drawbot/cogs/pronote_loop.py index ffd08fd..329dd29 100644 --- a/drawbot/cogs/pronote_loop.py +++ b/drawbot/cogs/pronote_loop.py @@ -1,6 +1,6 @@ import time -from utils import fetch_homeworks, fetch_grades +from utils import fetch_homeworks, fetch_grades, chunks import pronotepy import discord @@ -57,12 +57,12 @@ def discord_timestamp(t_str: str) -> str: auths = {"homeworks": True, "grades": True} - if auths["homeworks"]: - new_homework_count = 0 - for homework in fetch_homeworks(pronote): - new_homework_count += 1 - await pronote_channel.send( - embed=discord.Embed( + new_homework_count = 0 + for homeworks in chunks(list(fetch_homeworks(pronote)), 10): + new_homework_count += len(homeworks) + await pronote_channel.send( + embeds=[ + discord.Embed( title=( f"Nouveau devoir de {homework['subject']}\n" f"Pour le {discord_timestamp(homework['date'])}" @@ -70,14 +70,16 @@ def discord_timestamp(t_str: str) -> str: description=homework["description"], color=0x1E744F, ) - ) - - if auths["grades"]: - new_grades_count = 0 - for grade in fetch_grades(pronote): - new_grades_count += 1 - await pronote_channel.send( - embed=discord.Embed( + for homework in homeworks + ] + ) + + new_grades_count = 0 + for grades in chunks(list(fetch_grades(pronote)), 10): + new_grades_count += len(grades) + await pronote_channel.send( + embeds=[ + discord.Embed( title=( f"Nouvelle note de {grade['subject']}\n" f"Du {discord_timestamp(grade['date'])}" @@ -91,15 +93,14 @@ def discord_timestamp(t_str: str) -> str: ), color=0x1E744F, ) - ) + for grade in grades + ] + ) print( - (date if any(auths) else "") - + (f" - {new_homework_count} nouveaux devoirs" if auths["homeworks"] - else "") - + (f" - {new_grades_count} nouveaux notes" if auths["grades"] - else "") - + (" !" if any(auths) else "") + f"{date} " + f"- {new_homework_count} nouveaux devoirs " + f"- {new_grades_count} nouvelles notes !" ) diff --git a/drawbot/utils/pronote.py b/drawbot/utils/pronote.py index ca190c1..293d1fa 100644 --- a/drawbot/utils/pronote.py +++ b/drawbot/utils/pronote.py @@ -70,3 +70,9 @@ def fetch_from_json(filename: str, json_data: JsonData) -> Generator: continue yield value + + +def chunks(lst, n): + """Yield successive n-sized chunks from lst.""" + for i in range(0, len(lst), n): + yield lst[i:i + n] From 9e95e27b85e2e9c9b97352867ec04aa4238c430b Mon Sep 17 00:00:00 2001 From: drawbu <69208565+drawbu@users.noreply.github.com> Date: Fri, 9 Sep 2022 00:01:25 +0200 Subject: [PATCH 2/9] :pencil2: Removed unused variable `auths`. --- drawbot/cogs/pronote_loop.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/drawbot/cogs/pronote_loop.py b/drawbot/cogs/pronote_loop.py index 329dd29..7f4447e 100644 --- a/drawbot/cogs/pronote_loop.py +++ b/drawbot/cogs/pronote_loop.py @@ -55,8 +55,6 @@ async def refresh_pronote(self): def discord_timestamp(t_str: str) -> str: return f"" - auths = {"homeworks": True, "grades": True} - new_homework_count = 0 for homeworks in chunks(list(fetch_homeworks(pronote)), 10): new_homework_count += len(homeworks) From e2ce62349cc43e86e7810de68e371e84302f1f45 Mon Sep 17 00:00:00 2001 From: drawbu <69208565+drawbu@users.noreply.github.com> Date: Fri, 9 Sep 2022 11:32:35 +0200 Subject: [PATCH 3/9] :recycle: Removed error due to old code not awaited. --- drawbot/bot.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/drawbot/bot.py b/drawbot/bot.py index b62297e..255b937 100644 --- a/drawbot/bot.py +++ b/drawbot/bot.py @@ -40,10 +40,6 @@ def __init__(self): self.remove_command("help") - for filename in os.listdir("drawbot/cogs"): - if filename.endswith(".py") and filename != "__init__.py": - self.load_extension(f"drawbot.cogs.{filename[:-3]}") - def run(self): try: super().run(self._token) From 0bbd6b86a497a6789e643334a49482cf4d474b50 Mon Sep 17 00:00:00 2001 From: sigmanificient Date: Fri, 9 Sep 2022 11:55:14 +0200 Subject: [PATCH 4/9] :bug: Fixed sub packages imports & paths --- drawbot/bot.py | 143 +++++++++++---------- drawbot/cogs/__init__.py | 0 drawbot/cogs/pronote_commands.py | 176 ++++++++++++------------- drawbot/cogs/pronote_loop.py | 212 +++++++++++++++---------------- drawbot/utils/__init__.py | 3 +- drawbot/utils/pronote.py | 156 +++++++++++------------ 6 files changed, 348 insertions(+), 342 deletions(-) create mode 100644 drawbot/cogs/__init__.py diff --git a/drawbot/bot.py b/drawbot/bot.py index b62297e..9620115 100644 --- a/drawbot/bot.py +++ b/drawbot/bot.py @@ -1,69 +1,74 @@ -import os -import sys -from typing import Optional - -from discord import LoginFailure, Intents -from discord.ext import commands -from colorama import Fore, Style - -from .utils import json_wr, JsonData - - -class Bot(commands.Bot): - def __init__(self): - """Initialize the bot and load config for token and prefix.""" - self.embed_color: int = 0x1E744F - self._token: Optional[str] = None - - default_config: JsonData = { - "token": "", - "prefix": "!", - "channelID": "", - "username": "", - "password": "", - "url": "", - } - - self.config: JsonData = json_wr("config") - - for key in default_config.keys(): - if self.config.get(key, "") == "": - print( - f'Veuillez indiquer remplir la valeur "{key}" ' - "dans le fichier vars/config.json" - ) - sys.exit() - - super().__init__(command_prefix=";", intents=Intents.default()) - self._token = self.config.get("token") - self.config.pop("token") - - self.remove_command("help") - - for filename in os.listdir("drawbot/cogs"): - if filename.endswith(".py") and filename != "__init__.py": - self.load_extension(f"drawbot.cogs.{filename[:-3]}") - - def run(self): - try: - super().run(self._token) - except LoginFailure: - print( - "Echec de la connexion au client." - "Veuillez vérifier que votre token est correct." - ) - - async def on_ready(self): - await self.load_cogs() - print(f"Connecté en temps que {self.user.name} !") - - async def load_cogs(self): - for command in self.tree.get_commands(): - await self.unload_extension(command.name) - - for filename in os.listdir("drawbot/cogs"): - if filename.endswith(".py"): - await self.load_extension(f"cogs.{filename[:-3]}") - print(f" -> Loaded extension " - f"{Fore.BLUE}{Style.BRIGHT}{filename}{Style.RESET_ALL}") - await self.tree.sync() +import os +import sys +from typing import Optional + +from discord import LoginFailure, Intents +from discord.ext import commands +from colorama import Fore, Style + +from .utils import json_wr, JsonData + + +class Bot(commands.Bot): + def __init__(self): + """Initialize the bot and load config for token and prefix.""" + self.embed_color: int = 0x1E744F + self._token: Optional[str] = None + + default_config: JsonData = { + "token": "", + "prefix": "!", + "channelID": "", + "username": "", + "password": "", + "url": "", + } + + self.config: JsonData = json_wr("config") + + for key in default_config.keys(): + if self.config.get(key, "") == "": + print( + f'Veuillez indiquer remplir la valeur "{key}" ' + "dans le fichier vars/config.json" + ) + sys.exit() + + super().__init__(command_prefix=";", intents=Intents.default()) + self._token = self.config.get("token") + self.config.pop("token") + + self.remove_command("help") + + for filename in os.listdir("drawbot/cogs"): + if filename.endswith(".py") and filename != "__init__.py": + self.load_extension(f"drawbot.cogs.{filename[:-3]}") + + def run(self): + try: + super().run(self._token) + except LoginFailure: + print( + "Echec de la connexion au client." + "Veuillez vérifier que votre token est correct." + ) + + async def on_ready(self): + await self.load_cogs() + print(f"Connecté en temps que {self.user.name} !") + + async def load_cogs(self): + for command in self.tree.get_commands(): + await self.unload_extension(command.name) + + for filename in os.listdir("drawbot/cogs"): + if filename.startswith('_') or not filename.endswith('.py'): + continue + + await self.load_extension(f"drawbot.cogs.{filename[:-3]}") + print( + f" -> Loaded extension " + f"{Fore.BLUE}{Style.BRIGHT}{filename}{Style.RESET_ALL}" + ) + + await self.tree.sync() diff --git a/drawbot/cogs/__init__.py b/drawbot/cogs/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/drawbot/cogs/pronote_commands.py b/drawbot/cogs/pronote_commands.py index 1b8e239..7d50d15 100644 --- a/drawbot/cogs/pronote_commands.py +++ b/drawbot/cogs/pronote_commands.py @@ -1,88 +1,88 @@ -import time - -from utils import json_wr, JsonDict - -import discord -from discord.ext import commands -from discord import app_commands, Interaction - - -@app_commands.guild_only() -class PronoteCommandsGroup(app_commands.Group, name="pronote"): - @app_commands.command(name="help") - async def help_command(self, interaction: Interaction): - await interaction.response.send_message( - embed=discord.Embed( - title="Help of the Pronote", - description=( - "Un bot qui traque vos devoir pronote " - "et vous les notifient sur discord." - ), - color=interaction.client.embed_color, - ).add_field( - name="/pronote help", - value="Affiche ce message", - ).add_field( - name="/pronote here", - value=("Change le salon d'envoi des nouveaux messages " - "pour pronote (nouveaux devoirs et notes)"), - ).add_field( - name="/pronote incoming", - value="Affiche les prochains devoirs", - ) - ) - - @app_commands.command() - async def here(self, interaction: Interaction): - pronote_config: JsonDict = json_wr("pronote") - pronote_config["channelID"] = interaction.channel_id - json_wr("pronote", data=pronote_config) - - await interaction.response.send_message( - embed=discord.Embed( - title="Changement de salon", - description=( - "Le salon pour envoyer les nouveaux devoirs " - "à bien été mis à jour" - ), - color=interaction.client.embed_color, - ) - ) - - @app_commands.command(description="Donne la liste des prochains devoirs") - async def incoming(self, interaction: Interaction): - homeworks: JsonDict = json_wr("devoirs") - - embed = discord.Embed( - title="Prochains devoirs", - color=interaction.client.embed_color - ) - - today = time.time() - homeworks_dict = {} - for date, homeworks_list in homeworks.items(): - - date_timestamp = int(time.mktime(time.strptime(date, "%Y-%m-%d"))) - if date_timestamp >= today: - homeworks_dict[date_timestamp] = homeworks_list - - homeworks_dict = { - key: homeworks_dict[key] - for key in sorted(homeworks_dict) - } - - for date, homeworks_list in homeworks_dict.items(): - embed.add_field( - name=f"Pour le ", - value="\n".join( - f"**- {h['subject']} :** {h['description']}" - for h in homeworks_list - ), - inline=False, - ) - - await interaction.response.send_message(embed=embed) - - -async def setup(client: commands.Bot) -> None: - client.tree.add_command(PronoteCommandsGroup()) +import time + +import discord +from discord import app_commands, Interaction +from discord.ext import commands + +from ..utils import json_wr, JsonDict + + +@app_commands.guild_only() +class PronoteCommandsGroup(app_commands.Group, name="pronote"): + @app_commands.command(name="help") + async def help_command(self, interaction: Interaction): + await interaction.response.send_message( + embed=discord.Embed( + title="Help of the Pronote", + description=( + "Un bot qui traque vos devoir pronote " + "et vous les notifient sur discord." + ), + color=interaction.client.embed_color, + ).add_field( + name="/pronote help", + value="Affiche ce message", + ).add_field( + name="/pronote here", + value=("Change le salon d'envoi des nouveaux messages " + "pour pronote (nouveaux devoirs et notes)"), + ).add_field( + name="/pronote incoming", + value="Affiche les prochains devoirs", + ) + ) + + @app_commands.command() + async def here(self, interaction: Interaction): + pronote_config: JsonDict = json_wr("pronote") + pronote_config["channelID"] = interaction.channel_id + json_wr("pronote", data=pronote_config) + + await interaction.response.send_message( + embed=discord.Embed( + title="Changement de salon", + description=( + "Le salon pour envoyer les nouveaux devoirs " + "à bien été mis à jour" + ), + color=interaction.client.embed_color, + ) + ) + + @app_commands.command(description="Donne la liste des prochains devoirs") + async def incoming(self, interaction: Interaction): + homeworks: JsonDict = json_wr("devoirs") + + embed = discord.Embed( + title="Prochains devoirs", + color=interaction.client.embed_color + ) + + today = time.time() + homeworks_dict = {} + for date, homeworks_list in homeworks.items(): + + date_timestamp = int(time.mktime(time.strptime(date, "%Y-%m-%d"))) + if date_timestamp >= today: + homeworks_dict[date_timestamp] = homeworks_list + + homeworks_dict = { + key: homeworks_dict[key] + for key in sorted(homeworks_dict) + } + + for date, homeworks_list in homeworks_dict.items(): + embed.add_field( + name=f"Pour le ", + value="\n".join( + f"**- {h['subject']} :** {h['description']}" + for h in homeworks_list + ), + inline=False, + ) + + await interaction.response.send_message(embed=embed) + + +async def setup(client: commands.Bot) -> None: + client.tree.add_command(PronoteCommandsGroup()) diff --git a/drawbot/cogs/pronote_loop.py b/drawbot/cogs/pronote_loop.py index 7f4447e..54c09d5 100644 --- a/drawbot/cogs/pronote_loop.py +++ b/drawbot/cogs/pronote_loop.py @@ -1,106 +1,106 @@ -import time - -from utils import fetch_homeworks, fetch_grades, chunks - -import pronotepy -import discord -from discord.ext import commands, tasks - - -class LoopHandler(commands.Cog): - def __init__(self, client: commands.Bot): - self.client = client - self.refresh_pronote.start() - - def cog_unload(self): - self.refresh_pronote.cancel() - - @tasks.loop(minutes=5) - async def refresh_pronote(self): - await self.client.wait_until_ready() - date = time.strftime("%Y-%m-%d %H:%M", time.gmtime()) - - try: - pronote: pronotepy.Client = pronotepy.Client( - self.client.config["url"], - self.client.config["username"], - self.client.config["password"], - ) - - except pronotepy.CryptoError: - print( - "Connexion à Pronote échoué. " - "Mauvais nom d'utilisateur ou mot de passe." - ) - await self.client.close() - return - - except pronotepy.PronoteAPIError: - print(f"{date} - Connexion à Pronote échoué") - return - - if not pronote.logged_in: - print(f"{date} - Connexion à Pronote échoué") - return - - try: - pronote_channel: discord.TextChannel = await self.client.fetch_channel( - int(self.client.config.get("channelID")) - ) - except discord.errors.NotFound: - print("Channel non-trouvé ou inexistant") - await self.client.close() - return - - def discord_timestamp(t_str: str) -> str: - return f"" - - new_homework_count = 0 - for homeworks in chunks(list(fetch_homeworks(pronote)), 10): - new_homework_count += len(homeworks) - await pronote_channel.send( - embeds=[ - discord.Embed( - title=( - f"Nouveau devoir de {homework['subject']}\n" - f"Pour le {discord_timestamp(homework['date'])}" - ), - description=homework["description"], - color=0x1E744F, - ) - for homework in homeworks - ] - ) - - new_grades_count = 0 - for grades in chunks(list(fetch_grades(pronote)), 10): - new_grades_count += len(grades) - await pronote_channel.send( - embeds=[ - discord.Embed( - title=( - f"Nouvelle note de {grade['subject']}\n" - f"Du {discord_timestamp(grade['date'])}" - ), - description=( - f"Note élève : **{grade['grade']}**\n" - f"Moy. classe : **{grade['average']}**\n" - f"Coefficient : **{grade['coefficient']}**\n" - f"Note + : **{grade['max']}**\n" - f"Note - : **{grade['min']}**\n" - ), - color=0x1E744F, - ) - for grade in grades - ] - ) - - print( - f"{date} " - f"- {new_homework_count} nouveaux devoirs " - f"- {new_grades_count} nouvelles notes !" - ) - - -async def setup(client: commands.Bot) -> None: - LoopHandler(client) +import time + +import discord +import pronotepy +from discord.ext import commands, tasks + +from ..utils import fetch_homeworks, fetch_grades, chunks + + +class LoopHandler(commands.Cog): + def __init__(self, client: commands.Bot): + self.client = client + self.refresh_pronote.start() + + def cog_unload(self): + self.refresh_pronote.cancel() + + @tasks.loop(minutes=5) + async def refresh_pronote(self): + await self.client.wait_until_ready() + date = time.strftime("%Y-%m-%d %H:%M", time.gmtime()) + + try: + pronote: pronotepy.Client = pronotepy.Client( + self.client.config["url"], + self.client.config["username"], + self.client.config["password"], + ) + + except pronotepy.CryptoError: + print( + "Connexion à Pronote échoué. " + "Mauvais nom d'utilisateur ou mot de passe." + ) + await self.client.close() + return + + except pronotepy.PronoteAPIError: + print(f"{date} - Connexion à Pronote échoué") + return + + if not pronote.logged_in: + print(f"{date} - Connexion à Pronote échoué") + return + + try: + pronote_channel: discord.TextChannel = await self.client.fetch_channel( + int(self.client.config.get("channelID")) + ) + except discord.errors.NotFound: + print("Channel non-trouvé ou inexistant") + await self.client.close() + return + + def discord_timestamp(t_str: str) -> str: + return f"" + + new_homework_count = 0 + for homeworks in chunks(list(fetch_homeworks(pronote)), 10): + new_homework_count += len(homeworks) + await pronote_channel.send( + embeds=[ + discord.Embed( + title=( + f"Nouveau devoir de {homework['subject']}\n" + f"Pour le {discord_timestamp(homework['date'])}" + ), + description=homework["description"], + color=0x1E744F, + ) + for homework in homeworks + ] + ) + + new_grades_count = 0 + for grades in chunks(list(fetch_grades(pronote)), 10): + new_grades_count += len(grades) + await pronote_channel.send( + embeds=[ + discord.Embed( + title=( + f"Nouvelle note de {grade['subject']}\n" + f"Du {discord_timestamp(grade['date'])}" + ), + description=( + f"Note élève : **{grade['grade']}**\n" + f"Moy. classe : **{grade['average']}**\n" + f"Coefficient : **{grade['coefficient']}**\n" + f"Note + : **{grade['max']}**\n" + f"Note - : **{grade['min']}**\n" + ), + color=0x1E744F, + ) + for grade in grades + ] + ) + + print( + f"{date} " + f"- {new_homework_count} nouveaux devoirs " + f"- {new_grades_count} nouvelles notes !" + ) + + +async def setup(client: commands.Bot) -> None: + LoopHandler(client) diff --git a/drawbot/utils/__init__.py b/drawbot/utils/__init__.py index 07f9aaf..2b737c6 100644 --- a/drawbot/utils/__init__.py +++ b/drawbot/utils/__init__.py @@ -1,6 +1,6 @@ """Utilities for drawbot.""" from .json_files import json_wr, JsonData, JsonDict, JsonList -from .pronote import fetch_homeworks, fetch_grades +from .pronote import fetch_homeworks, fetch_grades, chunks __all__ = ( "json_wr", @@ -9,4 +9,5 @@ "JsonData", "JsonDict", "JsonList", + "chunks" ) diff --git a/drawbot/utils/pronote.py b/drawbot/utils/pronote.py index 293d1fa..01a685f 100644 --- a/drawbot/utils/pronote.py +++ b/drawbot/utils/pronote.py @@ -1,78 +1,78 @@ -from typing import DefaultDict, Generator, Optional -from collections import defaultdict - -from .json_files import JsonData -from utils import json_wr -import pronotepy - - -def fetch_homeworks(pronote_client: pronotepy.Client) -> Optional[Generator]: - fetched_homeworks = pronote_client.homework(pronote_client.start_day) - - homeworks: DefaultDict[str, list] = defaultdict(list) - for homework in fetched_homeworks: - homeworks[str(homework.date)].append( - { - "subject": homework.subject.name, - "description": homework.description.replace("\n", " "), - } - ) - - yield from fetch_from_json("devoirs", homeworks) - - -def fetch_grades(pronote_client: pronotepy.Client) -> Optional[Generator]: - fetched_grades = pronote_client.periods[0].grades - - grades: DefaultDict[str, list] = defaultdict(list) - for g in fetched_grades: - grades[str(g.date)].append( - { - "subject": g.subject.name, - "comment": g.comment, - "grade": f"{g.grade}/{g.out_of}", - "average": f"{g.average}/{g.out_of}", - "coefficient": f"{g.coefficient}", - "max": f"{g.max}/{g.out_of}", - "min": f"{g.min}/{g.out_of}", - } - ) - - yield from fetch_from_json("grades", grades) - - -def fetch_from_json(filename: str, json_data: JsonData) -> Generator: - json_file = json_wr(filename) - - if json_data == json_file: - return - - json_wr(filename, "w", json_data) - - if json_file == {}: - print("Première exécution, le générateur ne va rien renvoyer.") - return - - json_vals: list = [] - for key, value in json_data.items(): - for i in value: - i["date"] = key - json_vals.extend(value) - - old_vals: list = [] - for key, value in json_file.items(): - for i in value: - i["date"] = key - old_vals.extend(value) - - for value in json_vals: - if value in old_vals: - continue - - yield value - - -def chunks(lst, n): - """Yield successive n-sized chunks from lst.""" - for i in range(0, len(lst), n): - yield lst[i:i + n] +from collections import defaultdict +from typing import DefaultDict, Generator, Optional + +import pronotepy + +from .json_files import JsonData, json_wr + + +def fetch_homeworks(pronote_client: pronotepy.Client) -> Optional[Generator]: + fetched_homeworks = pronote_client.homework(pronote_client.start_day) + + homeworks: DefaultDict[str, list] = defaultdict(list) + for homework in fetched_homeworks: + homeworks[str(homework.date)].append( + { + "subject": homework.subject.name, + "description": homework.description.replace("\n", " "), + } + ) + + yield from fetch_from_json("devoirs", homeworks) + + +def fetch_grades(pronote_client: pronotepy.Client) -> Optional[Generator]: + fetched_grades = pronote_client.periods[0].grades + + grades: DefaultDict[str, list] = defaultdict(list) + for g in fetched_grades: + grades[str(g.date)].append( + { + "subject": g.subject.name, + "comment": g.comment, + "grade": f"{g.grade}/{g.out_of}", + "average": f"{g.average}/{g.out_of}", + "coefficient": f"{g.coefficient}", + "max": f"{g.max}/{g.out_of}", + "min": f"{g.min}/{g.out_of}", + } + ) + + yield from fetch_from_json("grades", grades) + + +def fetch_from_json(filename: str, json_data: JsonData) -> Generator: + json_file = json_wr(filename) + + if json_data == json_file: + return + + json_wr(filename, "w", json_data) + + if json_file == {}: + print("Première exécution, le générateur ne va rien renvoyer.") + return + + json_vals: list = [] + for key, value in json_data.items(): + for i in value: + i["date"] = key + json_vals.extend(value) + + old_vals: list = [] + for key, value in json_file.items(): + for i in value: + i["date"] = key + old_vals.extend(value) + + for value in json_vals: + if value in old_vals: + continue + + yield value + + +def chunks(lst, n): + """Yield successive n-sized chunks from lst.""" + for i in range(0, len(lst), n): + yield lst[i:i + n] From 42f6d8fb20621f856997ae815ebb06bd2367bf4e Mon Sep 17 00:00:00 2001 From: sigmanificient Date: Fri, 9 Sep 2022 11:55:35 +0200 Subject: [PATCH 5/9] :wrench: Added .attributes for lf --- .gitattributes | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..c6d0b1e --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +# Set the default behavior, in case people don't have core.autocrlf set. +* text=lf +* eol=lf From 18438d00023b16264ea61a35f63f5199053e0ad1 Mon Sep 17 00:00:00 2001 From: sigmanificient Date: Fri, 9 Sep 2022 11:58:01 +0200 Subject: [PATCH 6/9] :bug: Cogs were loaded twice? --- drawbot/bot.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/drawbot/bot.py b/drawbot/bot.py index 9620115..e036499 100644 --- a/drawbot/bot.py +++ b/drawbot/bot.py @@ -40,13 +40,9 @@ def __init__(self): self.remove_command("help") - for filename in os.listdir("drawbot/cogs"): - if filename.endswith(".py") and filename != "__init__.py": - self.load_extension(f"drawbot.cogs.{filename[:-3]}") - - def run(self): + def run(self, **kwargs): try: - super().run(self._token) + super().run(self._token, **kwargs) except LoginFailure: print( "Echec de la connexion au client." From 4c32b14893bfe74c7c7c7fcb764cfa1118298312 Mon Sep 17 00:00:00 2001 From: sigmanificient Date: Fri, 9 Sep 2022 12:03:31 +0200 Subject: [PATCH 7/9] :hammer: Improved the makefile a bit --- Makefile | 58 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 8495b2c..c32d550 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,34 @@ -VENV = venv -VBIN = $(VENV)/bin - -all: start - -clean: - rm -rf venv - rm -rf *.egg-info - rm -rf */__pycache__ - rm vars/*.json - -$(VBIN)/python: - python3 -m venv venv - chmod +x $(VBIN)/activate - ./$(VBIN)/activate - ${VBIN}/pip install -e . - -vars/config.json: - cp vars/config.json.example vars/config.json - -start: $(VBIN)/python vars/config.json - python3 drawbot - -.PHONY: all clean start +VENV = venv +V_BIN = $(VENV)/bin + +all: start + + +$(V_BIN)/python: + python3 -m venv venv + chmod +x $(V_BIN)/activate + ./$(V_BIN)/activate + + $(V_BIN)/pip install -e . + + +vars/config.json: + cp vars/config.json.example vars/config.json + + +start: $(V_BIN)/python vars/config.json + python3 drawbot + + +clean: + rm -rf venv + rm -rf *.egg-info + rm -rf */__pycache__ + + +fclean: clean + rm -rf venv + rm vars/*.json + + +.PHONY: all clean fclean start From 556a1733368f7755094442fd8d73261f3db228ee Mon Sep 17 00:00:00 2001 From: sigmanificient Date: Fri, 9 Sep 2022 12:03:31 +0200 Subject: [PATCH 8/9] :hammer: Improved the makefile a bit --- Makefile | 58 +++++++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 8495b2c..c32d550 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,34 @@ -VENV = venv -VBIN = $(VENV)/bin - -all: start - -clean: - rm -rf venv - rm -rf *.egg-info - rm -rf */__pycache__ - rm vars/*.json - -$(VBIN)/python: - python3 -m venv venv - chmod +x $(VBIN)/activate - ./$(VBIN)/activate - ${VBIN}/pip install -e . - -vars/config.json: - cp vars/config.json.example vars/config.json - -start: $(VBIN)/python vars/config.json - python3 drawbot - -.PHONY: all clean start +VENV = venv +V_BIN = $(VENV)/bin + +all: start + + +$(V_BIN)/python: + python3 -m venv venv + chmod +x $(V_BIN)/activate + ./$(V_BIN)/activate + + $(V_BIN)/pip install -e . + + +vars/config.json: + cp vars/config.json.example vars/config.json + + +start: $(V_BIN)/python vars/config.json + python3 drawbot + + +clean: + rm -rf venv + rm -rf *.egg-info + rm -rf */__pycache__ + + +fclean: clean + rm -rf venv + rm vars/*.json + + +.PHONY: all clean fclean start From 16bb301529cb1adaaa04566e9ec2202752a6d9e9 Mon Sep 17 00:00:00 2001 From: drawbu <69208565+drawbu@users.noreply.github.com> Date: Fri, 9 Sep 2022 11:32:35 +0200 Subject: [PATCH 9/9] :recycle: Removed error due to old code not awaited. --- drawbot/bot.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/drawbot/bot.py b/drawbot/bot.py index e036499..2bc7fc7 100644 --- a/drawbot/bot.py +++ b/drawbot/bot.py @@ -40,9 +40,9 @@ def __init__(self): self.remove_command("help") - def run(self, **kwargs): + def run(self): try: - super().run(self._token, **kwargs) + super().run(self._token) except LoginFailure: print( "Echec de la connexion au client." @@ -58,13 +58,8 @@ async def load_cogs(self): await self.unload_extension(command.name) for filename in os.listdir("drawbot/cogs"): - if filename.startswith('_') or not filename.endswith('.py'): - continue - - await self.load_extension(f"drawbot.cogs.{filename[:-3]}") - print( - f" -> Loaded extension " - f"{Fore.BLUE}{Style.BRIGHT}{filename}{Style.RESET_ALL}" - ) - + if filename.endswith(".py"): + await self.load_extension(f"cogs.{filename[:-3]}") + print(f" -> Loaded extension " + f"{Fore.BLUE}{Style.BRIGHT}{filename}{Style.RESET_ALL}") await self.tree.sync()