From a888776a6cd83cbf6a46ac007e51ecbaf84685c1 Mon Sep 17 00:00:00 2001 From: aikaterna <20862007+aikaterna@users.noreply.github.com> Date: Wed, 9 Oct 2019 16:47:48 -0700 Subject: [PATCH] [PressF] to pay respects --- README.md | 2 ++ pressf/__init__.py | 4 ++++ pressf/info.json | 13 +++++++++++ pressf/pressf.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 pressf/__init__.py create mode 100644 pressf/info.json create mode 100644 pressf/pressf.py diff --git a/README.md b/README.md index 8cb8c08..ed34720 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,8 @@ partycrash - A port of Will's partycrash command from the v2 Admin cog. This cog pingtime - Show all shards' pingtimes. +pressf - A port/rewrite of NekoTony's v2 pressf cog. Pay your respects by pressing F. + pupper - A cog for Ryan5374. A pet that comes around on an on_message listener and waits for someone to pet it (react with a standard wave emoji), and rewards with credits. Many attributes are configurable. region - A command to change the voice region of a server. Requires the guild admin or mod role or guild administrator. diff --git a/pressf/__init__.py b/pressf/__init__.py new file mode 100644 index 0000000..f4e0737 --- /dev/null +++ b/pressf/__init__.py @@ -0,0 +1,4 @@ +from .pressf import PressF + +def setup(bot): + bot.add_cog(PressF(bot)) diff --git a/pressf/info.json b/pressf/info.json new file mode 100644 index 0000000..d106408 --- /dev/null +++ b/pressf/info.json @@ -0,0 +1,13 @@ +{ + "author": [ + "aikaterna" + ], + "description": "Pay respects to a thing or user by pressing f.", + "install_msg": "Thanks for installing, have fun.", + "short": "Press f to pay respects.", + "tags": [ + "pressf", + "respects", + ], + "type": "COG" +} diff --git a/pressf/pressf.py b/pressf/pressf.py new file mode 100644 index 0000000..b8ed361 --- /dev/null +++ b/pressf/pressf.py @@ -0,0 +1,58 @@ +import asyncio +import discord +from redbot.core import commands + + +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." + ) + + 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 + + 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.") + + answer = pressf.content + + message = await ctx.send( + f"Everyone, let's pay respects to **{answer}**! Press the f reaction on the this message to pay respects." + ) + await message.add_reaction("\U0001f1eb") + self.channels[str(ctx.channel.id)] = [] + await asyncio.sleep(120) + await message.delete() + amount = len(self.channels[str(ctx.channel.id)]) + word = "person has" if amount == 1 else "people have" + await ctx.channel.send(f"**{amount}** {word} paid respects to **{answer}**.") + 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 user.id == self.bot.user.id: + return + if str(user.id) not in self.channels[str(reaction.message.channel.id)]: + if str(reaction.emoji) == "\U0001f1eb": + await reaction.message.channel.send(f"**{user.display_name}** has paid respects.") + self.channels[str(reaction.message.channel.id)].append(user.id)