Files

69 lines
2.7 KiB
Python
Raw Permalink 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."""
async def red_delete_data_for_user(self, **kwargs):
""" Nothing to delete """
return
2019-10-09 16:47:48 -07:00
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."
)
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:
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(
2020-11-25 19:45:43 +01:00
f"Everyone, let's pay respects to **{filter_mass_mentions(answer)}**! Press the f reaction on this message to pay respects."
2019-10-09 16:47:48 -07:00
)
await message.add_reaction("\U0001f1eb")
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
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
if self.channels[str(reaction.message.channel.id)]["msg_id"] != reaction.message.id:
2019-10-09 21:32:39 -04:00
return
2019-10-09 16:47:48 -07:00
if user.id == self.bot.user.id:
return
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.")
self.channels[str(reaction.message.channel.id)]["reacted"].append(user.id)