diff options
| author | 2019-03-30 10:37:59 -0400 | |
|---|---|---|
| committer | 2019-03-30 10:37:59 -0400 | |
| commit | 5fe5b7c688e19e533fe34d98b8c754bc67a58beb (patch) | |
| tree | 16c2946f97f85facf6b994b3c48099d369ee7f5a /bot/seasons/halloween/candy_collection.py | |
| parent | Merge pull request #163 from python-discord/easter_announce (diff) | |
| parent | Blank line required between summary line and description. (diff) | |
Merge pull request #146 from python-discord/flake8-docstring
Implement flake8-docstrings
Diffstat (limited to 'bot/seasons/halloween/candy_collection.py')
| -rw-r--r-- | bot/seasons/halloween/candy_collection.py | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/bot/seasons/halloween/candy_collection.py b/bot/seasons/halloween/candy_collection.py index 6932097c..2e010cbc 100644 --- a/bot/seasons/halloween/candy_collection.py +++ b/bot/seasons/halloween/candy_collection.py @@ -20,7 +20,9 @@ ADD_SKULL_REACTION_CHANCE = 50 # 2% ADD_SKULL_EXISTING_REACTION_CHANCE = 20 # 5% -class CandyCollection(commands.Cog): +class CandyCollection: + """Candy collection game Cog.""" + def __init__(self, bot): self.bot = bot with open(json_location) as candy: @@ -33,9 +35,7 @@ class CandyCollection(commands.Cog): @commands.Cog.listener() async def on_message(self, message): - """ - Randomly adds candy or skull to certain messages - """ + """Randomly adds candy or skull reaction to non-bot messages in the Event channel.""" # make sure its a human message if message.author.bot: @@ -57,9 +57,7 @@ class CandyCollection(commands.Cog): @commands.Cog.listener() async def on_reaction_add(self, reaction, user): - """ - Add/remove candies from a person if the reaction satisfies criteria - """ + """Add/remove candies from a person if the reaction satisfies criteria.""" message = reaction.message # check to ensure the reactor is human @@ -107,8 +105,10 @@ class CandyCollection(commands.Cog): async def reacted_msg_chance(self, message): """ - Randomly add a skull or candy to a message if there is a reaction there already - (higher probability) + Randomly add a skull or candy reaction to a message if there is a reaction there already. + + This event has a higher probability of occurring than a reaction add to a message without an + existing reaction. """ if random.randint(1, ADD_SKULL_EXISTING_REACTION_CHANCE) == 1: @@ -122,7 +122,8 @@ class CandyCollection(commands.Cog): return await message.add_reaction('\N{CANDY}') async def ten_recent_msg(self): - """Get the last 10 messages sent in the channel""" + """Get the last 10 messages sent in the channel.""" + ten_recent = [] recent_msg = max(message.id for message in self.bot._connection._messages @@ -139,9 +140,7 @@ class CandyCollection(commands.Cog): return ten_recent async def get_message(self, msg_id): - """ - Get the message from it's ID. - """ + """Get the message from its ID.""" try: o = discord.Object(id=msg_id + 1) @@ -158,15 +157,12 @@ class CandyCollection(commands.Cog): return None async def hacktober_channel(self): - """ - Get #hacktoberbot channel from it's id - """ + """Get #hacktoberbot channel from its ID.""" + return self.bot.get_channel(id=Hacktoberfest.channel_id) async def remove_reactions(self, reaction): - """ - Remove all candy/skull reactions - """ + """Remove all candy/skull reactions.""" try: async for user in reaction.users(): @@ -176,26 +172,22 @@ class CandyCollection(commands.Cog): pass async def send_spook_msg(self, author, channel, candies): - """ - Send a spooky message - """ + """Send a spooky message.""" + e = discord.Embed(colour=author.colour) e.set_author(name="Ghosts and Ghouls and Jack o' lanterns at night; " f"I took {candies} candies and quickly took flight.") await channel.send(embed=e) def save_to_json(self): - """ - Save json to the file. - """ + """Save JSON to a local file.""" + with open(json_location, 'w') as outfile: json.dump(self.candy_json, outfile) @commands.command() async def candy(self, ctx): - """ - Get the candy leaderboard and save to json when this is called - """ + """Get the candy leaderboard and save to JSON.""" # use run_in_executor to prevent blocking thing = functools.partial(self.save_to_json) @@ -232,5 +224,7 @@ class CandyCollection(commands.Cog): def setup(bot): + """Candy Collection game Cog load.""" + bot.add_cog(CandyCollection(bot)) log.info("CandyCollection cog loaded") |