Add tigerbot
This commit is contained in:
@@ -15,16 +15,18 @@ class TigerBot():
|
||||
self.tbmodel = tbconf["model"]
|
||||
self.fallback = ["滚", "快滚", "赶紧滚"]
|
||||
|
||||
def answer(self, msg: str, sender: str = None) -> str:
|
||||
def get_answer(self, msg: str, sender: str = None) -> str:
|
||||
payload = {
|
||||
"text": msg,
|
||||
"modelVersion": self.tbmodel
|
||||
}
|
||||
rsp = ""
|
||||
try:
|
||||
rsp = requests.post(self.tburl, headers=self.tbheaders, json=payload).json()["data"]["result"][0]
|
||||
rsp = requests.post(self.tburl, headers=self.tbheaders, json=payload).json()
|
||||
rsp = rsp["data"]["result"][0]
|
||||
except Exception as e:
|
||||
self.LOG.error(f"{e}")
|
||||
idx = randint(0, len(self.fallback))
|
||||
self.LOG.error(f"{e}: {payload}\n{rsp}")
|
||||
idx = randint(0, len(self.fallback) - 1)
|
||||
rsp = self.fallback[idx]
|
||||
|
||||
return rsp
|
||||
@@ -34,5 +36,5 @@ if __name__ == "__main__":
|
||||
from configuration import Config
|
||||
c = Config()
|
||||
tbot = TigerBot(c.TIGERBOT)
|
||||
rsp = tbot.answer("你还活着?")
|
||||
rsp = tbot.get_answer("你还活着?")
|
||||
print(rsp)
|
||||
|
||||
13
robot.py
13
robot.py
@@ -11,6 +11,7 @@ from configuration import Config
|
||||
from func_chatgpt import ChatGPT
|
||||
from func_chengyu import cy
|
||||
from func_news import News
|
||||
from func_tigerbot import TigerBot
|
||||
from job_mgmt import Job
|
||||
|
||||
|
||||
@@ -24,10 +25,14 @@ class Robot(Job):
|
||||
self.LOG = logging.getLogger("Robot")
|
||||
self.wxid = self.wcf.get_self_wxid()
|
||||
self.allContacts = self.getAllContacts()
|
||||
self.chat = None
|
||||
chatgpt = self.config.CHATGPT
|
||||
if chatgpt:
|
||||
self.chat = ChatGPT(chatgpt.get("key"), chatgpt.get("api"), chatgpt.get("proxy"), chatgpt.get("prompt"))
|
||||
|
||||
if self.config.TIGERBOT:
|
||||
self.chat = TigerBot(self.config.TIGERBOT)
|
||||
elif self.config.CHATGPT:
|
||||
cgpt = self.config.CHATGPT
|
||||
self.chat = ChatGPT(cgpt.get("key"), cgpt.get("api"), cgpt.get("proxy"), cgpt.get("prompt"))
|
||||
else:
|
||||
self.chat = None
|
||||
|
||||
def toAt(self, msg: WxMsg) -> bool:
|
||||
"""处理被 @ 消息
|
||||
|
||||
Reference in New Issue
Block a user