From 204241dcd52ed4ed6f3c53ccd1de797798b822a5 Mon Sep 17 00:00:00 2001 From: Fomys <29522056+Fomys@users.noreply.github.com> Date: Tue, 21 Aug 2018 02:08:06 +0200 Subject: [PATCH 1/9] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 35 +++++++++++++++++++++++ .github/ISSUE_TEMPLATE/custom.md | 7 +++++ .github/ISSUE_TEMPLATE/feature_request.md | 17 +++++++++++ 3 files changed, 59 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/custom.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..b735373 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,35 @@ +--- +name: Bug report +about: Create a report to help us improve + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Desktop (please complete the following information):** + - OS: [e.g. iOS] + - Browser [e.g. chrome, safari] + - Version [e.g. 22] + +**Smartphone (please complete the following information):** + - Device: [e.g. iPhone6] + - OS: [e.g. iOS8.1] + - Browser [e.g. stock browser, safari] + - Version [e.g. 22] + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md new file mode 100644 index 0000000..99bb9a0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/custom.md @@ -0,0 +1,7 @@ +--- +name: Custom issue template +about: Describe this issue template's purpose here. + +--- + + diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..066b2d9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,17 @@ +--- +name: Feature request +about: Suggest an idea for this project + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. From d204db45450961372411538af1e0fbb970980d44 Mon Sep 17 00:00:00 2001 From: louis chauvet Date: Tue, 21 Aug 2018 12:12:06 +0200 Subject: [PATCH 2/9] Add a basic help menu --- main.py | 3 +++ modules/help.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++ traductions.py | 39 +++++++++++++++++++++--------- 3 files changed, 94 insertions(+), 11 deletions(-) create mode 100644 modules/help.py diff --git a/main.py b/main.py index 3fe310a..58f458c 100644 --- a/main.py +++ b/main.py @@ -92,6 +92,8 @@ class Guild: errors = [] if "modules" not in self.config["modules"]: self.config["modules"].append("modules") + if "help" not in self.config["modules"]: + self.config["modules"].append("help") module_to_load = list(set(self.config["modules"])) for module in module_to_load: @@ -118,6 +120,7 @@ class Guild: if not msg.author.bot: for module in self.modules: await module.on_message(msg) + return class FoBot(discord.Client): diff --git a/modules/help.py b/modules/help.py new file mode 100644 index 0000000..1b5acfb --- /dev/null +++ b/modules/help.py @@ -0,0 +1,63 @@ +import discord +import traductions as tr + + +class MainClass: + name = "modules" + + def __init__(self, guild): + self.guild = guild + + async def help(self, msg, command, args): + if len(args) == 0: + texte = "Voici l'aide générale du bot:" + for module in self.guild.config["modules"]: + texte += "\n**" + texte += module + texte += "**: " + texte += tr.tr[self.guild.config["lang"]]["modules"][module]["description"] + texte += "\n\tCommandes: " + texte += ", ".join( + [commande for commande in tr.tr[self.guild.config["lang"]]["modules"][module]["help"].keys()]) + await msg.channel.send(texte) + return + elif len(args[0].split(":")) == 1: + if args[0] in tr.tr[self.guild.config["lang"]]["modules"].keys(): + texte = "Voici l'aide pour le module {module}:".format(module=args[0]) + for commande, aide in tr.tr[self.guild.config["lang"]]["modules"][args[0]]["help"].items(): + texte += "\n**" + texte += commande + texte += "**: " + texte += aide["description"] + await msg.channel.send(texte) + return + else: + # module non existant + await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["ModuleNotFoundError"]["text"] + .format(prefix=self.guild.config["prefix"], module=args[0])) + return + elif len(args[0].split(":")) == 2: + module, fonction = args[0].split(":") + if module in tr.tr[self.guild.config["lang"]]["modules"].keys(): + if fonction in tr.tr[self.guild.config["lang"]]["modules"][module]["help"].keys(): + texte = "Aide de la fonction {command}".format(command=fonction) + for exemple in tr.tr[self.guild.config["lang"]]["modules"][module]["help"][fonction]["examples"]: + texte += "\n" + texte += exemple[0].format(prefix=self.guild.config["prefix"]) + texte += ": " + texte += exemple[1] + await msg.channel.send(texte) + else: + await msg.channe.send(tr.tr[self.guild.config["lang"]]["errors"]["CommandNotFoundError"].format(command=fonction)) + else: + # module non existant + await msg.channel.send(tr.tr[self.guild.config["lang"]]["errors"]["ModuleNotFoundError"]["text"] + .format(prefix=self.guild.config["prefix"], module=module)) + return + + async def on_message(self, msg): + if msg.content.startswith(self.guild.config["prefix"]): + command, *args = msg.content.lstrip(self.guild.config["prefix"]).split(" ") + if command == "help": + await self.help(msg, command, args) + return diff --git a/traductions.py b/traductions.py index 822904d..f1ae12a 100644 --- a/traductions.py +++ b/traductions.py @@ -4,23 +4,23 @@ tr = { "modules": { "modules": { "description": "Permet de gérer les modules.", - "aide": { + "help": { "list_modules": { "description": "Liste tous les modules. Les modules en gras sont activés.", - "exemples": [ + "examples": [ ("`{prefix}list_modules`", "Liste tous les modules"), ], }, "load": { "description": "Permet de charger un ou des modules.", - "exemples": [ + "examples": [ ("`{prefix}load fun`", "Charge le module fun"), ("`{prefix}load fun admin`", "Charge les modules fun et admin"), ], }, "unload": { "description": "Permet de décharger un ou des modules.", - "exemples": [ + "examples": [ ("`{prefix}unload fun`", "Décharge le module fun"), ("`{prefix}unload fun admin`", "Décharge les modules fun et admin"), ], @@ -36,7 +36,7 @@ tr = { }, "config": { "description": "Configuration de foBot, doublez le préfixe pour y accéder.", - "aide": { + "help": { "lang": { "description": "Modifier la langue", "examples": [ @@ -56,10 +56,10 @@ tr = { ], }, "list": { - "title": "Liste des Paramètres disponibles", - "params": { - "prefix": "Le préfixe utilisé sur le serveur", - }, + "description": "Liste des paramètres disponibles", + "examples": [ + ("`{prefix}{prefix}list`", "Liste des paramètres modifiables") + ], }, }, "lang": "La langue {lang} est maintenant utilisée.", @@ -75,6 +75,19 @@ tr = { "add_master_admin": "L'utilisateur {user} est maintenant un administrateur du bot.", "del_master_admin": "L'utilisateur {user} n'est plus un administrateur du bot.", }, + "help": { + "description": "Active la commande d'aide", + "help": { + "help": { + "description": "Permat d'aficher de l'aide", + "examples": [ + ("`{prefix}help`", "Affiche l'aide générale"), + ("`{prefix}help config`", "Liste les commandes disponibles dans le module config"), + ("`{prefix}help config:lang`", "Affiche l'aide avancé de la commande lang u module config"), + ], + }, + }, + }, }, "errors": { "LangNotFoundError": "La langue {lang} est introuvable, tapez {prefix}list_lang pour voir les langues " @@ -83,7 +96,8 @@ tr = { "ModuleNotFoundOrDeactivatedError": { "title": "Erreur", "name": "Erreur lors de la désactivation du module {module}:", - "value": "Celui-ci n'existe pas ou n'es pas activé. Tapez {prefix}list_modules pour voir la liste des modules disponibles.", + "value": "Celui-ci n'existe pas ou n'es pas activé. Tapez {prefix}list_modules pour voir la liste des " + "modules disponibles.", }, "ModuleNotFoundError": { @@ -91,13 +105,16 @@ tr = { "name": "Erreur lors de l'activation du module {module}:", "value": "Celui-ci n'existe pas. Tapez {prefix}list_modules pour voir la liste des modules " "disponibles.", + "text": "Le module {module} n'existe pas, tapez {prefix}list_modules pour voir la liste des modules " + "disponibles.", }, "ForbiddenConfigError": "Ce paramètre ne peut pas être modifié directement.", "UnknownConfigError": "Le paramètre demandé n'existe pas. Utilisez {prefix}list pour lister les paramètres " "modifiables.", "NotEnoughParamError": "Il manque un ou plusieurs parametres à la commande.", "NoMentionsError": "Vous devez mentioner un utilisateur pour le rajouter à la liste des administrateurs " - "du bot." + "du bot.", + "CommandNotFoundError": "La commande {command} n'existe pas." }, }, } From dd8f7df72cfaeedea1c29e4fc98966b3bced7405 Mon Sep 17 00:00:00 2001 From: Fomys Date: Tue, 21 Aug 2018 15:19:43 +0200 Subject: [PATCH 3/9] update .gitignore --- .gitignore | 3 +++ app.json | 7 +++++++ runtime.txt | 1 + 3 files changed, 11 insertions(+) create mode 100644 app.json create mode 100644 runtime.txt diff --git a/.gitignore b/.gitignore index d395d94..fd4f379 100644 --- a/.gitignore +++ b/.gitignore @@ -105,3 +105,6 @@ venv.bak/ # Pycharm project settings .idea/ + +# FoBot config +foBot_config/* diff --git a/app.json b/app.json new file mode 100644 index 0000000..b2e2eba --- /dev/null +++ b/app.json @@ -0,0 +1,7 @@ +{ + "name": "foBot", + "description": "A simple bot for discord.", + "image": "heroku/python", + "repository": "https://github.com/Fomys/foBot", + "keywords": ["python", "discord", "rewrite"] +} diff --git a/runtime.txt b/runtime.txt new file mode 100644 index 0000000..b16fb5e --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +python-3.7.0 \ No newline at end of file From 88edce9d01e8fba3d0bc8adb04fcc3c58c10cc0e Mon Sep 17 00:00:00 2001 From: louis chauvet Date: Tue, 21 Aug 2018 15:53:13 +0200 Subject: [PATCH 4/9] Add procfile --- Procfile | 1 + 1 file changed, 1 insertion(+) create mode 100644 Procfile diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..b96cada --- /dev/null +++ b/Procfile @@ -0,0 +1 @@ +worker: python main.py \ No newline at end of file From 01985503282ba15162fe71728e2fa4179cf0be6b Mon Sep 17 00:00:00 2001 From: louis chauvet Date: Wed, 22 Aug 2018 15:58:49 +0200 Subject: [PATCH 5/9] Add a support for ftp file system --- main.py | 29 ++++++++++++++++++++--------- modules/help.py | 2 +- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 58f458c..d3b6c4d 100644 --- a/main.py +++ b/main.py @@ -6,7 +6,18 @@ import os import sys import discord +from fs.ftpfs import FTPFS +from fs.osfs import OSFS +from fs import path +fileSystem = None + +if os.environ.get("FTP_ADDRESS", False) and os.environ.get("FTP_USER", False) and os.environ("FTP_PASS", False): + print("FTP") + fileSystem = FTPFS(os.environ["FTP_ADDRESS"], user=os.environ["FTP_USER"], passwd=os.environ["FTP_PASS"]) +else: + print("OS") + fileSystem = OSFS(os.getcwd()) # json decoder for int keys class Decoder(json.JSONDecoder): @@ -70,10 +81,10 @@ class Guild: self.update_modules() def load_config(self): - if os.path.exists(self.config_file): + if fileSystem.exists(self.config_file): try: # Loading configuration file - with open(self.config_file) as conf: + with fileSystem.open(self.config_file) as conf: self.config.update(json.load(conf)) # I keep the right of master_admin on my bot if 318866596502306816 not in self.config["master_admins"]: @@ -111,7 +122,7 @@ class Guild: def save_config(self): try: - with open(self.config_file, 'w') as conf_file: + with fileSystem.open(self.config_file, 'w') as conf_file: json.dump(self.config, conf_file) except PermissionError: error("Cannot write to configuration file.") @@ -140,10 +151,10 @@ class FoBot(discord.Client): self.modules.update({module[:-3]: imported.MainClass}) def load_config(self): - if os.path.exists(os.path.join(self.config_folder, "conf.json")): + if fileSystem.exists(path.join(self.config_folder, "conf.json")): try: # Loading configuration file - with open(os.path.join(self.config_folder, "conf.json")) as conf: + with fileSystem.open(path.join(self.config_folder, "conf.json")) as conf: self.config.update(json.load(conf)) except PermissionError: critical("Cannot open config file.") @@ -157,16 +168,16 @@ class FoBot(discord.Client): for guild in self.guilds: if guild.id not in list(self.config["guilds"].keys()): self.config["guilds"].update( - {guild.id: os.path.join(self.config_folder, str(guild.id) + ".json")}) + {guild.id: path.join(self.config_folder, str(guild.id) + ".json")}) for guild_id, guild_config_file in self.config["guilds"].items(): self.guilds_class.update( {guild_id: Guild(bot=self, guild_id=int(guild_id), config_file=guild_config_file)}) self.save_config() - elif os.path.exists(self.config_folder): + elif fileSystem.exists(self.config_folder): self.save_config() else: try: - os.mkdir(self.config_folder) + fileSystem.makedir(self.config_folder) except PermissionError: critical("Cannot create config folder.") sys.exit() @@ -175,7 +186,7 @@ class FoBot(discord.Client): for guild in self.guilds_class.values(): guild.save_config() try: - with open(os.path.join(self.config_folder, "conf.json"), 'w') as conf_file: + with fileSystem.open(path.join(self.config_folder, "conf.json"), 'w') as conf_file: json.dump(self.config, conf_file, indent=4) except PermissionError: critical("Cannot write to configuration file.") diff --git a/modules/help.py b/modules/help.py index 1b5acfb..e886b30 100644 --- a/modules/help.py +++ b/modules/help.py @@ -3,7 +3,7 @@ import traductions as tr class MainClass: - name = "modules" + name = "help" def __init__(self, guild): self.guild = guild From fd84cf7f4487a5ae13b5d231d23c0b93cad72fe9 Mon Sep 17 00:00:00 2001 From: louis chauvet Date: Wed, 22 Aug 2018 16:02:09 +0200 Subject: [PATCH 6/9] Typo in fs initialisation --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index d3b6c4d..a6eef7b 100644 --- a/main.py +++ b/main.py @@ -12,7 +12,7 @@ from fs import path fileSystem = None -if os.environ.get("FTP_ADDRESS", False) and os.environ.get("FTP_USER", False) and os.environ("FTP_PASS", False): +if os.environ.get("FTP_ADDRESS", False) and os.environ.get("FTP_USER", False) and os.environ.get("FTP_PASS", False): print("FTP") fileSystem = FTPFS(os.environ["FTP_ADDRESS"], user=os.environ["FTP_USER"], passwd=os.environ["FTP_PASS"]) else: From 6166d50580bc94b993b732ba42e8303b3af4cb4b Mon Sep 17 00:00:00 2001 From: louis chauvet Date: Wed, 22 Aug 2018 16:34:34 +0200 Subject: [PATCH 7/9] Repair ftp timeout error --- main.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index a6eef7b..a2a849b 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import ftplib import importlib import json import logging @@ -14,11 +15,12 @@ fileSystem = None if os.environ.get("FTP_ADDRESS", False) and os.environ.get("FTP_USER", False) and os.environ.get("FTP_PASS", False): print("FTP") - fileSystem = FTPFS(os.environ["FTP_ADDRESS"], user=os.environ["FTP_USER"], passwd=os.environ["FTP_PASS"]) + fileSystem = FTPFS(os.environ["FTP_ADDRESS"], user=os.environ["FTP_USER"], passwd=os.environ["FTP_PASS"], timeout=600) else: print("OS") fileSystem = OSFS(os.getcwd()) + # json decoder for int keys class Decoder(json.JSONDecoder): def decode(self, s, **kwargs): @@ -206,8 +208,13 @@ class FoBot(discord.Client): info("foBot is resumed.") async def on_error(self, event, *args, **kwargs): + if sys.exc_type == ftplib.error_temp: + global fileSystem + fileSystem = FTPFS(os.environ["FTP_ADDRESS"], user=os.environ["FTP_USER"], passwd=os.environ["FTP_PASS"], + timeout=600) error("foBot encounter an error.", exc_info=True) + async def on_message(self, msg): await self.guilds_class[msg.guild.id].on_message(msg) From 6df2f9f8d9d20a331029ffdcc4d80952dd98bc0a Mon Sep 17 00:00:00 2001 From: louis chauvet Date: Wed, 22 Aug 2018 16:52:58 +0200 Subject: [PATCH 8/9] repair timeout error ftp --- main.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/main.py b/main.py index a2a849b..537822c 100644 --- a/main.py +++ b/main.py @@ -208,10 +208,6 @@ class FoBot(discord.Client): info("foBot is resumed.") async def on_error(self, event, *args, **kwargs): - if sys.exc_type == ftplib.error_temp: - global fileSystem - fileSystem = FTPFS(os.environ["FTP_ADDRESS"], user=os.environ["FTP_USER"], passwd=os.environ["FTP_PASS"], - timeout=600) error("foBot encounter an error.", exc_info=True) From 08715fb4570039e4845fd93137793cf174ac3921 Mon Sep 17 00:00:00 2001 From: louis chauvet Date: Thu, 23 Aug 2018 10:00:52 +0200 Subject: [PATCH 9/9] Add help for some config commands --- traductions.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/traductions.py b/traductions.py index f1ae12a..3a25d36 100644 --- a/traductions.py +++ b/traductions.py @@ -61,6 +61,24 @@ tr = { ("`{prefix}{prefix}list`", "Liste des paramètres modifiables") ], }, + "add_master_admin": { + "description": "Ajoute un administrateur du bot", + "examples": [ + ("`{prefix}{prefix}add_master_admin <@unemention>`", + "Ajoute <@unemention> aux administrateurs du bot"), + ("`{prefix}{prefix}add_master_admin <@unemention>, <@unemention2>`", + "Ajoute <@unemention> et <@unemention1> aux administrateurs du bot"), + ], + }, + "del_master_admin": { + "description": "Supprime un administrateur du bot", + "examples": [ + ("`{prefix}{prefix}del_master_admin <@unemention>`", + "Supprime <@unemention> des administrateurs du bot"), + ("`{prefix}{prefix}add_master_admin <@unemention>, <@unemention2>`", + "Supprime <@unemention> et <@unemention1> des administrateurs du bot"), + ], + }, }, "lang": "La langue {lang} est maintenant utilisée.", "list_lang": { @@ -106,7 +124,7 @@ tr = { "value": "Celui-ci n'existe pas. Tapez {prefix}list_modules pour voir la liste des modules " "disponibles.", "text": "Le module {module} n'existe pas, tapez {prefix}list_modules pour voir la liste des modules " - "disponibles.", + "disponibles.", }, "ForbiddenConfigError": "Ce paramètre ne peut pas être modifié directement.", "UnknownConfigError": "Le paramètre demandé n'existe pas. Utilisez {prefix}list pour lister les paramètres "