forked from kyubotics/python-cqhttp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
36 lines (27 loc) · 1.16 KB
/
demo.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
from cqhttp import CQHttp, Error
bot = CQHttp(api_root='http://127.0.0.1:5700/',
access_token='123',
secret='abc')
@bot.on_message()
def handle_msg(context):
# 下面这句等价于 bot.send_private_msg(user_id=context['user_id'], message='你好呀,下面一条是你刚刚发的:')
try:
bot.send(context, '你好呀,下面一条是你刚刚发的:')
except Error:
pass
return {'reply': context['message'],
'at_sender': False} # 返回给 HTTP API 插件,走快速回复途径
@bot.on_event('group_increase')
def handle_group_increase(context):
info = bot.get_group_member_info(group_id=context['group_id'],
user_id=context['user_id'])
nickname = info['nickname']
name = nickname if nickname else '新人'
bot.send(context, message='欢迎{}~'.format(name))
@bot.on_request('group')
def handle_group_request(context):
if context['message'] != 'some-secret':
# 验证信息不符,拒绝
return {'approve': False, 'reason': '你填写的验证信息有误'}
return {'approve': True}
bot.run(host='127.0.0.1', port=8080)