|
9 | 9 | from enum import Enum, auto |
10 | 10 | from logging import getLogger |
11 | 11 | from tempfile import NamedTemporaryFile |
12 | | -from typing import List, Callable, Union |
| 12 | +from typing import List, Callable, Union, Any |
13 | 13 | import requests |
14 | 14 | from git import Repo |
15 | 15 | from git.exc import InvalidGitRepositoryError, GitCommandNotFound |
|
18 | 18 |
|
19 | 19 | import slackbot_settings as conf |
20 | 20 | from library.vocabularydb \ |
21 | | - import get_vocabularys, add_vocabulary, show_vocabulary, delete_vocabulary, show_random_vocabulary |
| 21 | + import get_vocabularys, add_vocabulary, show_vocabulary, \ |
| 22 | + delete_vocabulary, show_random_vocabulary |
22 | 23 | from library.earthquake import generate_quake_info_for_slack, get_quake_list |
23 | 24 | from library.hukidasi import generator |
24 | 25 | from library.geo import get_geo_data |
25 | 26 | from library.hatokaraage import hato_ha_karaage |
26 | 27 | from library.clientclass import BaseClient |
27 | 28 | from library.jma_amesh import jma_amesh |
28 | 29 | from library.omikuji import OmikujiResult, OmikujiResults, draw as omikuji_draw |
29 | | -logger = getLogger(__name__) |
30 | 30 |
|
| 31 | +from mypy_extensions import VarArg |
| 32 | + |
| 33 | +logger = getLogger(__name__) |
31 | 34 |
|
32 | | -def action(plugin_name: str, with_client: bool = False) -> Callable[[BaseClient, ...], None]: |
| 35 | +def action(plugin_name: str, with_client: bool = False): |
33 | 36 | """ |
34 | 37 | アクション定義メソッドに使うデコレータ |
| 38 | +
|
35 | 39 | """ |
36 | 40 |
|
37 | | - def _action(func: Callable[[BaseClient, ...], Union[str, None]]): |
| 41 | + def _action(func: Callable[[BaseClient, VarArg(Any)], Union[str, None]]): |
38 | 42 | def wrapper(client: BaseClient, *args, **kwargs): |
39 | 43 | logger.debug("%s called '%s'", client.get_send_user(), plugin_name) |
40 | 44 | logger.debug("%s app called '%s'", client.get_type(), plugin_name) |
41 | 45 | if with_client: |
42 | 46 | func(client, *args, **kwargs) |
43 | 47 | else: |
44 | | - client.post(func(*args, **kwargs)) |
| 48 | + return_val = func(*args, **kwargs) |
| 49 | + if isinstance(return_val, str): |
| 50 | + client.post(return_val) |
45 | 51 |
|
46 | 52 | return wrapper |
47 | 53 | return _action |
@@ -236,8 +242,7 @@ def altitude(place: str): |
236 | 242 | try: |
237 | 243 | coordinates = [str(float(p)) for p in reversed(place_list)] |
238 | 244 | except ValueError: |
239 | | - client.post('引数が正しくないっぽ......') |
240 | | - return None |
| 245 | + return '引数が正しくないっぽ......' |
241 | 246 |
|
242 | 247 | place_name = ', '.join(reversed(coordinates)) |
243 | 248 | else: |
|
0 commit comments