-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommands.py
More file actions
executable file
·143 lines (129 loc) · 5.13 KB
/
commands.py
File metadata and controls
executable file
·143 lines (129 loc) · 5.13 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import datetime
import time
import message_xml
import logging
import crawler
import searchData
def deal_time(words, article):
"""
deal with time in the WeChat User send time command.
:param words: WeChat User send content split by space.
:param article: template WeChat receive object
:return: function do correct/fail
"""
# 消息格式为text
article.MsgType("text")
# 使用time库获取时间
article.append_Description("Content", time.strftime('(ノ´ヮ´)ノ*:・゚✧\n现在的时间是 %Y.%m.%d %H:%M:%S 哦\n(๑^ں^๑)', time.localtime(time.time())))
return True
def deal_sticker(words, article):
"""
deal with sticker in the WeChat User command.
:param words: WeChat User send content split by space.
:param article: template WeChat receive object
:return: function do correct/fail
"""
if len(words) != 2:
# 表示微信返回内容为text格式
article.MsgType("text")
# 添加内容
article.append_Description("Content", "关键词太多了啦")
return True
else:
# 获得图片的Bytes,并进行处理
# WeChat限制, 一次最多只有一张图片能够显示, 故设置过多的图片没有意义
logging.debug(f"[crawlerStartGet]:{time.time()}")
pic_contents = crawler.get_pix_by_key(words[1])
logging.debug(f"[crawlerFinishGet]:{time.time()}")
if pic_contents is None:
logging.debug(f"[crawlerGet pic]:not get")
# 表示微信返回内容为text格式
article.MsgType("text")
# 添加内容
article.append_Description("Content", "没有获取到表情包QAQ")
return True
logging.debug(f"[crawlerGet pic len]:{len(pic_contents)}")
pic_dicList = []
# 获取图片的id
for pic_content in pic_contents:
# 将图片发送给WeChat, 返回一个微信服务器上对应图片的id
picID = article.send_WXpic(pic_content)
# 将其追加到list中
if picID != "":
pic_dicList.append({"MediaId":picID})
if not pic_dicList:
# 表示微信返回内容为text格式
article.MsgType("text")
# 添加内容
article.append_Description("Content", "没有获取到表情包QAQ")
return True
# 表示微信返回内容为image格式
article.MsgType("image")
# 添加内容
article.append_Description("Image",pic_dicList)
return True
def deal_todo(words, article):
"""
you can add you want to do in the WeChat(NotRealized).
:param words: WeChat User send content split by space.
:param article: template WeChat receive object
:return: function do correct/fail
"""
return True
# 功能暂未调试完成
# lark.send_message(access_token, event.get("open_id"), "
#
# else:
# h_m = words[1].split(':', 2)
#
# inc_time = datetime.time(int(h_m[0]), int(h_m[1]), 00)
#
# cur = datetime.datetime.now()
# left_s = inc_time.hour * 60 * 60 + inc_time.minute * 60 - cur.hour * 60 * 60 - cur.minute * 60 - cur.second
# if left_s < 0:
# lark.send_message(access_token, event.get("open_id"), "时间已经过了吧, 你再仔细检查检查")
# else:
# s = time.strftime('%Y.%m.%d %H:%M:%S ', time.localtime(time.time()))
# lark.send_message(access_token, event.get("open_id"),
# "current time is: {}\n{} second(s) left".format(s, left_s))
# logging.debug("[commands.deal_todo] current time is: " + s, "%d second(s) left" % left_s)
# pass
def deal_search_tiku(words, article):
"""
from TiKu.docx search most similar answer.
:param words: WeChat User send content split by space.
:param article: template WeChat receive object
:return: function do correct/fail
"""
# 消息返回类型为text
article.MsgType("text")
# 如果用户没有发送题目,则返回false,执行图灵机器人的消息
if len(words) < 2:
return False
else:
# 将split用户的消息,再次集合起来
question = "".join(words[1:])
# question = question.replace(' ', '')
# 添加内容
Ans = searchData.search(question)
article.append_Description("Content", Ans)
return True
def process_input_info(words: list, article):
"""
find correct command from User send message.
:param words: WeChat User send content split by space.
:param article: template WeChat receive object
:return: function do correct/fail
"""
# 判断开头关键字
if words[0] == "time":
return deal_time(words, article)
elif words[0] == 'bq':
return deal_sticker(words, article)
elif words[0] == 'st':
return deal_search_tiku(words, article)
elif words[0] == '/todo':
# deal_todo(words, article)
return False
else:
return False