-
Notifications
You must be signed in to change notification settings - Fork 1
/
unflipper.py
72 lines (60 loc) · 3.1 KB
/
unflipper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import discord
import logging
class Unflipper(discord.Client):
def __init__(self, log_level=None, **kwargs):
self.BASIC_TABLE = "┻━┻"
self.AUTOFLIP_MSG = "(╯°□°)╯︵ " + self.BASIC_TABLE
self.logger = logging.getLogger("discord.client.unflipper")
if not log_level:
log_level = logging.INFO
self.logger.setLevel(log_level)
intents = discord.Intents.default()
intents.message_content = True
intents.reactions = True
super().__init__(intents=intents, **kwargs)
async def on_message(self, message):
# we do not want the bot to reply to itself
if message.author.id == self.user.id:
return
if self.BASIC_TABLE in message.content:
if message.author.id == 224697402383138817:
await message.reply("Fuck you.", mention_author=True)
elif self.AUTOFLIP_MSG in message.content:
await self.unflip(message)
else:
reply_content = "Do...do I unflip it? O.o"
reply = await message.reply(reply_content)
await reply.add_reaction("✅")
await reply.add_reaction("❌")
async def on_raw_reaction_add(self, reactionEvent):
message = await self.get_channel(reactionEvent.channel_id).fetch_message(reactionEvent.message_id)
emoji = str(reactionEvent.emoji)
# Ignore reactions from the bot and the flipper
if reactionEvent.user_id in [self.user.id, message.reference.resolved.author.id]:
self.logger.debug(f"Ignoring reaction \"{emoji}\" on message {message.id}" +
f"due to reactor ({reactionEvent.member.name})")
return
# Ignore reactions that we did not prompt
reaction = discord.utils.get(message.reactions, emoji=emoji)
if not reaction or not reaction.me:
self.logger.debug(f"Ignoring reaction \"{emoji}\" on message {message.id} because it was unprompted")
return
if emoji == "✅":
self.logger.debug(f"Unflipping message {message.reference.resolved.id}" +
f"from {message.reference.resolved.author.name} due to reaction" +
f"from {reactionEvent.member.name}")
await self.unflip(message.reference.resolved)
elif emoji == "❌":
self.logger.debug(f"Ignoring message {message.reference.resolved.id}" +
f"from {message.reference.resolved.author.name} due to reaction" +
f"from {reactionEvent.member.name}")
else:
self.logger.warn(f"Fallback! Ignoring reaction \"{emoji}\" on message {message.id}" +
"even though it was prompted")
return
for r in message.reactions:
await r.remove(self.user)
async def unflip(self, message):
flips = message.content.count("┻━┻")
reply_content = "┬─┬ノ( º \_ ºノ) " * flips
await message.reply(reply_content.strip(), mention_author=True)