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

React Baltics and Taiwan #23

Merged
merged 6 commits into from
Aug 11, 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
27 changes: 27 additions & 0 deletions commands/react_baltics/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from re import compile, IGNORECASE, UNICODE

POSSIBLE_REACTS = (
"<:tw_baltics_heart:1132524940587962388>",
"<:bubblemilktea:1132632348651966596>",
)

KEYWORDS = (
# Lithuanian
"Taivanas",
"Taivane",
"Taivano",
"Taivanui",
"Taivanietis",
"Taivanietė",
"Taivaniečiai",
"Taivaniečių",
"Taivaniečiui",
"Taivaniečiams",
"Taivanietiškas",
"Taivana"
# Latvian
# Estonian
)


BALTIC_REGEX = compile(rf"({'|'.join(KEYWORDS)})", flags=IGNORECASE | UNICODE)
25 changes: 25 additions & 0 deletions commands/react_baltics/react_baltics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import discord
import random
from .consts import POSSIBLE_REACTS, BALTIC_REGEX


def is_baltic_message(message: discord.Message):
return BALTIC_REGEX.search(message.content)


def mock_bernoulli(p: float) -> bool:
"""Returns True with probability p.

Args:
p (float): a float between 0 and 1.

Returns:
bool: True or False.
"""
return random.random() < p


async def send_react_baltic(message: discord.Message):
for react in POSSIBLE_REACTS:
if mock_bernoulli(0.69):
await message.add_reaction(react)
76 changes: 76 additions & 0 deletions commands/reacttw/consts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from re import compile, IGNORECASE, UNICODE

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>",
"<:TWHW3:1139172056349548604>",
"<:rice_cooker:1139169683824713892>",
"<:tw_beer:1139314162615459942>",
"<:hilife:1139176380521791519>",
"<:tw_hw_3:1139172056349548604>",
"<:AppleSidra:1139357659733172234>",
"<:Capoo:1139357657698938991>",
)

KEYWORDS = (
"TAIWAN",
"FORMOSA",
"TAIPEI",
"TAOYUAN",
"TAICHUNG",
"TAINAN",
"KAOHSIUNG",
"MIAOLI",
"CHANGHUA",
"NANTOU",
"YUNLIN",
"PINGTUNG",
"YILAN",
"HUALIEN",
"TAITUNG",
"PENGHU",
"KINMEN",
"LIENCHIANG",
"KEELUNG",
"HSINCHU",
"CHIAYI",
"台灣",
"臺灣",
"臺北",
"台北",
"新北",
"桃園",
"臺中",
"台中",
"臺南",
"台南",
"高雄",
"新竹",
"苗栗",
"彰化",
"南投",
"雲林",
"嘉義",
"屏東",
"宜蘭",
"花蓮",
"臺東",
"台東",
"澎湖",
"金門",
"連江",
"基隆",
"新竹",
"嘉義",
"美麗島",
)


TW_REGEX = compile(rf"({'|'.join(KEYWORDS)})", flags=IGNORECASE | UNICODE)
28 changes: 4 additions & 24 deletions commands/reacttw/react_tw.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,14 @@
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>",
"<:TWHW3:1139172056349548604>",
"<:rice_cooker:1139169683824713892>",
)
from .consts import POSSIBLE_REACTS, TW_REGEX


def is_TW_message(message: discord.Message):
to_upper = message.content.upper()
return (
("TAIWAN" in to_upper)
or ("FORMOSA" in to_upper)
or ("台灣" in message.content)
or ("臺灣" in message.content)
or ("FORMOSA" in message.content)
)
return TW_REGEX.search(message.content)


def mock_bernoulli(p: float) -> bool:
"""Returns True with probability.
"""Returns True with probability p.

Args:
p (float): a float between 0 and 1.
Expand All @@ -41,5 +21,5 @@ def mock_bernoulli(p: float) -> bool:

async def send_react_tw(message: discord.Message):
for react in POSSIBLE_REACTS:
if mock_bernoulli(0.20):
if mock_bernoulli(0.15):
await message.add_reaction(react)
4 changes: 4 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from commands.one_o_one import one_o_one
from commands import hgs
from commands.reacttw import react_tw
from commands.react_baltics import react_baltics
from commands.shiba import random_shiba
import sys

Expand Down Expand Up @@ -101,5 +102,8 @@ async def on_message(message: discord.Message):
if react_tw.is_TW_message(message):
await react_tw.send_react_tw(message)

if react_baltics.is_baltic_message(message):
await react_baltics.send_react_baltic(message)


client.run(TOKEN)