Merge pull request #11 from Si-Huan/master

update to Sihuan
This commit is contained in:
Weilin Cai 2021-01-19 15:06:05 +08:00 committed by GitHub
commit d61559dfed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 276 additions and 53 deletions

3
data/mc/rmc/go.mod Normal file
View file

@ -0,0 +1,3 @@
module rmc
go 1.15

64
data/mc/rmc/main.go Normal file
View file

@ -0,0 +1,64 @@
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"net/http"
"os/exec"
)
func checkErr(err error) {
if err != nil {
fmt.Println(err)
}
}
func handleStatus(writer http.ResponseWriter, request *http.Request) {
cmd := exec.Command("papermc", "status")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
fmt.Fprintf(writer, "Error")
return
}
fmt.Fprintf(writer, out.String())
}
func handleList(writer http.ResponseWriter, request *http.Request) {
cmd := exec.Command("papermc", "command", "list")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
fmt.Fprintf(writer, "Error")
return
}
fmt.Fprintf(writer, out.String())
}
func handleSay(writer http.ResponseWriter, request *http.Request) {
saywhat, _ := ioutil.ReadAll(request.Body)
cmd := exec.Command("papermc", "command", "say", string(saywhat))
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
fmt.Fprintf(writer, "Error")
return
}
fmt.Fprintf(writer, "0")
}
func main() {
http.HandleFunc("/status", handleStatus)
http.HandleFunc("/list", handleList)
http.HandleFunc("/say", handleSay)
fmt.Println("Running at port 58941 ...")
err := http.ListenAndServe("172.26.66.2:58941", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err.Error())
}
}

View file

@ -7,3 +7,5 @@ AUTHORIZATION = ''
HOST = '0.0.0.0'
PORT = 5580
REMOTE_MC_URL = ''

10
worker/106.py Normal file
View file

@ -0,0 +1,10 @@
import requests
from zzcore import StdAns
class Ans(StdAns):
AllowGroup = [959613860, 983250332]
def GETMSG(self):
seconds = int(requests.get("http://127.0.0.1:8095/").text)
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
return f'{h}小时{m}分钟{s}秒前有人来过。'

View file

@ -3,8 +3,11 @@ import requests
from config import LOLIKEYS
class Ans(StdAns):
AllowGroup = [973510746, 805197917,343700338,125733077,1084566280,920863253,798595664,655057127,196268763, 247022495, 474907856]
AllowGroup = [973510746, 805197917, 343700338, 125733077, 1084566280,
920863253, 798595664, 655057127, 196268763, 247022495, 474907856, 940333876]
def GETMSG(self):
keys = LOLIKEYS
@ -29,22 +32,22 @@ class Ans(StdAns):
elif code == 3:
msg += '咱没查到,也有可能是Pixiv坏掉惹'
elif code == 0:
if len(self.parms) < 2 or (len(self.parms > 2) and self.parms[2] == 'p'):
if len(self.parms) < 2 or (len(self.parms) > 2 and self.parms[2] == 'p'):
msg += f'[CQ:image,file={picurl}]'
else:
msg += f'[CQ:reply,id={self.mid}]咱帮你🔍{keyword}找到了这个\n{picurl}'
if quota == 0:
nowkey = (nowkey+1)%(len(keys))
nowkey = (nowkey+1) % (len(keys))
if code == 429:
msg += f'>_< 已经没有 loli 啦帮你换到了key{nowkey},再试一下吧'
else:
msg += f'额度用光了,下次将使用 key{nowkey}'
self.DATASET({'nowkey':nowkey})
self.DATASET({'nowkey': nowkey})
return msg
def getsetu(apikey, keyword = ''):
def getsetu(apikey, keyword=''):
url = 'https://api.lolicon.app/setu/'
params = {
'apikey': apikey,
@ -53,9 +56,9 @@ def getsetu(apikey, keyword = ''):
params['keyword'] = keyword
try:
resp = requests.get(url=url,params=params).json()
resp = requests.get(url=url, params=params).json()
except:
return -1, -1 ,''
return -1, -1, ''
#quota = str(resp['quota'])
#seconds = resp['quota_min_ttl']
@ -74,4 +77,5 @@ def getsetu(apikey, keyword = ''):
elif resp['code'] == 429:
return 429, 0, ''
else:
# print(resp['code'])
return -2, -1, ''

View file

@ -1,10 +1,11 @@
from zzcore import StdAns
import re
import re, requests
from subprocess import getoutput,call
from config import REMOTE_MC_URL
class Ans(StdAns):
AllowGroup = [959613860, 125733077, 204097403, 1140391080]
AllowUser = [1318000868]
def GETMSG(self):
if len(self.parms) < 2:
return '不加参数是坏文明!'
@ -13,39 +14,65 @@ class Ans(StdAns):
if cmd in AllowCmd:
if cmd == 'status':
output = getoutput('spigot status')
p = re.compile(r'processes = ([0-9]*) \(')
prsnum = re.findall(p,output)[0]
p = re.compile(r' \((.*?)\)',re.S)
prsnames = re.findall(p,output)[0].split(', ')
p = re.compile(r'Total memory usage = (.*)$')
memory = re.findall(p,output)[0]
msg = '咱的MC服务器现在有 '
for prsname in prsnames:
msg = msg + prsname + ' '
msg = msg + '' + prsnum +'个进程,\n一共占用了' + memory +'内存呢。'
msg = getStatus()
elif cmd == 'list':
output = getoutput('spigot command list')
p = re.compile(r'There are (.*?)[ of a max]', re.S)
online = re.findall(p,output)[0]
if online == '0':
msg = '咱看着没有人在线哎\n_(-ω-`_)⌒)_'
else:
msg = '' + online + '个小伙伴在线!'
p = re.compile(r'online: (.*?)[\n>]', re.S)
players = re.findall(p,output)[0].split(', ')
for player in players:
msg = msg + '\n' + player
msg = getList()
elif cmd == 'say':
saywhat = self.raw_msg['message'][8:]
if not saywhat:
return '汝让咱say whato(≧口≦)o'
shellcmd = ['spigot','command','say',saywhat]
if call(shellcmd) == 0:
msg = '咱已经把消息传过去了。'
else:
msg = '٩(ŏ﹏ŏ、)۶竟然失败了,汝是不是让我发送奇怪的话过去!'
msg = say(saywhat)
else:
msg = '汝是不是在mc后面添加了奇怪的参数咱可只知道 status list 和 say。'
return msg
def getStatus():
if REMOTE_MC_URL:
output = requests.post(f'{REMOTE_MC_URL}/status').text
else:
output = getoutput('papermc status')
p = re.compile(r'processes = ([0-9]*) \(')
prsnum = re.findall(p,output)[0]
p = re.compile(r' \((.*?)\)',re.S)
prsnames = re.findall(p,output)[0].split(', ')
p = re.compile(r'Total memory usage = (.*)$')
memory = re.findall(p,output)[0]
msg = '咱的MC服务器现在有 '
for prsname in prsnames:
msg = msg + prsname + ' '
msg = msg + '' + prsnum +'个进程,\n一共占用了' + memory +'内存呢。'
return msg
def getList():
if REMOTE_MC_URL:
output = requests.post(f'{REMOTE_MC_URL}/list').text
else:
output = getoutput('papermc command list')
p = re.compile(r'There are (.*?)[ of a max]', re.S)
online = re.findall(p,output)[0]
if online == '0':
msg = '咱看着没有人在线哎\n_(-ω-`_)⌒)_'
else:
msg = '' + online + '个小伙伴在线!'
p = re.compile(r'online: (.*?)[\n>]', re.S)
players = re.findall(p,output)[0].split(', ')
for player in players:
msg = msg + '\n' + player
return msg
def say(saywhat):
if not saywhat:
return '汝让咱say whato(≧口≦)o'
if REMOTE_MC_URL:
code = requests.post(f'{REMOTE_MC_URL}/say',data=saywhat).text
else:
shellcmd = ['papermc','command','say',saywhat]
code = call(shellcmd)
if code == '0':
msg = '咱已经把消息传过去了。'
else:
msg = '٩(ŏ﹏ŏ、)۶竟然失败了,汝是不是让我发送奇怪的话过去!'
return msg

110
worker/rss.py Normal file
View file

@ -0,0 +1,110 @@
from zzcore import StdAns
import feedparser, json, time
allowCMD = ['sub','unsub','list','disable', 'enable']
# allSub = {
# 'https://farseerfc.me/feeds/atom.xml' : {
# 'url' : 'https://farseerfc.me/feeds/atom.xml',
# 'title' : 'Farseerfc的小窩',
# 'lastUpdated' : 'Sat, 12 Dec 2020 22:55:52 +0800',
# }
# }
class Ans(StdAns):
def push(self,title,posttitle,posturl):
msg = f'{title}\n{posttitle} {posturl}'
self.sendmsg(msg)
def GETMSG(self):
if len(self.parms) < 2:
return '不加参数是坏文明!'
gid = str(self.gid)
cmd = self.parms[1]
if cmd not in allowCMD:
return f'咱不知道 {cmd} 是什么东西 ●﹏●'
try:
nowdata = json.loads(self.DATAGET()[gid])
except:
nowdata ={
'allSub' : {},
'status' : False,
}
if cmd == 'sub':
if len(self.parms) < 3:
return '汝想订阅什么呢?'
suburl = self.parms[2]
try:
d = feedparser.parse(suburl)
title = d.feed.title
lastUpdated = d.entries[0].published
except:
return "咱好像没能成功订阅 (╥_╥)"
newsub = {
'url': suburl,
'title': title,
'lastUpdated' : lastUpdated,
}
nowdata['allSub'][suburl] = newsub
msg = f'{title}》订阅成功'
elif cmd == 'unsub':
if len(self.parms) < 3:
return '汝想退订什么呢?'
suburl = self.parms[2]
if suburl not in nowdata['allSub'].keys():
return '汝没有订阅过这个!'
unsub = nowdata['allSub'].pop(suburl)
msg = f"{unsub['title']}》已退订"
elif cmd == 'list':
msg = '订阅列表'
for sub in nowdata['allSub'].values():
msg += f"\n{sub['title']} {sub['url']}"
elif cmd == 'enable':
nowdata['status'] = True
self.DATASET({gid:json.dumps(nowdata)})
self.sendmsg("订阅已启用,咱会每隔五分钟抓取订阅,有新内容就会推送哦")
while(nowdata['status']):
nowdata = json.loads(self.DATAGET()[gid])
for sub in nowdata['allSub'].values():
try:
d = feedparser.parse(sub['url'])
except:
self.sendmsg(f"咱抓取不到 《{sub['title']}》!")
continue
if d.entries[0].published == sub['lastUpdated']:
continue
newfeedtitle = d.entries[0].title
newfeedlink = d.entries[0].link
self.push(sub['title'], newfeedtitle, newfeedlink)
nowdata['allSub'][sub['url']]['lastUpdated'] = d.entries[0].published
self.DATASET({gid:json.dumps(nowdata)})
time.sleep(300)
return '订阅已经真的停了!'
elif cmd == 'disable':
nowdata['status'] = False
msg = '咱不会再推送了!'
self.DATASET({gid:json.dumps(nowdata)})
return msg

View file

@ -36,8 +36,9 @@ def getWeather(id='101120206'):
}
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']}℃。"
# 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记得收好衣服,出门带伞~'
@ -46,24 +47,26 @@ def getWeather(id='101120206'):
def calendar():
ymc = ["十一", "十二", "", "", "", "", "", "", "", "", "", ""]
ymc = ["", "", "", "", "", "", "", "", "", "", "", ""]
rmc = ["初一", "初二", "初三", "初四", "初五", "初六", "初七", "初八", "初九", "初十", "十一", "十二", "十三", "十四", "十五",
"十六", "十七", "十八", "十九", "二十", "廿一", "廿二", "廿三", "廿四", "廿五", "廿六", "廿七", "廿八", "廿九", "三十", "卅一"]
zmc = ["", "", "", "", "", "", ""]
nowdate = datetime.now()
kaoyandate = datetime(2021,12,21)
djs = (kaoyandate - nowdate).days -1
y = nowdate.year
m = nowdate.month
d = nowdate.day
zc = int(nowdate.strftime("%W")) - 34
zc = int(nowdate.strftime("%W")) - 1
z = zmc[nowdate.weekday()]
lunar = sxtwl.Lunar()
lunarday = lunar.getDayBySolar(y, m, d)
lunardaychinese = f"{ymc[lunarday.Lmc]}{rmc[lunarday.Ldi]}"
lunardaychinese = f"{ymc[lunarday.Lmc]}{rmc[lunarday.Ldi]}"
if lunarday.Lleap:
lunardaychinese = "" + lunardaychinese
cal = f"{m}{d}日,农历{lunardaychinese}本学期{zc}周,星期{z}"
cal = f"{m}{d}日,{lunardaychinese}寒假{zc}周,星期{z}\n\n距离 2022 考研还有 {djs}"
return cal