From eef9c71d05d7d729b4a684ff1c6cfac55aadb1a2 Mon Sep 17 00:00:00 2001 From: fono Date: Fri, 23 Feb 2024 21:22:38 +0900 Subject: [PATCH] =?UTF-8?q?hato-bot=E7=94=A8=E3=81=8A=E3=81=BF=E3=81=8F?= =?UTF-8?q?=E3=81=98=E3=82=BB=E3=83=83=E3=83=88=E3=82=A2=E3=83=83=E3=83=97?= =?UTF-8?q?=E3=82=92plugins/hato=5Fmikuji=E3=81=AB=E5=88=86=E9=9B=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/hato.py | 50 ++----------------------------- plugins/hato_mikuji.py | 60 ++++++++++++++++++++++++++++++++++++++ tests/plugins/test_hato.py | 4 +-- 3 files changed, 64 insertions(+), 50 deletions(-) create mode 100644 plugins/hato_mikuji.py diff --git a/plugins/hato.py b/plugins/hato.py index b1d22346d3..2b7665f1c6 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,58 +428,13 @@ 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("おみくじ") 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..6860b06f3f --- /dev/null +++ b/plugins/hato_mikuji.py @@ -0,0 +1,60 @@ +""" +hato-bot用のおみくじラッパー +""" + +from enum import Enum, auto + +from library.omikuji import OmikujiResult, OmikujiResults, draw + + +class HatoMikuji: + """ + HatoMikuji + + Omikujiをhato-bot用に設定を導入しラップするAdapter + """ + + class OmikujiEnum(Enum): + """ + HatoMikuji用のおみくじ結果一覧 + """ + + DAI_KICHI = auto() + CHU_KICHI = auto() + SHO_KICHI = auto() + KICHI = auto() + SUE_KICHI = auto() + AGE_KICHI = auto() + KYO = auto() + DAI_KYO = auto() + + 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()), )