diff options
Diffstat (limited to 'bot/seasons/halloween/monstersurvey.py')
| -rw-r--r-- | bot/seasons/halloween/monstersurvey.py | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/bot/seasons/halloween/monstersurvey.py b/bot/seasons/halloween/monstersurvey.py index 08873f24..2ae98f6e 100644 --- a/bot/seasons/halloween/monstersurvey.py +++ b/bot/seasons/halloween/monstersurvey.py @@ -4,7 +4,7 @@ import os from discord import Embed from discord.ext import commands -from discord.ext.commands import Bot, Context +from discord.ext.commands import Bot, Cog, Context log = logging.getLogger(__name__) @@ -14,10 +14,12 @@ EMOJIS = { } -class MonsterSurvey: +class MonsterSurvey(Cog): """ - Vote for your favorite monster! - This command allows users to vote for their favorite listed monster. + Vote for your favorite monster. + + This Cog allows users to vote for their favorite listed monster. + Users may change their vote, but only their current vote will be counted. """ @@ -30,12 +32,18 @@ class MonsterSurvey: self.voter_registry = json.load(jason) def json_write(self): + """Write voting results to a local JSON file.""" + log.info("Saved Monster Survey Results") with open(self.registry_location, 'w') as jason: json.dump(self.voter_registry, jason, indent=2) def cast_vote(self, id: int, monster: str): """ + Cast a user's vote for the specified monster. + + If the user has already voted, their existing vote is removed. + :param id: The id of the person voting :param monster: the string key of the json that represents a monster :return: None @@ -50,6 +58,8 @@ class MonsterSurvey: vr[m]['votes'].remove(id) def get_name_by_leaderboard_index(self, n): + """Return the monster at the specified leaderboard index.""" + n = n - 1 vr = self.voter_registry top = sorted(vr, key=lambda k: len(vr[k]['votes']), reverse=True) @@ -61,9 +71,7 @@ class MonsterSurvey: aliases=('ms',) ) async def monster_group(self, ctx: Context): - """ - The base voting command. If nothing is called, then it will return an embed. - """ + """The base voting command. If nothing is called, then it will return an embed.""" if ctx.invoked_subcommand is None: async with ctx.typing(): @@ -95,8 +103,9 @@ class MonsterSurvey: ) async def monster_vote(self, ctx: Context, name=None): """ - Casts a vote for a particular monster, or displays a list of monsters that can be voted for - if one is not given. + Cast a vote for a particular monster. + + Displays a list of monsters that can be voted for if one is not specified. """ if name is None: @@ -185,6 +194,7 @@ class MonsterSurvey: async def monster_leaderboard(self, ctx: Context): """ Shows the current standings. + :param ctx: :return: """ @@ -214,5 +224,7 @@ class MonsterSurvey: def setup(bot): + """Monster survey Cog load.""" + bot.add_cog(MonsterSurvey(bot)) - log.debug("MonsterSurvey cog loaded") + log.info("MonsterSurvey cog loaded") |