Files
aikaterna-cogs/pressf/pressf.py

67 lines
2.7 KiB
Python
Raw Normal View History

2019-10-09 16:47:48 -07:00
import asyncio
import discord
from redbot.core import commands
2019-10-10 17:59:52 -07:00
from redbot.core.utils.common_filters import filter_mass_mentions
2019-10-09 16:47:48 -07:00
class PressF(commands.Cog):
"""Pay some respects."""
def __init__(self, bot):
self.bot = bot
self.channels = {}
@commands.command()
@commands.bot_has_permissions(add_reactions=True)
async def pressf(self, ctx, *, user: discord.User = None):
"""Pay respects by pressing F"""
if str(ctx.channel.id) in self.channels:
return await ctx.send(
"Oops! I'm still paying respects in this channel, you'll have to wait until I'm done."
)
self.channels[str(ctx.channel.id)] = {}
2019-10-09 16:47:48 -07:00
if user:
answer = user.display_name
else:
await ctx.send("What do you want to pay respects to?")
def check(m):
return m.author == ctx.author and m.channel == ctx.channel
2019-10-09 16:47:48 -07:00
try:
pressf = await ctx.bot.wait_for("message", timeout=120.0, check=check)
except asyncio.TimeoutError:
del self.channels[str(ctx.channel.id)]
2019-10-09 16:47:48 -07:00
return await ctx.send("You took too long to reply.")
2019-10-09 21:32:39 -04:00
answer = pressf.content[:1900]
2019-10-09 16:47:48 -07:00
message = await ctx.send(
2019-10-10 17:59:52 -07:00
f"Everyone, let's pay respects to **{filter_mass_mentions(answer)}**! Press the f reaction on the this message to pay respects."
2019-10-09 16:47:48 -07:00
)
await message.add_reaction("\U0001f1eb")
2019-10-09 21:32:39 -04:00
self.channels[str(ctx.channel.id)] = {'msg_id': message.id, 'reacted': []}
2019-10-09 16:47:48 -07:00
await asyncio.sleep(120)
try:
await message.delete()
except (discord.errors.NotFound, discord.errors.Forbidden):
pass
2019-10-09 21:32:39 -04:00
amount = len(self.channels[str(ctx.channel.id)]['reacted'])
2019-10-09 16:47:48 -07:00
word = "person has" if amount == 1 else "people have"
await ctx.send(f"**{amount}** {word} paid respects to **{filter_mass_mentions(answer)}**.")
2019-10-09 16:47:48 -07:00
del self.channels[str(ctx.channel.id)]
@commands.Cog.listener()
async def on_reaction_add(self, reaction, user):
if str(reaction.message.channel.id) not in self.channels:
return
2019-10-09 21:32:39 -04:00
if self.channels[str(reaction.message.channel.id)]['msg_id'] != reaction.message.id:
return
2019-10-09 16:47:48 -07:00
if user.id == self.bot.user.id:
return
2019-10-09 21:32:39 -04:00
if user.id not in self.channels[str(reaction.message.channel.id)]['reacted']:
2019-10-09 16:47:48 -07:00
if str(reaction.emoji) == "\U0001f1eb":
await reaction.message.channel.send(f"**{user.name}** has paid their respects.")
2019-10-09 21:32:39 -04:00
self.channels[str(reaction.message.channel.id)]['reacted'].append(user.id)