diff --git a/commands/react_baltics/consts.py b/commands/react_baltics/consts.py new file mode 100644 index 0000000..fbc4012 --- /dev/null +++ b/commands/react_baltics/consts.py @@ -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) diff --git a/commands/react_baltics/react_baltics.py b/commands/react_baltics/react_baltics.py new file mode 100644 index 0000000..dee00e8 --- /dev/null +++ b/commands/react_baltics/react_baltics.py @@ -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) diff --git a/commands/reacttw/consts.py b/commands/reacttw/consts.py new file mode 100644 index 0000000..bbc9734 --- /dev/null +++ b/commands/reacttw/consts.py @@ -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) diff --git a/commands/reacttw/react_tw.py b/commands/reacttw/react_tw.py index 63bfcca..a091023 100644 --- a/commands/reacttw/react_tw.py +++ b/commands/reacttw/react_tw.py @@ -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. @@ -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) diff --git a/main.py b/main.py index 223004a..a4c8727 100644 --- a/main.py +++ b/main.py @@ -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 @@ -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)