mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
✨ 增加群温度
This commit is contained in:
parent
f221696337
commit
53d89cd56c
66
chat/chat.go
66
chat/chat.go
@ -1,9 +1,8 @@
|
|||||||
package chat
|
package chat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
@ -46,18 +45,59 @@ func init() { // 插件主体
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
})
|
})
|
||||||
|
// 群空调
|
||||||
|
var AirConditTemp = map[int64]int{}
|
||||||
|
var AirConditSwitch = map[int64]bool{}
|
||||||
|
zero.OnFullMatch("空调开").SetBlock(true).FirstPriority().
|
||||||
|
Handle(func(ctx *zero.Ctx) {
|
||||||
|
AirConditSwitch[ctx.Event.GroupID] = true
|
||||||
|
ctx.SendChain(message.Text("☀哔~"))
|
||||||
|
})
|
||||||
|
zero.OnFullMatch("空调关").SetBlock(true).FirstPriority().
|
||||||
|
Handle(func(ctx *zero.Ctx) {
|
||||||
|
AirConditSwitch[ctx.Event.GroupID] = false
|
||||||
|
delete(AirConditTemp, ctx.Event.GroupID)
|
||||||
|
ctx.SendChain(message.Text("💤哔~"))
|
||||||
|
})
|
||||||
|
zero.OnRegex(`设置温度(\d+)`).SetBlock(true).FirstPriority().
|
||||||
|
Handle(func(ctx *zero.Ctx) {
|
||||||
|
if _, exist := AirConditTemp[ctx.Event.GroupID]; !exist {
|
||||||
|
AirConditTemp[ctx.Event.GroupID] = 26
|
||||||
|
}
|
||||||
|
if AirConditSwitch[ctx.Event.GroupID] {
|
||||||
|
temp := ctx.State["regex_matched"].([]string)[1]
|
||||||
|
AirConditTemp[ctx.Event.GroupID], _ = strconv.Atoi(temp)
|
||||||
|
ctx.SendChain(message.Text(
|
||||||
|
"☀风速中", "\n",
|
||||||
|
"群温度 ", AirConditTemp[ctx.Event.GroupID], "℃",
|
||||||
|
))
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
ctx.SendChain(message.Text(
|
||||||
|
"💤", "\n",
|
||||||
|
"群温度 ", AirConditTemp[ctx.Event.GroupID], "℃",
|
||||||
|
))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func FileRead(path string) []byte {
|
})
|
||||||
//读取文件数据
|
zero.OnFullMatch(`群温度`).SetBlock(true).FirstPriority().
|
||||||
file, _ := os.Open(path)
|
Handle(func(ctx *zero.Ctx) {
|
||||||
defer file.Close()
|
if _, exist := AirConditTemp[ctx.Event.GroupID]; !exist {
|
||||||
data, _ := ioutil.ReadAll(file)
|
AirConditTemp[ctx.Event.GroupID] = 26
|
||||||
return data
|
|
||||||
}
|
}
|
||||||
|
if AirConditSwitch[ctx.Event.GroupID] {
|
||||||
func FileWrite(path string, content []byte) int {
|
ctx.SendChain(message.Text(
|
||||||
//写入文件数据
|
"☀风速中", "\n",
|
||||||
ioutil.WriteFile(path, content, 0644)
|
"群温度 ", AirConditTemp[ctx.Event.GroupID], "℃",
|
||||||
return len(content)
|
))
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
ctx.SendChain(message.Text(
|
||||||
|
"💤", "\n",
|
||||||
|
"群温度 ", AirConditTemp[ctx.Event.GroupID], "℃",
|
||||||
|
))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user