From b94bcd6f73b34f69dfe56d9deca89eb19f3c1f6d Mon Sep 17 00:00:00 2001 From: fono Date: Fri, 23 Feb 2024 21:22:38 +0900 Subject: [PATCH 1/3] =?UTF-8?q?hato-bot=E7=94=A8=E3=81=8A=E3=81=BF?= =?UTF-8?q?=E3=81=8F=E3=81=98=E3=82=BB=E3=83=83=E3=83=88=E3=82=A2=E3=83=83?= =?UTF-8?q?=E3=83=97=E3=82=92plugins/hato=5Fmikuji=E3=81=AB=E5=88=86?= =?UTF-8?q?=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/hato.py | 48 ++--------------------------------- plugins/hato_mikuji.py | 52 ++++++++++++++++++++++++++++++++++++++ tests/plugins/test_hato.py | 4 +-- 3 files changed, 56 insertions(+), 48 deletions(-) create mode 100644 plugins/hato_mikuji.py diff --git a/plugins/hato.py b/plugins/hato.py index b1d22346d3..19fa38c975 100644 --- a/plugins/hato.py +++ b/plugins/hato.py @@ -26,8 +26,6 @@ from library.hukidasi import generator from library.jma_amedas import get_jma_amedas from library.jma_amesh import jma_amesh -from library.omikuji import OmikujiResult, OmikujiResults -from library.omikuji import draw as omikuji_draw from library.textlint import get_textlint_result from library.vocabularydb import ( add_vocabulary, @@ -36,6 +34,7 @@ show_random_vocabulary, show_vocabulary, ) +from plugins.hato_mikuji import HatoMikuji logger = getLogger(__name__) @@ -429,49 +428,6 @@ def yoshiyoshi(): return "よしよし" -# 以下おみくじの設定 -# Refer: dev-hato/hato-bot#876 -class OmikujiEnum(Enum): - """ - おみくじの結果一覧 - """ - - DAI_KICHI = auto() - CHU_KICHI = auto() - SHO_KICHI = auto() - KICHI = auto() - SUE_KICHI = auto() - AGE_KICHI = auto() - KYO = auto() - DAI_KYO = auto() - - -omikuji_results = OmikujiResults( - { - OmikujiEnum.DAI_KICHI: OmikujiResult( - 12, ":tada: 大吉 何でもうまくいく!!気がする!!" - ), - OmikujiEnum.KICHI: OmikujiResult(100, ":smirk: 吉 まあうまくいくかも!?"), - OmikujiEnum.CHU_KICHI: OmikujiResult( - 100, ":smile: 中吉 そこそこうまくいくかも!?" - ), - OmikujiEnum.SHO_KICHI: OmikujiResult( - 100, ":smiley: 小吉 なんとなくうまくいくかも!?" - ), - OmikujiEnum.SUE_KICHI: OmikujiResult( - 37, ":expressionless: 末吉 まあ多分うまくいくかもね……!?" - ), - OmikujiEnum.AGE_KICHI: OmikujiResult( - 2, ":poultry_leg: 揚げ吉 鳩を揚げると良いことあるよ!!" - ), - OmikujiEnum.KYO: OmikujiResult( - 12, ":cry: 凶 ちょっと慎重にいったほうがいいかも……" - ), - OmikujiEnum.DAI_KYO: OmikujiResult( - 2, ":crying_cat_face: 大凶 そういう時もあります……猫になって耐えましょう" - ), - } -) @action("おみくじ") @@ -480,7 +436,7 @@ def omikuji(): おみくじ結果を返す """ - return omikuji_draw(omikuji_results)[1].message + return HatoMikuji.draw() @action("chat") diff --git a/plugins/hato_mikuji.py b/plugins/hato_mikuji.py new file mode 100644 index 0000000000..842beed116 --- /dev/null +++ b/plugins/hato_mikuji.py @@ -0,0 +1,52 @@ +""" +hato-bot用のおみくじラッパー +""" + +from enum import Enum, auto +from library.omikuji import OmikujiResult, OmikujiResults, draw + +# 以下おみくじの設定 +class OmikujiEnum(Enum): + """ + おみくじの結果一覧 + """ + DAI_KICHI = auto() + CHU_KICHI = auto() + SHO_KICHI = auto() + KICHI = auto() + SUE_KICHI = auto() + AGE_KICHI = auto() + KYO = auto() + DAI_KYO = auto() + +class HatoMikuji: + OMIKUJI_CONFIG = OmikujiResults( + { + OmikujiEnum.DAI_KICHI: OmikujiResult( + 12, ":tada: 大吉 何でもうまくいく!!気がする!!" + ), + OmikujiEnum.KICHI: OmikujiResult(100, ":smirk: 吉 まあうまくいくかも!?"), + OmikujiEnum.CHU_KICHI: OmikujiResult( + 100, ":smile: 中吉 そこそこうまくいくかも!?" + ), + OmikujiEnum.SHO_KICHI: OmikujiResult( + 100, ":smiley: 小吉 なんとなくうまくいくかも!?" + ), + OmikujiEnum.SUE_KICHI: OmikujiResult( + 37, ":expressionless: 末吉 まあ多分うまくいくかもね……!?" + ), + OmikujiEnum.AGE_KICHI: OmikujiResult( + 2, ":poultry_leg: 揚げ吉 鳩を揚げると良いことあるよ!!" + ), + OmikujiEnum.KYO: OmikujiResult( + 12, ":cry: 凶 ちょっと慎重にいったほうがいいかも……" + ), + OmikujiEnum.DAI_KYO: OmikujiResult( + 2, ":crying_cat_face: 大凶 そういう時もあります……猫になって耐えましょう" + ), + } + ) + + @classmethod + def draw(cls): + return draw(cls.OMIKUJI_CONFIG)[1].message diff --git a/tests/plugins/test_hato.py b/tests/plugins/test_hato.py index 1c6fe514ed..080e3d07c9 100644 --- a/tests/plugins/test_hato.py +++ b/tests/plugins/test_hato.py @@ -17,10 +17,10 @@ amesh, earth_quake, omikuji, - omikuji_results, split_command, yoshiyoshi, ) +from plugins.hato_mikuji import HatoMikuji from tests.library.test_geo import set_yahoo_mock from tests.plugins import TestClient @@ -399,7 +399,7 @@ def test_omikuji(self): omikuji(client1) self.assertIn( client1.get_post_message(), - map(lambda e: e.message, omikuji_results.values()), + map(lambda e: e.message, HatoMikuji.OMIKUJI_CONFIG.values()), ) From 20559086ca808db75347b51d8ef861936b53485f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:24:16 +0000 Subject: [PATCH 2/3] =?UTF-8?q?format=E3=81=8C=E9=96=93=E9=81=95=E3=81=A3?= =?UTF-8?q?=E3=81=A6=E3=81=9F=E3=81=AE=E3=81=A7=E7=9B=B4=E3=81=97=E3=81=A6?= =?UTF-8?q?=E3=81=82=E3=81=92=E3=81=9F=E3=82=88=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/hato.py | 2 -- plugins/hato_mikuji.py | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/hato.py b/plugins/hato.py index 19fa38c975..2b7665f1c6 100644 --- a/plugins/hato.py +++ b/plugins/hato.py @@ -428,8 +428,6 @@ def yoshiyoshi(): return "よしよし" - - @action("おみくじ") def omikuji(): """ diff --git a/plugins/hato_mikuji.py b/plugins/hato_mikuji.py index 842beed116..ab7512810b 100644 --- a/plugins/hato_mikuji.py +++ b/plugins/hato_mikuji.py @@ -3,13 +3,17 @@ """ from enum import Enum, auto + from library.omikuji import OmikujiResult, OmikujiResults, draw # 以下おみくじの設定 + + class OmikujiEnum(Enum): """ おみくじの結果一覧 """ + DAI_KICHI = auto() CHU_KICHI = auto() SHO_KICHI = auto() @@ -19,6 +23,7 @@ class OmikujiEnum(Enum): KYO = auto() DAI_KYO = auto() + class HatoMikuji: OMIKUJI_CONFIG = OmikujiResults( { From ca554ed047d62615254c3f5951ce218c70c241ca Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 23 Feb 2024 12:27:53 +0000 Subject: [PATCH 3/3] =?UTF-8?q?node=E3=82=92=E3=82=A2=E3=83=83=E3=83=97?= =?UTF-8?q?=E3=83=87=E3=83=BC=E3=83=88=E3=81=97=E3=81=A6=E3=81=82=E3=81=92?= =?UTF-8?q?=E3=81=9F=E3=82=88=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 180d62e445..a0e9befe6d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "textlint-rule-terminology": "4.0.1" }, "engines": { - "npm": "^10.2.3 || ^8.19.2" + "npm": "^10.2.4 || ^8.19.2" } }, "node_modules/@aashutoshrathi/word-wrap": { diff --git a/package.json b/package.json index 7d8d55040c..5c320c7c77 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,6 @@ "textlint-rule-terminology": "4.0.1" }, "engines": { - "npm": "^10.2.3 || ^8.19.2" + "npm": "^10.2.4 || ^8.19.2" } }