Skip to content

Commit 2fc3644

Browse files
authored
Merge pull request #920 from dev-hato/fono/hato-plugin-logger-to-decorator
デコレータでリファクタ
2 parents 28c6b38 + 712562e commit 2fc3644

6 files changed

Lines changed: 206 additions & 196 deletions

File tree

Pipfile.lock

Lines changed: 27 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/analyze.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,41 @@
33
"""
44

55
from typing import Callable
6+
from functools import partial
67
from library.clientclass import BaseClient
78
from plugins import hato
89

910

1011
def analyze_message(message: str) -> Callable[[BaseClient], None]:
1112
"""コマンド解析"""
1213

13-
conditions = {'help': lambda m: hato.help_message,
14-
'eq': lambda m: hato.earth_quake,
15-
'地震': lambda m: hato.earth_quake,
16-
'text list': lambda m: hato.get_text_list,
17-
'text add ': lambda m: hato.add_text(m[len('text add '):]),
18-
'text show ': lambda m: hato.show_text(m[len('text show '):]),
19-
'text delete ': lambda m: hato.delete_text(m[len('text delete '):]),
20-
'text random': lambda m: hato.show_random_text,
21-
'text': lambda m: hato.show_random_text,
22-
'>< ': lambda m: hato.totuzensi(m[len('>< '):]),
23-
'amesh': lambda m: hato.amesh((m[len('amesh'):]).strip()),
24-
'電力': lambda m: hato.electricity_demand,
25-
'標高': lambda m: hato.altitude((m[len('標高'):]).strip()),
26-
'version': lambda m: hato.version,
27-
'にゃーん': lambda m: hato.yoshiyoshi,
28-
'おみくじ': lambda m: hato.omikuji,
29-
}
14+
conditions = {
15+
'help': lambda m: hato.help_message,
16+
'eq': lambda m: hato.earth_quake,
17+
'地震': lambda m: hato.earth_quake,
18+
'text list': lambda m: hato.get_text_list,
19+
'text add ': lambda m: partial(
20+
hato.add_text,
21+
word=m[len('text add '):]
22+
),
23+
'text show ': lambda m: partial(
24+
hato.show_text,
25+
power_word_id=m[len('text show '):]
26+
),
27+
'text delete ': lambda m: partial(
28+
hato.delete_text,
29+
power_word_id=m[len('text delete '):]
30+
),
31+
'text random': lambda m: hato.show_random_text,
32+
'text': lambda m: hato.show_random_text,
33+
'>< ': lambda m: partial(hato.totuzensi, message=m[len('>< '):]),
34+
'amesh': lambda m: partial(hato.amesh, place=m[len('amesh'):].strip()),
35+
'電力': lambda m: hato.electricity_demand,
36+
'標高': lambda m: partial(hato.altitude, place=m[len('標高'):].strip()),
37+
'version': lambda m: hato.version,
38+
'にゃーん': lambda m: hato.yoshiyoshi,
39+
'おみくじ': lambda m: hato.omikuji,
40+
}
3041

3142
for key, method in conditions.items():
3243
if message.startswith(key):

0 commit comments

Comments
 (0)