-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWechat_Bot.py
167 lines (135 loc) · 6 KB
/
Wechat_Bot.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
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import sys
import time
import ntchat
from os.path import join
from json import load, dump
from time import time, localtime, sleep
from os import system, getcwd
from re import sub
from BuildArchives import new_archive
from Fortuneslip import fortune, slip
from Sign import sign
from Setu import random_setu, time_convert
from Fish import fish
from meitu import erciyuan
from Joke import joke
from love import love
from love import bixin
import random
# 创建微信
wechat = ntchat.WeChat()
# 打开pc微信, smart: 是否管理已经登录的微信
wechat.open(smart=True)
# 等待登录
wechat.wait_login()
# 色图冷却计时器,防止有老六访问量过大
setu_time = 0
# 贤者时间语句计时器
xianzhe_time = 0
lastmoyu=0
moyutime=0
# 读取群友信息
with open("name_dict.json", mode="r", encoding="utf-8") as f:
name_dict = load(f)
with open("info.json", mode="r", encoding="utf-8") as f:
origin = load(f)
# 提醒群友bot已经启动
# wechat.send_text(to_wxid="23278031443@chatroom", content="bot已启动,已更新钓鱼! ᕕ( ᐛ )ᕗ")
@wechat.msg_register(ntchat.MT_RECV_TEXT_MSG)
def bot(wechat_instance: ntchat.WeChat, message):
global setu_time
global name_dict
global origin
global name_dict
global moyutime
global lastmoyu
data = message["data"]
msg = data["msg"]
room_wxid = data["room_wxid"]
# 判断是否是SnapHack群消息
if room_wxid == "23278031443@chatroom":
from_wxid = data["from_wxid"]
# 判断是否已经建档
if from_wxid not in origin.keys():
new_archive(from_wxid)
with open("info.json", mode="r", encoding="utf-8") as f:
origin = load(f)
with open("name_dict.json", mode="r", encoding="utf-8") as f:
name_dict = load(f)
# 签到
if msg == "/sign":
wechat_instance.send_room_at_msg(to_wxid="23278031443@chatroom",
content=sign(from_wxid), at_list=[from_wxid])
# 今日人品
if msg == "/fortune":
if slip(from_wxid):
slippath = [join(getcwd(), "slip.gif").replace("\\", "/")]
wechat_instance.send_gif(to_wxid="23278031443@chatroom", file=slippath[0])
sleep(2)
wechat_instance.send_room_at_msg(to_wxid="23278031443@chatroom",
content=fortune(from_wxid), at_list=[from_wxid])
if msg == "/time":
timetu=[join(getcwd(), f"time\\{localtime()[3]}.gif").replace("\\", "/")]
wechat.send_gif(to_wxid="23278031443@chatroom", file=timetu[0])
# 钓鱼
if msg == "/fish":
wechat_instance.send_room_at_msg(to_wxid="23278031443@chatroom",
content=fish(from_wxid), at_list=[from_wxid])
if msg == "/flip_coin":
if random.randint(0,1)==1:
wechat.send_gif(to_wxid="23278031443@chatroom", file=r"C:\WeChatBot\1.gif")
else:
wechat.send_gif(to_wxid="23278031443@chatroom", file=r"C:\WeChatBot\hua.gif")
# 地狱笑话
if msg == "/joke":
wechat_instance.send_room_at_msg(to_wxid="23278031443@chatroom", content=joke(from_wxid), at_list=[from_wxid])
if msg=="/test":
wechat_instance.send_video(to_wxid="23278031443@chatroom",file_path=r"C:\WeChatBot\test.mp3")
if msg=="/rick_roll":
wechat_instance.send_video(to_wxid="23278031443@chatroom", file_path=r"C:\WeChatBot\rickroll.mp4")
# 跑团
elif msg[:5] == "/roll":
msg = sub(r'[\\\"\<\>\|\']', "/", msg)
print(f"python Command.py {msg}")
system(f"python Command.py {msg}")
with open("temp.json", mode="r", encoding="utf-8") as doc:
wechat_instance.send_room_at_msg(to_wxid="23278031443@chatroom",
content=f"@{name_dict[from_wxid]} {load(doc)['text']} ᕕ( ᐛ )ᕗ",
at_list=[from_wxid])
elif msg[:5] == "/chag":
msg = sub(r'[\\\"\<\>\|\']', "/", msg)
with open("temp.json", mode="w") as doc:
dump({"wxid": f"{from_wxid}"}, doc, indent=4)
print(f"python Command.py {msg}")
system(f"python Command.py {msg}")
# 瑟瑟
elif msg[:5] == "/setu":
if time() - int(origin['last_setu']) >= 7200:
msg = sub(r'[\/\\\"\<\>\|\_\%\;\']', "/", msg[5:])
system(f"python Command.py {msg}")
data = random_setu()
wechat_instance.send_text(to_wxid="23278031443@chatroom", content="啊哈哈哈!色图来喽!ᕕ( ᐛ )ᕗ")
for img in data:
print(img)
wechat_instance.send_image(to_wxid="23278031443@chatroom", file_path=img)
origin['last_setu'] = time()
with open("info.json", mode="w") as doc:
dump(origin, doc, indent=4)
else:
wechat_instance.send_text(to_wxid="23278031443@chatroom",
content=f"贤者时间还有{time_convert(7200 - time() + int(origin['last_setu']))},"
f"先休息一下啦(`Д´)")
elif from_wxid=="wxid_ssyd5nc3hbcp12" and msg[:1] == "/":
wechat_instance.send_text(to_wxid="23278031443@chatroom", content=msg)
#love
elif msg[:5] == "/love":
love(wechat_instance, message)
elif room_wxid == "23278031443@chatroom" and "@周子勋\u2005" in msg:
if msg == "@周子勋\u2005笔芯":
bixin(wechat_instance, message)
try:
while True:
sleep(1)
except KeyboardInterrupt:
ntchat.exit_()
sys.exit()