From b52520c965d4220e5a8c2a0699e4ce6ec218bb4e Mon Sep 17 00:00:00 2001 From: chanomkaimuk <22185824+chanomkaimuk@users.noreply.github.com> Date: Thu, 10 Aug 2023 15:01:31 +0200 Subject: [PATCH 1/6] formosa hotfix --- commands/reacttw/react_tw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/reacttw/react_tw.py b/commands/reacttw/react_tw.py index 63bfcca..4d6868f 100644 --- a/commands/reacttw/react_tw.py +++ b/commands/reacttw/react_tw.py @@ -23,7 +23,7 @@ def is_TW_message(message: discord.Message): or ("FORMOSA" in to_upper) or ("台灣" in message.content) or ("臺灣" in message.content) - or ("FORMOSA" in message.content) + or ("FORMOSA" in to_upper) ) From 90a50b00bb4224fb5dbf883fd25a9b8563f20b1b Mon Sep 17 00:00:00 2001 From: chanomkaimuk <22185824+chanomkaimuk@users.noreply.github.com> Date: Fri, 11 Aug 2023 02:29:12 +0200 Subject: [PATCH 2/6] more possible emotes, reduced probability to 0.15 --- commands/reacttw/react_tw.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/commands/reacttw/react_tw.py b/commands/reacttw/react_tw.py index 4d6868f..731c388 100644 --- a/commands/reacttw/react_tw.py +++ b/commands/reacttw/react_tw.py @@ -13,6 +13,9 @@ "<:bubblemilktea:1132632348651966596>", "<:TWHW3:1139172056349548604>", "<:rice_cooker:1139169683824713892>", + "<:tw_beer:1139314162615459942>", + "<:hilife:1139176380521791519>", + "<:tw_hw_3:1139172056349548604>", ) @@ -41,5 +44,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) From 630ad974648476f9678bf0ca003eaebb58d0fce3 Mon Sep 17 00:00:00 2001 From: chanomkaimuk <22185824+chanomkaimuk@users.noreply.github.com> Date: Fri, 11 Aug 2023 02:52:39 +0200 Subject: [PATCH 3/6] more possible emotes, more keywords, turned to regex --- commands/reacttw/consts.py | 70 ++++++++++++++++++++++++++++++++++++ commands/reacttw/react_tw.py | 30 +++------------- 2 files changed, 74 insertions(+), 26 deletions(-) create mode 100644 commands/reacttw/consts.py diff --git a/commands/reacttw/consts.py b/commands/reacttw/consts.py new file mode 100644 index 0000000..ac8e7ed --- /dev/null +++ b/commands/reacttw/consts.py @@ -0,0 +1,70 @@ +import re + +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>", +) + +KEYWORDS = ( + "TAIWAN", + "FORMOSA", + "TAIPEI", + "TAOYUAN", + "TAICHUNG", + "TAINAN", + "KAOHSIUNG", + "MIAOLI", + "CHANGHUA", + "NANTOU", + "YUNLIN", + "PINGTUNG", + "YILAN", + "HUALIEN", + "TAITUNG", + "PENGHU", + "KINMEN", + "LIENCHIANG", + "KEELUNG", + "HSINCHU", + "CHIAYI", + "台灣", + "臺灣", + "臺北", + "新北", + "桃園", + "臺中", + "臺南", + "高雄", + "新竹", + "苗栗", + "彰化", + "南投", + "雲林", + "嘉義", + "屏東", + "宜蘭", + "花蓮", + "臺東", + "澎湖", + "金門", + "連江", + "基隆", + "新竹", + "嘉義", + "美麗島", +) + + +TW_REGEX = re.compile(rf"({'|'.join(KEYWORDS)})") diff --git a/commands/reacttw/react_tw.py b/commands/reacttw/react_tw.py index 731c388..74fd1f6 100644 --- a/commands/reacttw/react_tw.py +++ b/commands/reacttw/react_tw.py @@ -1,37 +1,15 @@ 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>", - "<:tw_beer:1139314162615459942>", - "<:hilife:1139176380521791519>", - "<:tw_hw_3:1139172056349548604>", -) +import re +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 to_upper) - ) + return TW_REGEX.search(message.content.upper()) def mock_bernoulli(p: float) -> bool: - """Returns True with probability. + """Returns True with probability p. Args: p (float): a float between 0 and 1. From cd30bcaea4ae751e2f043640fa9a1a24f3466290 Mon Sep 17 00:00:00 2001 From: chanomkaimuk <22185824+chanomkaimuk@users.noreply.github.com> Date: Fri, 11 Aug 2023 02:53:25 +0200 Subject: [PATCH 4/6] added more emotes --- commands/reacttw/consts.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/commands/reacttw/consts.py b/commands/reacttw/consts.py index ac8e7ed..e682c13 100644 --- a/commands/reacttw/consts.py +++ b/commands/reacttw/consts.py @@ -15,6 +15,8 @@ "<:tw_beer:1139314162615459942>", "<:hilife:1139176380521791519>", "<:tw_hw_3:1139172056349548604>", + "<:AppleSidra:1139357659733172234>", + "<:Capoo:1139357657698938991>", ) KEYWORDS = ( From 908c35731bbe99cea321adbc74127d17eb543f55 Mon Sep 17 00:00:00 2001 From: chanomkaimuk <22185824+chanomkaimuk@users.noreply.github.com> Date: Fri, 11 Aug 2023 02:54:31 +0200 Subject: [PATCH 5/6] slight reactoring --- commands/reacttw/consts.py | 4 ++-- commands/reacttw/react_tw.py | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/commands/reacttw/consts.py b/commands/reacttw/consts.py index e682c13..b2ccf49 100644 --- a/commands/reacttw/consts.py +++ b/commands/reacttw/consts.py @@ -1,4 +1,4 @@ -import re +from re import compile POSSIBLE_REACTS = ( "<:flag_twi:1133045891780071436>", @@ -69,4 +69,4 @@ ) -TW_REGEX = re.compile(rf"({'|'.join(KEYWORDS)})") +TW_REGEX = compile(rf"({'|'.join(KEYWORDS)})") diff --git a/commands/reacttw/react_tw.py b/commands/reacttw/react_tw.py index 74fd1f6..75ae938 100644 --- a/commands/reacttw/react_tw.py +++ b/commands/reacttw/react_tw.py @@ -1,6 +1,5 @@ import discord import random -import re from .consts import POSSIBLE_REACTS, TW_REGEX From 7288fc1c7c1c098d9d06847ece8c9253c8493e4d Mon Sep 17 00:00:00 2001 From: chanomkaimuk <22185824+chanomkaimuk@users.noreply.github.com> Date: Fri, 11 Aug 2023 03:14:49 +0200 Subject: [PATCH 6/6] improved regex and added Lithuanian keywords for Baltic heart --- commands/react_baltics/consts.py | 27 +++++++++++++++++++++++++ commands/react_baltics/react_baltics.py | 25 +++++++++++++++++++++++ commands/reacttw/consts.py | 8 ++++++-- commands/reacttw/react_tw.py | 2 +- main.py | 4 ++++ 5 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 commands/react_baltics/consts.py create mode 100644 commands/react_baltics/react_baltics.py 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 index b2ccf49..bbc9734 100644 --- a/commands/reacttw/consts.py +++ b/commands/reacttw/consts.py @@ -1,4 +1,4 @@ -from re import compile +from re import compile, IGNORECASE, UNICODE POSSIBLE_REACTS = ( "<:flag_twi:1133045891780071436>", @@ -44,10 +44,13 @@ "台灣", "臺灣", "臺北", + "台北", "新北", "桃園", "臺中", + "台中", "臺南", + "台南", "高雄", "新竹", "苗栗", @@ -59,6 +62,7 @@ "宜蘭", "花蓮", "臺東", + "台東", "澎湖", "金門", "連江", @@ -69,4 +73,4 @@ ) -TW_REGEX = compile(rf"({'|'.join(KEYWORDS)})") +TW_REGEX = compile(rf"({'|'.join(KEYWORDS)})", flags=IGNORECASE | UNICODE) diff --git a/commands/reacttw/react_tw.py b/commands/reacttw/react_tw.py index 75ae938..a091023 100644 --- a/commands/reacttw/react_tw.py +++ b/commands/reacttw/react_tw.py @@ -4,7 +4,7 @@ def is_TW_message(message: discord.Message): - return TW_REGEX.search(message.content.upper()) + return TW_REGEX.search(message.content) def mock_bernoulli(p: float) -> bool: 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)