58 lines
1.7 KiB
Python
58 lines
1.7 KiB
Python
import botpy
|
|
from botpy.message import Message
|
|
from dotenv import load_dotenv
|
|
import os
|
|
import types
|
|
from bobby import bobbySession
|
|
#环境配置
|
|
|
|
class djtuWebsocket (botpy.Client) :
|
|
async def on_group_at_message_create(self, message: Message):
|
|
|
|
await self.parseCommand(message)
|
|
|
|
async def on_group_message_create(self,message:Message):
|
|
|
|
await self.parseGlobalMessage(message)
|
|
|
|
|
|
async def parseCommand(self,msg :Message):
|
|
commands:dict[str,types.MethodType|types.FunctionType] = {
|
|
r'/邀请码' : bobby.getInviteCode,
|
|
r'吃什么' : lambda :"是啊吃什么"
|
|
}
|
|
required = msg.content
|
|
reply = ""
|
|
for cmd,func in commands.items():
|
|
if required.find(cmd) != -1:
|
|
try:
|
|
reply = func()
|
|
except:
|
|
reply = "服务异常"
|
|
break
|
|
if reply.__len__() == 0:
|
|
reply = "你在发什么东西我怎么看不懂?"
|
|
await msg.reply(content=reply)
|
|
|
|
async def parseGlobalMessage(self,msg:Message):
|
|
await msg.reply(content="awda")
|
|
# source
|
|
load_dotenv(".env")
|
|
print(os.getenv("APP_ID"))
|
|
|
|
|
|
bbyAccount = os.getenv("BOBBY_ACCOUNT")
|
|
bbyPasswd = os.getenv("BOBBY_PASSWORD")
|
|
appid = os.getenv("APP_ID")
|
|
secret_bot = os.getenv("SECRET")
|
|
|
|
# bobby Session
|
|
if bbyAccount is None or bbyPasswd is None :
|
|
raise SystemError("未找到账密配置")
|
|
if appid is None or secret_bot is None :
|
|
raise SystemError("未找到bot配置")
|
|
bobby = bobbySession(bbyAccount,bbyPasswd)
|
|
|
|
#bot 启动
|
|
ws = djtuWebsocket(botpy.Intents(public_messages=True))
|
|
ws.run(appid=appid,secret=secret_bot) |