commit
2da71764f7
7 changed files with 295 additions and 5 deletions
28
README.md
28
README.md
|
@ -1,17 +1,36 @@
|
|||
# XZZ
|
||||
小智障,一个拓展 CoolQ HttpApi,快速构建命令式 QQ 机器人的框架.
|
||||
小智障,一个拓展 go-cqhttp ,快速构建命令式 QQ 机器人的框架.
|
||||
|
||||
## 如何使用
|
||||
|
||||
> 阅读完以下内容后可以参考我的 blog -> [部署一个自己的智障机器人](https://blog.sakuya.love/archives/xzz/)
|
||||
> 其中 go-cqhttp 配置文件部分格式可能有点过时,但是不影响理解🙈
|
||||
|
||||
### 安装配置
|
||||
|
||||
#### 0.自己安装配置好 CoolQ 及其 HttpApi 插件.
|
||||
#### 0.自己安装配置好 go-cqhttp.
|
||||
|
||||
包括上报过滤!
|
||||
`XZZ` 需要的配置有
|
||||
|
||||
- 相对应的上报地址与 `go-cqhttp` api 地址
|
||||
- 上报消息类型为 `array`
|
||||
- 上报消息过滤为以下条件
|
||||
|
||||
```json
|
||||
{
|
||||
"message_type": "group",
|
||||
"raw_message":{
|
||||
".regex":"^\/"
|
||||
},
|
||||
"user_id":{
|
||||
".neq": 80000000
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### 1.clone 本仓库, 填写 `config.py`
|
||||
|
||||
其中 `APIURL` 为 CoolQ HttpApi 的 URL, `AUTHORIZATION` 为 CoolQ HttpApi 的 `access_token`, `PORT` 和 CoolQ HttpApi `post_url` 中的端口保持一致.
|
||||
其中 `APIURL` 为 go-cqhttp 的 api 地址, `AUTHORIZATION` 为 go-cqhttp 的 `access_token`, `PORT` 和 go-cqhttp 反向 http post 设置的端口保持一致.
|
||||
|
||||
#### 2.安装依赖, 启动服务
|
||||
|
||||
|
@ -21,7 +40,6 @@ python main.py
|
|||
```
|
||||
|
||||
|
||||
|
||||
### 拓展功能
|
||||
|
||||
在 `worker` 文件夹中添加 python 模块.文件名即受该文件响应的命令.
|
||||
|
|
16
sample_config.py
Normal file
16
sample_config.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
from config import BINGKEY
|
||||
|
||||
|
||||
ALLWORKERS = ['ping','yiyan','mc',]
|
||||
|
||||
APIURL = 'http://127.0.0.1:5700/'
|
||||
|
||||
AUTHORIZATION = ''
|
||||
|
||||
HOST = '0.0.0.0'
|
||||
|
||||
PORT = 5580
|
||||
|
||||
REMOTE_MC_URL = ''
|
||||
|
||||
BINGKEY = ''
|
29
worker/hhsh.py
Normal file
29
worker/hhsh.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
from zzcore import StdAns, mysakuya
|
||||
import requests
|
||||
|
||||
class Ans(StdAns):
|
||||
def GETMSG(self):
|
||||
if len(self.parms) < 2:
|
||||
return '不加参数是坏文明!'
|
||||
|
||||
if mysakuya(self, self.raw_msg['raw_message']) == False:
|
||||
return "不许你们说咲夜!!"
|
||||
|
||||
msg = f"[CQ:reply,id={self.raw_msg['message_id']}]"
|
||||
r = nbnhhsh(self.parms[1])
|
||||
try:
|
||||
msg += f'''{(str(r['trans'])[1:-1]).replace("'","").replace(","," ")}'''
|
||||
except:
|
||||
msg += "没查到("
|
||||
|
||||
return msg
|
||||
|
||||
|
||||
def nbnhhsh(text):
|
||||
url = 'https://lab.magiconch.com/api/nbnhhsh/guess'
|
||||
data = {
|
||||
'text': text,
|
||||
}
|
||||
|
||||
r = requests.post(url=url, data=data).json()
|
||||
return r[0]
|
50
worker/lsp.py
Normal file
50
worker/lsp.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
from zzcore import StdAns, mysakuya
|
||||
import requests
|
||||
|
||||
from config import LOLIKEY
|
||||
|
||||
|
||||
class Ans(StdAns):
|
||||
AllowGroup = [959613860, 125733077]
|
||||
|
||||
def GETMSG(self):
|
||||
if self.parms[-1] == 'p':
|
||||
flash = ''
|
||||
self.parms = self.parms[0:-1]
|
||||
else:
|
||||
flash = ',type=flash'
|
||||
|
||||
if len(self.parms) == 1:
|
||||
code, picurl, pid = getsetu()
|
||||
else:
|
||||
keyword = self.parms[1]
|
||||
if mysakuya(self, keyword) == False:
|
||||
return "不许你们看咲夜的涩图!!"
|
||||
code, picurl, pid = getsetu(keyword)
|
||||
if code == 0:
|
||||
self.sendmsg(f'[CQ:reply,id={self.mid}]Pixiv ID:{pid}')
|
||||
return f'[CQ:image,file={picurl}{flash}]'
|
||||
else:
|
||||
return f'[CQ:reply,id={self.mid}] 什么东西出错了,code:{code}'
|
||||
|
||||
|
||||
def getsetu(keyword=''):
|
||||
url = 'https://api.lolicon.app/setu/'
|
||||
params = {
|
||||
'apikey': LOLIKEY,
|
||||
'keyword': keyword,
|
||||
}
|
||||
|
||||
try:
|
||||
resp = requests.get(url=url, params=params, timeout=5).json()
|
||||
except:
|
||||
return 500, '',0
|
||||
|
||||
|
||||
picurl = ''
|
||||
pid = 0
|
||||
if resp['code'] == 0:
|
||||
picurl = "https://r.zjuyk.site/" + resp['data'][0]['url']
|
||||
pid = resp['data'][0]['pid']
|
||||
|
||||
return resp['code'], picurl, pid
|
27
worker/mner.py
Normal file
27
worker/mner.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
import requests
|
||||
|
||||
from zzcore import StdAns
|
||||
|
||||
|
||||
class Ans(StdAns):
|
||||
def GETMSG(self):
|
||||
if len(self.parms) < 2:
|
||||
msg = '请输入包名 如:/mner yjun'
|
||||
return msg
|
||||
else:
|
||||
msg = ''
|
||||
req = requests.get(
|
||||
url='https://aur.archlinux.org/rpc/?v=5&type=search&by=maintainer&arg=' + self.parms[1]).json()
|
||||
count = req['resultcount']
|
||||
if count != 0:
|
||||
msg += '工具人 ' + self.parms[1] + ' 打包了' + str(count) + '个软件\n'
|
||||
soft=''
|
||||
if count < 5:
|
||||
# soft = list()
|
||||
for i in range(count):
|
||||
soft= req['results'][i]['Name']
|
||||
else:
|
||||
for i in range(5):
|
||||
soft+=req['results'][i]['Name']+'\n'
|
||||
soft+='....'
|
||||
return msg+soft
|
72
worker/pkg.py
Normal file
72
worker/pkg.py
Normal file
|
@ -0,0 +1,72 @@
|
|||
import requests
|
||||
import time
|
||||
from zzcore import StdAns
|
||||
|
||||
|
||||
class Ans(StdAns):
|
||||
# AllowGroup = [874769998,596678277,7343311]
|
||||
|
||||
def GETMSG(self):
|
||||
if len(self.parms) < 2:
|
||||
msg = '请输入包名 如:/pkg linux testing 查询 Testing 的 linux 软件'
|
||||
return msg
|
||||
elif self.parms[1] == 'help':
|
||||
msg = '使用 /pkg 包名 查询Core, Extra, Testing, Multilib, Multilib-Testing, ' \
|
||||
'Community, Community-Testing仓库以及AUR的软件 '
|
||||
return msg
|
||||
else:
|
||||
repo = str()
|
||||
try:
|
||||
if len(self.parms) > 1:
|
||||
repo = '&repo=' + self.parms[2].capitalize()
|
||||
except:
|
||||
print('repo empty')
|
||||
|
||||
def timeTrans(value):
|
||||
temp = time.localtime(int(value))
|
||||
timeValue = time.strftime("%Y-%m-%d %H:%M:%S", temp)
|
||||
return timeValue[:16]
|
||||
|
||||
req = requests.get(
|
||||
url='https://archlinux.org/packages/search/json/?name=' + self.parms[1] + repo).json()
|
||||
if not req['results']:
|
||||
req = requests.get(
|
||||
url='https://aur.tuna.tsinghua.edu.cn/rpc/?v=5&type=info&arg=' + self.parms[1]).json()
|
||||
if req['resultcount'] == 0:
|
||||
req = requests.get(
|
||||
url='https://aur.tuna.tsinghua.edu.cn/rpc/?v=5&type=search&arg=' + self.parms[1]).json()
|
||||
# print(req)
|
||||
if req['resultcount'] > 0:
|
||||
name = '包名:' + req['results'][0]['Name']
|
||||
# pkgname = req['results'][0]['pkgname']
|
||||
version = '版本:' + req['results'][0]['Version']
|
||||
description = '描述:' + req['results'][0]['Description']
|
||||
maintainer = '维护:' + str(req['results'][0]['Maintainer'])
|
||||
numvotes = '投票:' + str(req['results'][0]['NumVotes'])
|
||||
updatetime = '更新日期:' + timeTrans(req['results'][0]['LastModified'])
|
||||
outofdate = req['results'][0]['OutOfDate']
|
||||
if outofdate is not None:
|
||||
outofdate=timeTrans(outofdate)
|
||||
updatetime = updatetime + '\n过期日期:' + outofdate
|
||||
url = req['results'][0]['URL']
|
||||
if url is None:
|
||||
url = '链接:None'
|
||||
else:
|
||||
url = '链接:' + url
|
||||
msg = '仓库:AUR\n' + name + '\n' + version + '\n' + description + '\n' + maintainer \
|
||||
+ '\n' + numvotes + '\n' + updatetime + '\n' + url
|
||||
return msg
|
||||
else:
|
||||
repo = req['results'][0]['repo']
|
||||
pkgname = req['results'][0]['pkgname']
|
||||
pkgver = req['results'][0]['pkgver'] + '\n'
|
||||
pkgdesc = req['results'][0]['pkgdesc']
|
||||
url = req['results'][0]['url']
|
||||
updatetime = req['results'][0]['last_update']
|
||||
updatetime = updatetime.replace('T', ' ')
|
||||
updatetime = updatetime[0:16] + '\n'
|
||||
# return repo,pkgname,pkgver,pkgdesc,url
|
||||
# print('仓库:' + repo + '\n包名:' + pkgname + '\n版本:' + pkgver + '\n描述:' + pkgdesc + '\n上游:' + url + '\n')
|
||||
msg = '仓库:' + repo + '\n包名:' + pkgname + '\n版本:' + pkgver + '描述:' + pkgdesc + '\n更新日期:' \
|
||||
+ updatetime + '上游:' + url
|
||||
return msg
|
78
worker/zhaoan.py
Normal file
78
worker/zhaoan.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
from zzcore import StdAns
|
||||
import requests
|
||||
import sxtwl
|
||||
from datetime import datetime
|
||||
from config import HFWEATHERKEY
|
||||
|
||||
|
||||
class Ans(StdAns):
|
||||
def GETMSG(self):
|
||||
msg = f'早上好,今天是{calendar()}\n\n'
|
||||
msg += getWeather() + '\n\n'
|
||||
# t = requests.get('https://v1.hitokoto.cn/?c=k&encode=text').text
|
||||
t =("只要不失去你的崇高,整个世界都会向你敞开")
|
||||
msg += t
|
||||
return msg
|
||||
|
||||
|
||||
def getWeather(id='101120206'):
|
||||
def wemoji(text):
|
||||
if '雪' in text:
|
||||
return text + '🌨'
|
||||
if '雨' in text:
|
||||
return text + '🌧️'
|
||||
if '阴' in text:
|
||||
return text + '⛅'
|
||||
if '云' in text:
|
||||
return text + '🌤'
|
||||
if '晴' in text:
|
||||
return text + '☀️'
|
||||
return text
|
||||
|
||||
url = 'https://devapi.heweather.net/v7/weather/3d'
|
||||
params = {
|
||||
'location': id,
|
||||
'key': HFWEATHERKEY,
|
||||
}
|
||||
r = requests.get(url=url, params=params).json()
|
||||
tdw = r['daily'][0]
|
||||
# ndw = r['daily'][1]
|
||||
# weather = f"今日日间{wemoji(tdw['textDay'])},温度{tdw['tempMin']}~{tdw['tempMax']}℃,{tdw['windDirDay']}{tdw['windScaleDay']}级;夜间{wemoji(tdw['textNight'])},{tdw['windDirNight']}{tdw['windScaleNight']}级。明日日间{wemoji(ndw['textDay'])},温度{ndw['tempMin']}~{ndw['tempMax']}℃。"
|
||||
weather = f"今日日间{wemoji(tdw['textDay'])},温度{tdw['tempMin']}~{tdw['tempMax']}℃,{tdw['windDirDay']}{tdw['windScaleDay']}级;夜间{wemoji(tdw['textNight'])},{tdw['windDirNight']}{tdw['windScaleNight']}级。"
|
||||
if float(tdw['precip']) > 0:
|
||||
weather += '\n记得收好衣服,出门带伞~'
|
||||
|
||||
return weather
|
||||
|
||||
|
||||
def calendar():
|
||||
|
||||
# 可选 教学、寒假、暑假 等
|
||||
NowStatus = "暑假"
|
||||
# 开始周次是今年的第几周
|
||||
StartWeek = 28
|
||||
# 今年考研开始日期
|
||||
KaoYanDate = datetime(2021, 12, 25)
|
||||
|
||||
ymc = ["冬", "腊", "正", "二", "三", "四", "五", "六", "七", "八", "九", "十"]
|
||||
rmc = ["初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五",
|
||||
"十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十", "卅一"]
|
||||
zmc = ["一", "二", "三", "四", "五", "六", "天"]
|
||||
nowdate = datetime.now()
|
||||
djs = (KaoYanDate - nowdate).days -1
|
||||
y = nowdate.year
|
||||
m = nowdate.month
|
||||
d = nowdate.day
|
||||
zc = int(nowdate.strftime("%W")) - StartWeek
|
||||
|
||||
z = zmc[nowdate.weekday()]
|
||||
|
||||
lunar = sxtwl.Lunar()
|
||||
lunarday = lunar.getDayBySolar(y, m, d)
|
||||
|
||||
lunardaychinese = f"{ymc[lunarday.Lmc]}月{rmc[lunarday.Ldi]}"
|
||||
if lunarday.Lleap:
|
||||
lunardaychinese = "闰" + lunardaychinese
|
||||
|
||||
cal = f"{m}月{d}日,{lunardaychinese},{NowStatus}第{zc}周,星期{z}\n\n距离 2022 考研还有 {djs} 天"
|
||||
return cal
|
Loading…
Reference in a new issue