From ea63309c33d1bde2b3ef9e1aa89b7e3c7703817d Mon Sep 17 00:00:00 2001 From: chanomkaimuk <22185824+chanomkaimuk@users.noreply.github.com> Date: Thu, 10 Aug 2023 02:56:12 +0200 Subject: [PATCH] reacts when Taiwan is mentioned --- commands/reacttw/react_tw.py | 32 ++++++++++++++++++++++++++++++++ main.py | 14 ++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 commands/reacttw/react_tw.py diff --git a/commands/reacttw/react_tw.py b/commands/reacttw/react_tw.py new file mode 100644 index 0000000..8acbcfb --- /dev/null +++ b/commands/reacttw/react_tw.py @@ -0,0 +1,32 @@ +import discord +import random + +POSSIBLE_REACTS = ( + "<:flag_twi:1133045891780071436>", + "<:Black_Bear:1132603463126237244>", + "<:Urocissacaerulea:1132839946303062086>", + "<:101_Floor:1132608196515725332>", + "<:tw_amogus:1133361653908516885>", + "<:roc_troll:1133368648967405610>", + "<:roc_heart:1133045894678319235>", + "<:tw_heart:1133045893227102299>", + "<:bubblemilktea:1132632348651966596>", +) + + +def mock_bernoulli(p: float) -> bool: + """Returns True with probability. + + Args: + p (float): a float between 0 and 1. + + Returns: + bool: True or False. + """ + return random.random() < p + + +async def send_react_tw(message: discord.Message): + for react in POSSIBLE_REACTS: + if mock_bernoulli(0.25): + await message.add_reaction(react) diff --git a/main.py b/main.py index e0365ab..cf8f92d 100644 --- a/main.py +++ b/main.py @@ -14,6 +14,7 @@ from commands.edit_entry import edit_entry_cmd from commands.one_o_one import one_o_one from commands import hgs +from commands.reacttw import react_tw from commands.shiba import random_shiba import sys @@ -27,6 +28,8 @@ # setting up the bot intents = discord.Intents.default() +# also turn on messages functionality +intents.message_content = True # if you don't want all intents you can do discord.Intents.default() client = discord.Client(intents=intents) # CommandTree is where all our defined commands are stored @@ -88,4 +91,15 @@ async def on_ready(): print("Bot is ready.") +# when someone sends any message +@client.event +async def on_message(message: discord.Message): + # don't respond to bot's own posts + if message.author == client.user: + return + + if "TAIWAN" in message.content.upper(): + await react_tw.send_react_tw(message) + + client.run(TOKEN)