aboutsummaryrefslogtreecommitdiffstats
path: root/bot/seasons/halloween/candy_collection.py
diff options
context:
space:
mode:
Diffstat (limited to 'bot/seasons/halloween/candy_collection.py')
-rw-r--r--bot/seasons/halloween/candy_collection.py58
1 files changed, 26 insertions, 32 deletions
diff --git a/bot/seasons/halloween/candy_collection.py b/bot/seasons/halloween/candy_collection.py
index 6932097c..f8ab4c60 100644
--- a/bot/seasons/halloween/candy_collection.py
+++ b/bot/seasons/halloween/candy_collection.py
@@ -7,7 +7,7 @@ import random
import discord
from discord.ext import commands
-from bot.constants import Hacktoberfest
+from bot.constants import Channels
log = logging.getLogger(__name__)
@@ -21,6 +21,8 @@ ADD_SKULL_EXISTING_REACTION_CHANCE = 20 # 5%
class CandyCollection(commands.Cog):
+ """Candy collection game Cog."""
+
def __init__(self, bot):
self.bot = bot
with open(json_location) as candy:
@@ -33,15 +35,13 @@ 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:
return
# ensure it's hacktober channel
- if message.channel.id != Hacktoberfest.channel_id:
+ if message.channel.id != Channels.seasonalbot_chat:
return
# do random check for skull first as it has the lower chance
@@ -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
@@ -67,7 +65,7 @@ class CandyCollection(commands.Cog):
return
# check to ensure it is in correct channel
- if message.channel.id != Hacktoberfest.channel_id:
+ if message.channel.id != Channels.seasonalbot_chat:
return
# if its not a candy or skull, and it is one of 10 most recent messages,
@@ -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,11 +122,12 @@ 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
- if message.channel.id == Hacktoberfest.channel_id)
+ if message.channel.id == Channels.seasonalbot_chat)
channel = await self.hacktober_channel()
ten_recent.append(recent_msg.id)
@@ -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
- """
- return self.bot.get_channel(id=Hacktoberfest.channel_id)
+ """Get #hacktoberbot channel from its ID."""
+
+ return self.bot.get_channel(id=Channels.seasonalbot_chat)
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")