Skip to content

Commit

Permalink
Merge pull request #19 from placeTW/reacttw
Browse files Browse the repository at this point in the history
reacts when Taiwan is mentioned
  • Loading branch information
howardt12345 authored Aug 10, 2023
2 parents e113d77 + ea63309 commit f15ceb7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
32 changes: 32 additions & 0 deletions commands/reacttw/react_tw.py
Original file line number Diff line number Diff line change
@@ -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)
14 changes: 14 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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)

0 comments on commit f15ceb7

Please sign in to comment.