forked from PumpkinDemo/mini-happy-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
74 lines (54 loc) · 1.87 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
import nonebot
from nonebot import on_command, CommandSession
from nonebot import on_natural_language, NLPSession, IntentCommand
import config
import os
from plugins.saying import has_saying
# config = Config()
HOST = '127.0.0.1'
PORT = 5000
def get_file_contents(file):
if not os.path.exists(file):
os.system(f'touch {file}')
with open(file, 'r') as f:
content = f.read()
return content
@on_command('help', only_to_me=False)
async def help(session:CommandSession):
await session.send('no help~ :)')
@on_command('about', only_to_me=False)
async def about(session:CommandSession):
msg = get_file_contents('./txts/about.txt')
await session.send(msg)
@on_command('changelog', only_to_me=False)
async def changelog(session:CommandSession):
msg = get_file_contents('./txts/changelog.txt')
await session.send(msg)
@on_command('usage', only_to_me=False)
async def usage(session:CommandSession):
msg = get_file_contents('./txts/usage.txt')
await session.send(msg)
@on_command('sese', only_to_me=False)
async def sese(session:CommandSession):
await session.send('不可以色色~')
@on_natural_language(keywords={'来点'}, only_to_me=False)
async def some(session:NLPSession):
msg = session.msg_text.strip()
if not msg.startswith('来点'):
return
key = msg.split('来点')[1]
if not key:
return
if key in ['涩图']:
return IntentCommand(80.0, 'setu')
if key in ['语录']:
return IntentCommand(80.0, 'saying')
if has_saying(key):
return IntentCommand(80.0, 'sayingof', current_arg=key)
await session.send(f'unrecognized keyword: {key}')
if __name__ == '__main__':
nonebot.init(config_object=config)
# nonebot.load_builtin_plugins()
nonebot.load_plugin('plugins.saying')
nonebot.load_plugin('plugins.setu')
nonebot.run(host=HOST, port=PORT)