forked from benx1n/wows-stats-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_select.py
62 lines (54 loc) · 2.64 KB
/
command_select.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from dataclasses import dataclass
from email.policy import default
from typing import List, Tuple,Protocol
from .publicAPI import get_nation_list,get_ship_name,get_ship_byName
from .wws_info import get_AccountInfo
from .wws_recent import get_RecentInfo
from .wws_bind import set_BindInfo,get_BindInfo,change_BindInfo,set_special_BindInfo,delete_BindInfo
from .wws_ship import get_ShipInfo,get_ShipInfoRecent,ShipSecletProcess
from .wws_clan import get_ClanInfo,ClanSecletProcess
from .wws_record import get_record
from .wws_shiprank import get_ShipRank
from .utils import match_keywords,bytes2b64
class Func(Protocol):
async def __call__(self, **kwargs):
...
@dataclass
class command:
keywords: Tuple[str, ...]
func: Func
default_func: Func = None
first_command_list = [ #同指令中越长的匹配词越靠前
command(("切换绑定","更换绑定","更改绑定"),change_BindInfo),
command(("查询绑定","绑定查询","绑定列表","查绑定"),get_BindInfo),
command(("删除绑定",),delete_BindInfo),
command(("特殊绑定",),set_special_BindInfo),
command(("ship.rank","rank"),get_ShipRank),
command(("bind","绑定","set"),set_BindInfo),
command(("recent","近期",),None,get_RecentInfo),
command(("ship","单船",),None,get_ShipInfo),
command(("record","历史记录"),None,get_record),
command(("clan","军团","公会","工会"),None,get_ClanInfo),
command(("搜船名","查船名","船名"),get_ship_name),
]
second_command_list = [
command(("recent","近期",),get_ShipInfoRecent),
command(("ship","单船",),get_ShipInfoRecent),
command(("clan","军团","公会","工会"),get_record),
command(("record","历史记录"),get_record),
]
async def findFunction_and_replaceKeywords(match_list,command_List,default_func):
for com in command_List :
for kw in com.keywords:
for i,match_kw in enumerate(match_list):
if (match_kw.find(kw)+1):
match_list[i] = str(match_kw).replace(kw,"")
if match_list[i] == '': #为空时才删除,防止未加空格没有被split切割
match_list.remove('')
return com,match_list
return command(None,default_func,None),match_list
async def select_command(search_list):
command,search_list = await findFunction_and_replaceKeywords(search_list,first_command_list,get_AccountInfo)
if command.func == None:
command,search_list = await findFunction_and_replaceKeywords(search_list,second_command_list,command.default_func)
return command.func,search_list