-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
116 lines (91 loc) · 3.24 KB
/
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
import base64
import os
import requests
from EAbotoy import Botoy, jconfig, Action, sugar, MsgTypes
from EAbotoy.model import WeChatMsg, EventMsg
from EAbotoy import decorators
from EAbotoy.schedule import scheduler
from plugins.bot_reply import is_bot_master
wxid = jconfig.wxid
os.environ["wxid"] = str(wxid)
os.environ["env"] = str(jconfig.env)
bot = Botoy(wxid=wxid, use_plugins=True)
action = Action(wxid, host=jconfig.host, port=jconfig.port, is_use_queue=True)
@bot.wx_context_use
def wx_mid_add_master(ctx):
ctx.master = jconfig.master
return ctx
@bot.on_wx_msg
@decorators.these_msgtypes(MsgTypes.TextMsg)
def admin_manage(ctx: WeChatMsg):
if ctx.ActionUserName != jconfig.master:
return
if 'add admin' in ctx.Content and ctx.isAtMsg:
res = '上面用户成功添加为admin'
user_ls = ctx.atUserIds
if user_ls is None or len(user_ls) == 0:
return
for _qq in user_ls:
if is_bot_master(ctx.CurrentWxid, _qq):
continue
from plugins.bot_reply import DB
sql = DB()
sql.add_bot_admin(_qq, ctx.CurrentWxid)
sugar.Text(res)
@bot.on_wx_msg
@decorators.these_msgtypes(MsgTypes.TextMsg)
def plugin_manage(ctx: WeChatMsg):
if ctx.ActionUserName != jconfig.master:
return
if ctx.Content == '刷新插件':
bot.plugMgr.reload_plugins()
sugar.Text("~~所有插件刷新完毕")
@bot.on_wx_msg
@decorators.these_msgtypes(MsgTypes.TextMsg)
@decorators.on_regexp(r'^[.。]')
def help(ctx: WeChatMsg):
args = ctx.Content.split(" ")
if args[0].lower() in ['.h', '.help', '。h', '。help']:
plugins = bot.plugMgr.enabled_plugins
end = '\n'
if len(args) == 1:
sugar.Text(f"输入.help 【插件名】 来查看具体插件说明\n"
f"~~~~~~~~~~~~~~\n"
f"{end.join([i[1] for i in plugins])}")
else:
for plugin in plugins:
if args[1] == plugin[1] and plugin[2] != '':
sugar.Text(f"{plugin[1]}的说明:\n"
f"~~~~~~~~~~~~~~\n"
f"{plugin[2]}")
return
sugar.Text(f"没找到这种插件")
@bot.on_event
def event_log(ctx: EventMsg):
pass
@bot.on_wx_msg
@decorators.these_msgtypes(MsgTypes.TextMsg)
def daily_message(ctx: WeChatMsg):
if ctx.Content == '每日新闻':
daily(ctx.FromUserName)
def notice(switch):
if switch == 1:
action.sendWxText(
toUserName="25373433877@chatroom",
content="半夜一点啦,早睡早起哦。"
)
else:
action.sendWxText(
toUserName="25373433877@chatroom",
content="起床了,记得好好学习。"
)
def daily(group: str = '18728854191@chatroom'):
res = requests.get("https://api.03c3.cn/zb/")
base = str(base64.b64encode(res.content), encoding="utf-8")
action.sendImg(toUserName=group,
imageBase64=base)
scheduler.add_job(notice, "cron", hour=0, minute=59, args=(1,))
scheduler.add_job(notice, "cron", hour=7, minute=20, args=(0,))
scheduler.add_job(daily, "cron", hour=8, minute=00)
if __name__ == "__main__":
bot.run()