aboutsummaryrefslogtreecommitdiffstats
path: root/bot/exts
diff options
context:
space:
mode:
authorGravatar Quanta <[email protected]>2020-10-10 14:29:34 +0530
committerGravatar Quanta <[email protected]>2020-10-10 14:29:34 +0530
commitb83c2a9c735a9bdfd33fb1f86862ef8c50db7402 (patch)
tree49990eb5b1b45b33e3d8a120363cdfb499f9dfb8 /bot/exts
parentUse discord.Reaction#clear to remove reactions (diff)
Remove redundant function ten_recent_msg
Diffstat (limited to 'bot/exts')
-rw-r--r--bot/exts/halloween/candy_collection.py29
1 files changed, 8 insertions, 21 deletions
diff --git a/bot/exts/halloween/candy_collection.py b/bot/exts/halloween/candy_collection.py
index 8cd4b7ed..8afababf 100644
--- a/bot/exts/halloween/candy_collection.py
+++ b/bot/exts/halloween/candy_collection.py
@@ -2,7 +2,7 @@ import json
import logging
import os
import random
-from typing import List, Union
+from typing import Union
import discord
from discord.ext import commands
@@ -84,7 +84,11 @@ class CandyCollection(commands.Cog):
# if its not a candy or skull, and it is one of 10 most recent messages,
# proceed to add a skull/candy with higher chance
if str(reaction.emoji) not in (EMOJIS['SKULL'], EMOJIS['CANDY']):
- if message.id in await self.ten_recent_msg():
+ recent_message_ids = map(
+ lambda m: m.id,
+ await self.hacktober_channel.history(limit=10).flatten()
+ )
+ if message.id in recent_message_ids:
await self.reacted_msg_chance(message)
return
@@ -125,25 +129,8 @@ class CandyCollection(commands.Cog):
self.candy_messages.add(message.id)
return await message.add_reaction(EMOJIS['CANDY'])
- async def ten_recent_msg(self) -> List[int]:
- """Get the last 10 messages sent in the channel."""
- ten_recent = []
- recent_msg_id = max(
- message.id for message in self.bot._connection._messages
- if message.channel.id == Channels.seasonalbot_commands
- )
-
- channel = await self.hacktober_channel()
- ten_recent.append(recent_msg_id)
-
- for i in range(9):
- o = discord.Object(id=recent_msg_id + i)
- msg = await next(channel.history(limit=1, before=o))
- ten_recent.append(msg.id)
-
- return ten_recent
-
- async def hacktober_channel(self) -> discord.TextChannel:
+ @property
+ def hacktober_channel(self) -> discord.TextChannel:
"""Get #hacktoberbot channel from its ID."""
return self.bot.get_channel(id=Channels.seasonalbot_commands)