diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..c88c265 --- /dev/null +++ b/Pipfile @@ -0,0 +1,13 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +"fs.dropboxfs" = {git = "https://github.com/rkhwaja/fs.dropboxfs.git"} +"discord.py" = {ref = "rewrite", git = "https://github.com/Rapptz/discord.py"} + +[dev-packages] + +[requires] +python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 0000000..0366270 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,29 @@ +{ + "_meta": { + "hash": { + "sha256": "0b00547c8080ca98592603203321ca0aa4c3be1d1d1d0d69ac0fb28b78619350" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.7" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "discord.py": { + "git": "https://github.com/Rapptz/discord.py", + "ref": "00a659c6526b2445162b52eaf970adbd22c6d35d" + }, + "fs.dropboxfs": { + "git": "https://github.com/rkhwaja/fs.dropboxfs.git", + "ref": "68988a25143a8ea760bc6dfb2a715f6f98ac31c7" + } + }, + "develop": {} +} diff --git a/main.py b/main.py index c9bdc57..5f56ca4 100644 --- a/main.py +++ b/main.py @@ -7,16 +7,15 @@ import os import sys import discord -from fs.ftpfs import FTPFS +from fs.dropboxfs import DropboxFS 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.get("FTP_PASS", False): +if os.environ.get("DROPBOX_ACCESS_TOKEN", False): print("FTP") - fileSystem = FTPFS(os.environ["FTP_ADDRESS"], user=os.environ["FTP_USER"], passwd=os.environ["FTP_PASS"], - timeout=600) + fileSystem = DropboxFS(os.environ["DROPBOX_ACCESS_TOKEN"]) else: print("OS") fileSystem = OSFS(os.getcwd()) @@ -82,6 +81,7 @@ class Guild: self.modules = [] self.load_config() self.update_modules() + self.save_config() def load_config(self): if self.bot.fileSystem.exists(self.config_file): @@ -110,6 +110,9 @@ class Guild: self.config["modules"].append("help") module_to_load = list(set(self.config["modules"])) + self.config["modules"] = module_to_load + self.save_config() + for module in module_to_load: # Try to load all modules by name if module not in self.bot.modules.keys(): @@ -139,7 +142,7 @@ class Guild: class FoBot(discord.Client): - def __init__(self, config='foBot_config', *args, **kwargs): + def __init__(self, config='/foBot_config', *args, **kwargs): super().__init__(*args, **kwargs) self.config_folder = config self.config = {"guilds": {}} @@ -209,16 +212,16 @@ class FoBot(discord.Client): async def on_resumed(self): info("foBot is resumed.") + async def on_guild_join(self, guild): + self.load_modules() + self.load_config() + self.save_config() + async def on_error(self, event, *args, **kwargs): error("foBot encounter an error.", exc_info=True) - if os.environ.get("FTP_ADDRESS", False) and \ - os.environ.get("FTP_USER", False) and \ - os.environ.get("FTP_PASS", False): + if os.environ.get("DROPBOX_ACCESS_TOKEN", False): print("FTP") - self.fileSystem = FTPFS(os.environ["FTP_ADDRESS"], - user=os.environ["FTP_USER"], - passwd=os.environ["FTP_PASS"], - timeout=600) + self.fileSystem = DropboxFS(os.environ["DROPBOX_ACCESS_TOKEN"]) else: print("OS") self.fileSystem = OSFS(os.getcwd()) diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 8923509..0000000 --- a/requirements.txt +++ /dev/null @@ -1,13 +0,0 @@ -aiohttp==3.3.2 -async-timeout==3.0.0 -attrs==18.1.0 -cffi==1.11.5 -chardet==3.0.4 -git+https://github.com/Rapptz/discord.py@rewrite#egg=discord.py -idna==2.7 -multidict==4.3.1 -pycparser==2.18 -six==1.11.0 -websockets==6.0 -yarl==1.2.6 -fs \ No newline at end of file