Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hato-bot用おみくじセットアップをplugins/hato_mikujiに分離 #3713

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
massongit marked this conversation as resolved.
Show resolved Hide resolved
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
Loading