aboutsummaryrefslogtreecommitdiffstats
path: root/bot/__main__.py
diff options
context:
space:
mode:
authorGravatar Leon Sandøy <[email protected]>2018-11-27 21:01:18 +0100
committerGravatar Gareth Coles <[email protected]>2018-11-27 21:01:18 +0100
commit70d2170a0a6594561d59c7d080c4280f1ebcd70b (patch)
tree3eb52bc45b91f3de1cc51a0cb2e710685009dd4d /bot/__main__.py
parentMerge pull request #69 from python-discord/issue/68-with-typing (diff)
Allows you to create Seasons. (#64)
* Allows you to create Season objects which change the bots behavior. For example, a season can determine things like the avatar, the nickname, and which cogs are loaded. Season automatically changes according to the date range you specify when you create it. * removing some hungarian notation. * Automatic season changes will now always happen at a minute past midnight, no matter when the bot started. * catching dunders in the glob. * Refine Season Creation behaviour and structure. * Added channel and role constants, refactored roles into NamedTuples, added role check decorators from the main bot, and added role checks for the season change feature. Yes this is duplicate code from our main bot, but it will just have to be like that for now until we get a bot core running. * replacing the or with an xor and switching out the assert for a UserWarning * New lockfile * changing discord.py to discord-py to prevent pip bug from putting two of them in our lockfile * fixing flake errors * flake8 * Cleaned everything up, but I seem to have introduced some sort of infinite load loop? o.O * Fixing up all bugs in the halloween cogs. This should be ready for merge now. * Add avatar_path baseclass method for consistency. While making it simpler to add avatar urls in new season extensions, it also allows the avatar resource path to be changed in a single place if needed in future. * Avoid shadowing builtin `object`. * Add debug mode, refine bot user editing on season load. The changing of a bot's username and avatar is heavily ratelimited. While testing, restarting the bot and changing seasons is required, and hitting these limits are typical. Instead, when in debug mode, the avatar isn't set and only the nickname is changed to prevent unnecessary account edit requests. In the case that the rate limit is hit when not in debug mode, there's an added fallback to use the nickname instead. * Add cancel load_seasons task on SeasonManager un/reload. Previously the load_seasons task was loaded and looping forever. Even if the cog was unloaded for some reason, it would still be running. On loading the SeasonManager again, it would create a new load_seasons task, while the old one still existed. Adding the cancellation allows the task to end when the cog is unloaded or reloaded, and will help assist with live code changes during development at a later time where it's possible to reload this extension (perhaps when the pending bot core is implemented). * get_season_class helper, season class attribs, fix admin id Changes `get_season`'s date check to not initialise unwanted classes (to avoid needless loading of tasks which would otherwise cause unexpected behaviour). To do this, defining attributes of season classes have been moved from `__init__` as an instance variable, to the class variable level. This also results in `__init__` not needing to be defined for the `SeasonBase` class, and `super().__init__()` not needing to be called in individual season classes, making things cleaner/simpler for them. Adds a helper function for retrieving a season class and combines two unnecessarily separate if statements. Credits to @MarkKoz for the suggestions. Reverts the admin ID mistakenly changed in a previous commit. * Update bot/seasons/halloween/hacktoberstats.py Co-Authored-By: heavysaturn <[email protected]> * Update bot/seasons/halloween/halloween_facts.py Co-Authored-By: heavysaturn <[email protected]> * No more property in halloweenfacts * Changed all aliases to tuples * Made tokens a seperate namedtuple * Update bot/seasons/halloween/spookyavatar.py Co-Authored-By: heavysaturn <[email protected]>
Diffstat (limited to 'bot/__main__.py')
-rw-r--r--bot/__main__.py33
1 files changed, 4 insertions, 29 deletions
diff --git a/bot/__main__.py b/bot/__main__.py
index b74e4f54..a3b68ec1 100644
--- a/bot/__main__.py
+++ b/bot/__main__.py
@@ -1,33 +1,8 @@
import logging
-from os import environ
-from pathlib import Path
-from traceback import format_exc
-from discord.ext import commands
+from bot.constants import Client, bot
-SEASONALBOT_TOKEN = environ.get('SEASONALBOT_TOKEN')
-log = logging.getLogger()
+log = logging.getLogger(__name__)
-if SEASONALBOT_TOKEN:
- token_dl = len(SEASONALBOT_TOKEN) // 8
- log.info(f'Bot token loaded: {SEASONALBOT_TOKEN[:token_dl]}...{SEASONALBOT_TOKEN[-token_dl:]}')
-else:
- log.error(f'Bot token not found: {SEASONALBOT_TOKEN}')
-
-ghost_unicode = "\N{GHOST}"
-bot = commands.Bot(command_prefix=commands.when_mentioned_or(".", f"{ghost_unicode} ", ghost_unicode))
-
-log.info('Start loading extensions from ./bot/cogs/halloween/')
-
-
-if __name__ == '__main__':
- # Scan for files in the /cogs/ directory and make a list of the file names.
- cogs = [file.stem for file in Path('bot', 'cogs', 'hacktober').glob('*.py') if not file.stem.startswith("__")]
- for extension in cogs:
- try:
- bot.load_extension(f'bot.cogs.hacktober.{extension}')
- log.info(f'Successfully loaded extension: {extension}')
- except Exception as e:
- log.error(f'Failed to load extension {extension}: {repr(e)} {format_exc()}')
-
-bot.run(SEASONALBOT_TOKEN)
+bot.load_extension("bot.seasons")
+bot.run(Client.token)