forked from XDzzzzzZyq/Guluton_test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot_modules.py
52 lines (41 loc) · 1.62 KB
/
bot_modules.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
from json import dumps as jsonify, loads as from_json
from v2 import MessageHandler
from cqhttp_api import *
from RecvContext import RecvContext
from predicates import *
from common import *
from typing import Tuple
class KeywordsBot(MessageHandler):
def __init__(self) -> None:
super().__init__()
self.last_response = unixtime()
self.priority = 0
def __eq__(self, context: RecvContext) -> Tuple[bool, bool]:
if unixtime()- self.last_response<1000:
return False,False
print(str(context))
return isGroupMessage(context) and isBeingAt(context)
def __call__(self,context:RecvContext):
config = from_json(fread("./keywords.json"))
templates = config["templates"]
for template in templates:
keywords,response = template["keywords"],template["response"]
for keyword in keywords:
if keyword in context.raw_message:
self.last_response = unixtime()
api_send_group_msg(context.group_id,response)
return True
api_send_group_msg(context.group_id,config["catch-all"])
return True
def __str__(self) -> str:
return "KeywordsBot"
class DiceBot(KeywordsBot):
def __init__(self) -> None:
super().__init__()
self.priority = 1
def __call__(self, context: RecvContext) -> bool:
return
def __eq__(self, context: RecvContext) -> Tuple[bool, bool]:
return super().__call__(context) and "random" in context.raw_message
def __str__(self) -> str:
return "DiceBot"