Skip to content

Commit

Permalink
Merge pull request #31 from placeTW/react_cz
Browse files Browse the repository at this point in the history
React LT, LV in TW + tests
  • Loading branch information
chanomkaimuk authored Aug 13, 2023
2 parents ee21ebb + bcc7b98 commit 1517f58
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 5 deletions.
23 changes: 20 additions & 3 deletions commands/react_baltics/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,34 @@
POSSIBLE_REACTS = (
"<:tw_baltics_heart:1132524940587962388>",
"<:bubblemilktea:1132632348651966596>",
"<:chaos:1140296704516706315>",
)

LT_REGEX_STR = r"Taivan(?:as|a|e|o|ui|ie(?:tiškas|tis|tė|či(?:ų|u|ai|ui|ams)))"
LT_REGEX_STR_TW = "立陶宛"

LV_REGEX_STR = (
r"Taivān(?:a|ā|ai|as|u|isks|ie(?:tis|te|šu|tim|tei|šiem|ti|te|ši|tes|ši))"
)
LV_REGEX_STR_TW = "拉脫維亞"


KEYWORDS = (
# Lithuanian
r"Taivan(?:as|a|e|o|ui|ie(?:tiškas|tis|tė|či(?:ų|u|ai|ui|ams)))",
LT_REGEX_STR,
# Latvian
r"Taivān(?:a|ā|ai|as|u|isks|ie(?:tis|te|šu|tim|tei|šiem|ti|te|ši|tes|ši))",
LV_REGEX_STR,
# ! Estonian (STILL MISSING)
)

LT_REGEX = compile(
rf"\b(?:{LT_REGEX_STR})\b|{LT_REGEX_STR_TW}", flags=IGNORECASE | UNICODE
)
LV_REGEX = compile(
rf"\b(?:{LV_REGEX_STR})\b|{LV_REGEX_STR_TW}", flags=IGNORECASE | UNICODE
)

BALTIC_REGEX = compile(
rf"\b(?:{'|'.join(KEYWORDS)})\b", flags=IGNORECASE | UNICODE
rf"\b(?:{'|'.join(KEYWORDS)})\b|{LV_REGEX_STR_TW}|{LT_REGEX_STR_TW}",
flags=IGNORECASE | UNICODE,
)
8 changes: 6 additions & 2 deletions commands/react_baltics/react_baltics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import discord
import random
from .consts import POSSIBLE_REACTS, BALTIC_REGEX
from .consts import POSSIBLE_REACTS, BALTIC_REGEX, LT_REGEX, LV_REGEX
from ..modules.probability import mock_bernoulli


Expand All @@ -10,5 +10,9 @@ def is_baltic_message(message: discord.Message):

async def send_react_baltic(message: discord.Message):
for react in POSSIBLE_REACTS:
if mock_bernoulli(0.69):
if mock_bernoulli(0.40):
await message.add_reaction(react)
if LV_REGEX.search(message.content) and mock_bernoulli(0.60):
await message.add_reaction("<:lv_tw_hgs:1139660598574055514>")
if LT_REGEX.search(message.content) and mock_bernoulli(0.60):
await message.add_reaction("<:lt_tw_hgs:1139647918442283038>")
2 changes: 2 additions & 0 deletions commands/react_czech/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

POSSIBLE_REACTS = (
"❤",
"🇨🇿",
"<:bubblemilktea:1132632348651966596>",
"<:roc_troll:1133368648967405610>",
)

KEYWORDS = (r"T(?:ch)?aj-?[wv]an(?:y|u|ů|ům|e|ě|ech|em|ský|sky|ec|ka)?",)
Expand Down
17 changes: 17 additions & 0 deletions tests/test_react/test_react_baltics.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
# ! Estonian (STILL MISSING)
)

TEST_CASES_TW = ("立陶宛", "拉脫維亞")


@pytest.mark.parametrize(
"test_str",
Expand All @@ -54,6 +56,21 @@ def test_react_baltics_regex_yes_match(test_str: str):
assert BALTIC_REGEX.search(test_str.title())


@pytest.mark.parametrize(
"test_str",
TEST_CASES_TW,
)
def test_react_baltics_regex_tw_yes_match(test_str: str):
"""Tests that these strings return TRUE."""
# * isolated string
assert BALTIC_REGEX.search(test_str)
# * surrounded by spaces
assert BALTIC_REGEX.search(f" {test_str} ")
# * surrounded by text
assert BALTIC_REGEX.search(f"a{test_str}b")
assert BALTIC_REGEX.search(f"哈{test_str}囉")


@pytest.mark.parametrize(
"test_str",
TEST_CASES,
Expand Down

0 comments on commit 1517f58

Please sign in to comment.