Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reacts when Taiwan is mentioned #19

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)