Skip to content

Commit

Permalink
Merge pull request #3713 from dev-hato/fono/refactor-hato-mikuji
Browse files Browse the repository at this point in the history
hato-bot用おみくじセットアップをplugins/hato_mikujiに分離
  • Loading branch information
fono09 authored Feb 23, 2024
2 parents f886134 + 759a305 commit e48f047
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 51 deletions.
51 changes: 2 additions & 49 deletions plugins/hato.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import json
import os
import re
from enum import Enum, auto
from logging import getLogger
from tempfile import NamedTemporaryFile
from typing import List, Optional
Expand All @@ -26,8 +25,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,
Expand All @@ -36,6 +33,7 @@
show_random_vocabulary,
show_vocabulary,
)
from plugins.hato_mikuji import HatoMikuji

logger = getLogger(__name__)

Expand Down Expand Up @@ -429,58 +427,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")
Expand Down
60 changes: 60 additions & 0 deletions plugins/hato_mikuji.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions tests/plugins/test_hato.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()),
)


Expand Down

0 comments on commit e48f047

Please sign in to comment.