manager 增加 cron

This commit is contained in:
fumiama 2021-10-27 23:50:46 +08:00
parent 085e04c9ba
commit 022ee6cd95
11 changed files with 2575 additions and 416 deletions

View File

@ -75,6 +75,8 @@ zerobot -h -t token -u url [-d|w] [-g] qq1 qq2 qq3 ...
- [x] 在[MM]月[每周|周几]的[hh]点[mm]分时(用[url])提醒大家[xxx] - [x] 在[MM]月[每周|周几]的[hh]点[mm]分时(用[url])提醒大家[xxx]
- [x] 取消在[MM]月[dd]日的[hh]点[mm]分的提醒 - [x] 取消在[MM]月[dd]日的[hh]点[mm]分的提醒
- [x] 取消在[MM]月[每周|周几]的[hh]点[mm]分的提醒 - [x] 取消在[MM]月[每周|周几]的[hh]点[mm]分的提醒
- [x] 在"cron"时(用[url])提醒大家[xxx]
- [x] 取消在"cron"的提醒
- [x] 列出所有提醒 - [x] 列出所有提醒
- [x] 翻牌 - [x] 翻牌
- [x] [开启|关闭]入群验证 - [x] [开启|关闭]入群验证

View File

@ -252,42 +252,65 @@ func init() { // 插件主体
ctx.SendChain(message.Text("📧 --> " + ctx.State["regex_matched"].([]string)[1])) ctx.SendChain(message.Text("📧 --> " + ctx.State["regex_matched"].([]string)[1]))
}) })
// 定时提醒 // 定时提醒
zero.OnRegex(`^在(.{1,2})月(.{1,3}日|每?周.?)的(.{1,3})点(.{1,3})分时(用.+)?提醒大家(.*)`, zero.AdminPermission).SetBlock(true).SetPriority(40). zero.OnRegex(`^在(.{1,2})月(.{1,3}日|每?周.?)的(.{1,3})点(.{1,3})分时(用.+)?提醒大家(.*)`, zero.AdminPermission, zero.OnlyGroup).SetBlock(true).SetPriority(40).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
if ctx.Event.GroupID > 0 {
dateStrs := ctx.State["regex_matched"].([]string) dateStrs := ctx.State["regex_matched"].([]string)
ts := timer.GetFilledTimer(dateStrs, false) ts := timer.GetFilledTimer(dateStrs, ctx.Event.SelfID, false)
ts.Grpid = uint64(ctx.Event.GroupID)
if ts.Enable { if ts.Enable {
go clock.RegisterTimer(ts, true) go clock.RegisterTimer(ts, ctx.Event.GroupID, true)
ctx.SendChain(message.Text("记住了~")) ctx.SendChain(message.Text("记住了~"))
} else { } else {
ctx.SendChain(message.Text("参数非法!")) ctx.SendChain(message.Text("参数非法!"))
} }
})
// 定时 cron 提醒
zero.OnRegex(`^在"(.*)"时(用.+)?提醒大家(.*)`, zero.AdminPermission, zero.OnlyGroup).SetBlock(true).SetPriority(40).
Handle(func(ctx *zero.Ctx) {
dateStrs := ctx.State["regex_matched"].([]string)
var url, alert string
if len(dateStrs) == 3 {
url = dateStrs[1]
alert = dateStrs[2]
} else {
alert = dateStrs[1]
}
ts := timer.GetFilledCronTimer(dateStrs[0], alert, url, ctx.Event.SelfID)
if clock.RegisterTimer(ts, ctx.Event.GroupID, true) {
ctx.SendChain(message.Text("记住了~"))
} else {
ctx.SendChain(message.Text("参数非法!"))
} }
}) })
// 取消定时 // 取消定时
zero.OnRegex(`^取消在(.{1,2})月(.{1,3}日|每?周.?)的(.{1,3})点(.{1,3})分的提醒`, zero.AdminPermission).SetBlock(true).SetPriority(40). zero.OnRegex(`^取消在(.{1,2})月(.{1,3}日|每?周.?)的(.{1,3})点(.{1,3})分的提醒`, zero.AdminPermission, zero.OnlyGroup).SetBlock(true).SetPriority(40).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
if ctx.Event.GroupID > 0 {
dateStrs := ctx.State["regex_matched"].([]string) dateStrs := ctx.State["regex_matched"].([]string)
ts := timer.GetFilledTimer(dateStrs, true) ts := timer.GetFilledTimer(dateStrs, ctx.Event.SelfID, true)
ts.Grpid = uint64(ctx.Event.GroupID) ti := ts.GetTimerInfo(ctx.Event.GroupID)
ti := ts.GetTimerInfo()
ok := clock.CancelTimer(ti) ok := clock.CancelTimer(ti)
if ok { if ok {
ctx.SendChain(message.Text("取消成功~")) ctx.SendChain(message.Text("取消成功~"))
} else { } else {
ctx.SendChain(message.Text("没有这个定时器哦~")) ctx.SendChain(message.Text("没有这个定时器哦~"))
} }
})
// 取消 cron 定时
zero.OnRegex(`^取消在"(.*)"的提醒`, zero.AdminPermission, zero.OnlyGroup).SetBlock(true).SetPriority(40).
Handle(func(ctx *zero.Ctx) {
dateStrs := ctx.State["regex_matched"].([]string)
ts := timer.Timer{Cron: dateStrs[0]}
ti := ts.GetTimerInfo(ctx.Event.GroupID)
ok := clock.CancelTimer(ti)
if ok {
ctx.SendChain(message.Text("取消成功~"))
} else {
ctx.SendChain(message.Text("没有这个定时器哦~"))
} }
}) })
// 列出本群所有定时 // 列出本群所有定时
zero.OnFullMatch("列出所有提醒", zero.AdminPermission).SetBlock(true).SetPriority(40). zero.OnFullMatch("列出所有提醒", zero.AdminPermission, zero.OnlyGroup).SetBlock(true).SetPriority(40).
Handle(func(ctx *zero.Ctx) { Handle(func(ctx *zero.Ctx) {
if ctx.Event.GroupID > 0 {
ctx.SendChain(message.Text(clock.ListTimers(uint64(ctx.Event.GroupID)))) ctx.SendChain(message.Text(clock.ListTimers(uint64(ctx.Event.GroupID))))
}
}) })
// 随机点名 // 随机点名
zero.OnFullMatchGroup([]string{"翻牌"}, zero.OnlyGroup).SetBlock(true).SetPriority(40). zero.OnFullMatchGroup([]string{"翻牌"}, zero.OnlyGroup).SetBlock(true).SetPriority(40).

View File

@ -0,0 +1,68 @@
package main
import (
"fmt"
io "io"
"os"
"github.com/FloatTech/ZeroBot-Plugin/utils/file"
)
var timersmap TimersMapOld
var timersmapnew TimersMap
func loadTimers(pbfile string) bool {
if file.IsExist(pbfile) {
f, err := os.Open(pbfile)
if err == nil {
data, err1 := io.ReadAll(f)
if err1 == nil {
if len(data) > 0 {
err1 = timersmap.Unmarshal(data)
if err1 == nil {
return true
}
}
}
}
}
return false
}
// saveTimers 保存当前计时器
func saveTimers(pbfile string) error {
data, err := timersmapnew.Marshal()
if err == nil {
f, err1 := os.OpenFile(pbfile, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
if err1 != nil {
return err1
} else {
_, err2 := f.Write(data)
f.Close()
return err2
}
}
return err
}
func main() {
if len(os.Args) == 3 {
if loadTimers(os.Args[1]) {
timersmapnew.Timers = make(map[string]*Timer)
for s, t := range timersmap.Timers {
timersmapnew.Timers[s] = &Timer{
Enable: t.Enable,
Alert: t.Alert,
Url: t.Url,
Month: t.Month,
Day: t.Day,
Hour: t.Hour,
Minute: t.Minute,
}
}
saveTimers(os.Args[2])
}
} else {
fmt.Println("用法:旧文件路径 新文件路径")
}
}

View File

@ -0,0 +1,946 @@
package main
import (
fmt "fmt"
io "io"
math "math"
math_bits "math/bits"
proto "github.com/golang/protobuf/proto"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type TimerOld struct {
Enable bool `protobuf:"varint,1,opt,name=enable,proto3" json:"enable,omitempty"`
Alert string `protobuf:"bytes,2,opt,name=alert,proto3" json:"alert,omitempty"`
Url string `protobuf:"bytes,3,opt,name=url,proto3" json:"url,omitempty"`
Month int32 `protobuf:"zigzag32,4,opt,name=month,proto3" json:"month,omitempty"`
Day int32 `protobuf:"zigzag32,5,opt,name=day,proto3" json:"day,omitempty"`
Week int32 `protobuf:"zigzag32,6,opt,name=week,proto3" json:"week,omitempty"`
Hour int32 `protobuf:"zigzag32,7,opt,name=hour,proto3" json:"hour,omitempty"`
Minute int32 `protobuf:"zigzag32,8,opt,name=minute,proto3" json:"minute,omitempty"`
Grpid uint64 `protobuf:"varint,9,opt,name=grpid,proto3" json:"grpid,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *TimerOld) Reset() { *m = TimerOld{} }
func (m *TimerOld) String() string { return proto.CompactTextString(m) }
func (*TimerOld) ProtoMessage() {}
func (*TimerOld) Descriptor() ([]byte, []int) {
return fileDescriptor_old, []int{0}
}
func (m *TimerOld) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *TimerOld) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_Timer.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *TimerOld) XXX_Merge(src proto.Message) {
xxx_messageInfo_Timer.Merge(m, src)
}
func (m *TimerOld) XXX_Size() int {
return m.Size()
}
func (m *TimerOld) XXX_DiscardUnknown() {
xxx_messageInfo_Timer.DiscardUnknown(m)
}
func (m *TimerOld) GetEnable() bool {
if m != nil {
return m.Enable
}
return false
}
func (m *TimerOld) GetAlert() string {
if m != nil {
return m.Alert
}
return ""
}
func (m *TimerOld) GetUrl() string {
if m != nil {
return m.Url
}
return ""
}
func (m *TimerOld) GetMonth() int32 {
if m != nil {
return m.Month
}
return 0
}
func (m *TimerOld) GetDay() int32 {
if m != nil {
return m.Day
}
return 0
}
func (m *TimerOld) GetWeek() int32 {
if m != nil {
return m.Week
}
return 0
}
func (m *TimerOld) GetHour() int32 {
if m != nil {
return m.Hour
}
return 0
}
func (m *TimerOld) GetMinute() int32 {
if m != nil {
return m.Minute
}
return 0
}
func (m *TimerOld) GetGrpid() uint64 {
if m != nil {
return m.Grpid
}
return 0
}
type TimersMapOld struct {
Timers map[string]*TimerOld `protobuf:"bytes,1,rep,name=timers,proto3" json:"timers,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *TimersMapOld) Reset() { *m = TimersMapOld{} }
func (m *TimersMapOld) String() string { return proto.CompactTextString(m) }
func (*TimersMapOld) ProtoMessage() {}
func (*TimersMapOld) Descriptor() ([]byte, []int) {
return fileDescriptor_old, []int{1}
}
func (m *TimersMapOld) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *TimersMapOld) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_TimersMap.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *TimersMapOld) XXX_Merge(src proto.Message) {
xxx_messageInfo_TimersMap.Merge(m, src)
}
func (m *TimersMapOld) XXX_Size() int {
return m.Size()
}
func (m *TimersMapOld) XXX_DiscardUnknown() {
xxx_messageInfo_TimersMap.DiscardUnknown(m)
}
func (m *TimersMapOld) GetTimers() map[string]*TimerOld {
if m != nil {
return m.Timers
}
return nil
}
func init() {
proto.RegisterType((*TimerOld)(nil), "timer.Timer")
proto.RegisterType((*TimersMapOld)(nil), "timer.TimersMap")
proto.RegisterMapType((map[string]*TimerOld)(nil), "timer.TimersMap.TimersEntry")
}
func init() { proto.RegisterFile("timer.proto", fileDescriptor_old) }
var fileDescriptor_old = []byte{
// 278 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xcd, 0x4a, 0xc3, 0x40,
0x10, 0xc7, 0x9d, 0xe6, 0xc3, 0x66, 0xe3, 0xa1, 0x2e, 0x22, 0x83, 0x48, 0x08, 0x39, 0xe5, 0xd4,
0x43, 0xf5, 0x20, 0x1e, 0x05, 0xf1, 0xe4, 0x65, 0xf1, 0x05, 0x52, 0xba, 0xd8, 0xd0, 0x7c, 0xb1,
0xdd, 0x28, 0x79, 0x05, 0x9f, 0xc0, 0x17, 0x12, 0x3c, 0xfa, 0x08, 0x12, 0x5f, 0x44, 0x66, 0x36,
0x94, 0xde, 0x7e, 0xff, 0x5f, 0xfe, 0x64, 0x67, 0x46, 0xc4, 0xb6, 0xac, 0xb5, 0x59, 0x76, 0xa6,
0xb5, 0xad, 0x0c, 0x38, 0x64, 0x5f, 0x20, 0x82, 0x17, 0x22, 0x79, 0x29, 0x42, 0xdd, 0x14, 0xeb,
0x4a, 0x23, 0xa4, 0x90, 0xcf, 0xd5, 0x94, 0xe4, 0x85, 0x08, 0x8a, 0x4a, 0x1b, 0x8b, 0xb3, 0x14,
0xf2, 0x48, 0xb9, 0x20, 0x17, 0xc2, 0xeb, 0x4d, 0x85, 0x1e, 0x3b, 0x42, 0xea, 0xd5, 0x6d, 0x63,
0xb7, 0xe8, 0xa7, 0x90, 0x9f, 0x2b, 0x17, 0xa8, 0xb7, 0x29, 0x06, 0x0c, 0xd8, 0x11, 0x4a, 0x29,
0xfc, 0x77, 0xad, 0x77, 0x18, 0xb2, 0x62, 0x26, 0xb7, 0x6d, 0x7b, 0x83, 0xa7, 0xce, 0x11, 0xd3,
0x3c, 0x75, 0xd9, 0xf4, 0x56, 0xe3, 0x9c, 0xed, 0x94, 0xe8, 0x9d, 0x57, 0xd3, 0x95, 0x1b, 0x8c,
0x52, 0xc8, 0x7d, 0xe5, 0x42, 0xf6, 0x01, 0x22, 0xe2, 0x3d, 0xf6, 0xcf, 0x45, 0x27, 0x6f, 0x45,
0xc8, 0xeb, 0xed, 0x11, 0x52, 0x2f, 0x8f, 0x57, 0xd7, 0x4b, 0xb7, 0xfa, 0xa1, 0x31, 0xd1, 0x63,
0x63, 0xcd, 0xa0, 0xa6, 0xee, 0xd5, 0x93, 0x88, 0x8f, 0x34, 0x8d, 0xbe, 0xd3, 0x03, 0x5f, 0x23,
0x52, 0x84, 0x32, 0x13, 0xc1, 0x5b, 0x51, 0xf5, 0x9a, 0x4f, 0x11, 0xaf, 0xce, 0x8e, 0xff, 0xaa,
0xdc, 0xa7, 0xfb, 0xd9, 0x1d, 0x3c, 0x2c, 0xbe, 0xc7, 0x04, 0x7e, 0xc6, 0x04, 0x7e, 0xc7, 0x04,
0x3e, 0xff, 0x92, 0x93, 0x75, 0xc8, 0x47, 0xbf, 0xf9, 0x0f, 0x00, 0x00, 0xff, 0xff, 0xe0, 0xc7,
0xad, 0xf8, 0x83, 0x01, 0x00, 0x00,
}
func (m *TimerOld) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *TimerOld) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *TimerOld) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.XXX_unrecognized != nil {
i -= len(m.XXX_unrecognized)
copy(dAtA[i:], m.XXX_unrecognized)
}
if m.Grpid != 0 {
i = encodeVarintTimerOld(dAtA, i, uint64(m.Grpid))
i--
dAtA[i] = 0x48
}
if m.Minute != 0 {
i = encodeVarintTimerOld(dAtA, i, uint64((uint32(m.Minute)<<1)^uint32((m.Minute>>31))))
i--
dAtA[i] = 0x40
}
if m.Hour != 0 {
i = encodeVarintTimerOld(dAtA, i, uint64((uint32(m.Hour)<<1)^uint32((m.Hour>>31))))
i--
dAtA[i] = 0x38
}
if m.Week != 0 {
i = encodeVarintTimerOld(dAtA, i, uint64((uint32(m.Week)<<1)^uint32((m.Week>>31))))
i--
dAtA[i] = 0x30
}
if m.Day != 0 {
i = encodeVarintTimerOld(dAtA, i, uint64((uint32(m.Day)<<1)^uint32((m.Day>>31))))
i--
dAtA[i] = 0x28
}
if m.Month != 0 {
i = encodeVarintTimerOld(dAtA, i, uint64((uint32(m.Month)<<1)^uint32((m.Month>>31))))
i--
dAtA[i] = 0x20
}
if len(m.Url) > 0 {
i -= len(m.Url)
copy(dAtA[i:], m.Url)
i = encodeVarintTimerOld(dAtA, i, uint64(len(m.Url)))
i--
dAtA[i] = 0x1a
}
if len(m.Alert) > 0 {
i -= len(m.Alert)
copy(dAtA[i:], m.Alert)
i = encodeVarintTimerOld(dAtA, i, uint64(len(m.Alert)))
i--
dAtA[i] = 0x12
}
if m.Enable {
i--
if m.Enable {
dAtA[i] = 1
} else {
dAtA[i] = 0
}
i--
dAtA[i] = 0x8
}
return len(dAtA) - i, nil
}
func (m *TimersMapOld) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *TimersMapOld) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *TimersMapOld) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.XXX_unrecognized != nil {
i -= len(m.XXX_unrecognized)
copy(dAtA[i:], m.XXX_unrecognized)
}
if len(m.Timers) > 0 {
for k := range m.Timers {
v := m.Timers[k]
baseI := i
if v != nil {
{
size, err := v.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintTimerOld(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x12
}
i -= len(k)
copy(dAtA[i:], k)
i = encodeVarintTimerOld(dAtA, i, uint64(len(k)))
i--
dAtA[i] = 0xa
i = encodeVarintTimerOld(dAtA, i, uint64(baseI-i))
i--
dAtA[i] = 0xa
}
}
return len(dAtA) - i, nil
}
func encodeVarintTimerOld(dAtA []byte, offset int, v uint64) int {
offset -= sovTimerOld(v)
base := offset
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
return base
}
func (m *TimerOld) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.Enable {
n += 2
}
l = len(m.Alert)
if l > 0 {
n += 1 + l + sovTimerOld(uint64(l))
}
l = len(m.Url)
if l > 0 {
n += 1 + l + sovTimerOld(uint64(l))
}
if m.Month != 0 {
n += 1 + sozTimerOld(uint64(m.Month))
}
if m.Day != 0 {
n += 1 + sozTimerOld(uint64(m.Day))
}
if m.Week != 0 {
n += 1 + sozTimerOld(uint64(m.Week))
}
if m.Hour != 0 {
n += 1 + sozTimerOld(uint64(m.Hour))
}
if m.Minute != 0 {
n += 1 + sozTimerOld(uint64(m.Minute))
}
if m.Grpid != 0 {
n += 1 + sovTimerOld(uint64(m.Grpid))
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
return n
}
func (m *TimersMapOld) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if len(m.Timers) > 0 {
for k, v := range m.Timers {
_ = k
_ = v
l = 0
if v != nil {
l = v.Size()
l += 1 + sovTimerOld(uint64(l))
}
mapEntrySize := 1 + len(k) + sovTimerOld(uint64(len(k))) + l
n += mapEntrySize + 1 + sovTimerOld(uint64(mapEntrySize))
}
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
return n
}
func sovTimerOld(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
func sozTimerOld(x uint64) (n int) {
return sovTimerOld(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *TimerOld) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimerOld
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: Timer: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: Timer: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Enable", wireType)
}
var v int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimerOld
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
v |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
m.Enable = bool(v != 0)
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Alert", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimerOld
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthTimerOld
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthTimerOld
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Alert = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Url", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimerOld
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthTimerOld
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthTimerOld
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Url = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 4:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Month", wireType)
}
var v int32
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimerOld
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
v |= int32(b&0x7F) << shift
if b < 0x80 {
break
}
}
v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31))
m.Month = v
case 5:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Day", wireType)
}
var v int32
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimerOld
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
v |= int32(b&0x7F) << shift
if b < 0x80 {
break
}
}
v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31))
m.Day = v
case 6:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Week", wireType)
}
var v int32
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimerOld
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
v |= int32(b&0x7F) << shift
if b < 0x80 {
break
}
}
v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31))
m.Week = v
case 7:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Hour", wireType)
}
var v int32
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimerOld
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
v |= int32(b&0x7F) << shift
if b < 0x80 {
break
}
}
v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31))
m.Hour = v
case 8:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Minute", wireType)
}
var v int32
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimerOld
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
v |= int32(b&0x7F) << shift
if b < 0x80 {
break
}
}
v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31))
m.Minute = v
case 9:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Grpid", wireType)
}
m.Grpid = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimerOld
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Grpid |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
default:
iNdEx = preIndex
skippy, err := skipTimerOld(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthTimerOld
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *TimersMapOld) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimerOld
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: TimersMap: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: TimersMap: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Timers", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimerOld
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthTimerOld
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthTimerOld
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.Timers == nil {
m.Timers = make(map[string]*TimerOld)
}
var mapkey string
var mapvalue *TimerOld
for iNdEx < postIndex {
entryPreIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimerOld
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
if fieldNum == 1 {
var stringLenmapkey uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimerOld
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLenmapkey |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLenmapkey := int(stringLenmapkey)
if intStringLenmapkey < 0 {
return ErrInvalidLengthTimerOld
}
postStringIndexmapkey := iNdEx + intStringLenmapkey
if postStringIndexmapkey < 0 {
return ErrInvalidLengthTimerOld
}
if postStringIndexmapkey > l {
return io.ErrUnexpectedEOF
}
mapkey = string(dAtA[iNdEx:postStringIndexmapkey])
iNdEx = postStringIndexmapkey
} else if fieldNum == 2 {
var mapmsglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimerOld
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
mapmsglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if mapmsglen < 0 {
return ErrInvalidLengthTimerOld
}
postmsgIndex := iNdEx + mapmsglen
if postmsgIndex < 0 {
return ErrInvalidLengthTimerOld
}
if postmsgIndex > l {
return io.ErrUnexpectedEOF
}
mapvalue = &TimerOld{}
if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil {
return err
}
iNdEx = postmsgIndex
} else {
iNdEx = entryPreIndex
skippy, err := skipTimerOld(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthTimerOld
}
if (iNdEx + skippy) > postIndex {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
m.Timers[mapkey] = mapvalue
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipTimerOld(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthTimerOld
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipTimerOld(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
depth := 0
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowTimerOld
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
wireType := int(wire & 0x7)
switch wireType {
case 0:
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowTimerOld
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
iNdEx++
if dAtA[iNdEx-1] < 0x80 {
break
}
}
case 1:
iNdEx += 8
case 2:
var length int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowTimerOld
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
length |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if length < 0 {
return 0, ErrInvalidLengthTimerOld
}
iNdEx += length
case 3:
depth++
case 4:
if depth == 0 {
return 0, ErrUnexpectedEndOfGroupTimerOld
}
depth--
case 5:
iNdEx += 4
default:
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
}
if iNdEx < 0 {
return 0, ErrInvalidLengthTimerOld
}
if depth == 0 {
return iNdEx, nil
}
}
return 0, io.ErrUnexpectedEOF
}
var (
ErrInvalidLengthTimerOld = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowTimerOld = fmt.Errorf("proto: integer overflow")
ErrUnexpectedEndOfGroupTimerOld = fmt.Errorf("proto: unexpected end of group")
)

View File

@ -0,0 +1,992 @@
package main
import (
fmt "fmt"
io "io"
math "math"
math_bits "math/bits"
proto "github.com/golang/protobuf/proto"
)
// Reference imports to suppress errors if they are not otherwise used.
var _ = proto.Marshal
var _ = fmt.Errorf
var _ = math.Inf
// This is a compile-time assertion to ensure that this generated file
// is compatible with the proto package it is being compiled against.
// A compilation error at this line likely means your copy of the
// proto package needs to be updated.
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type Timer struct {
Enable bool `protobuf:"varint,1,opt,name=enable,proto3" json:"enable,omitempty"`
Alert string `protobuf:"bytes,2,opt,name=alert,proto3" json:"alert,omitempty"`
Url string `protobuf:"bytes,3,opt,name=url,proto3" json:"url,omitempty"`
Month int32 `protobuf:"varint,4,opt,name=month,proto3" json:"month,omitempty"`
Day int32 `protobuf:"varint,5,opt,name=day,proto3" json:"day,omitempty"`
Week int32 `protobuf:"varint,6,opt,name=week,proto3" json:"week,omitempty"`
Hour int32 `protobuf:"varint,7,opt,name=hour,proto3" json:"hour,omitempty"`
Minute int32 `protobuf:"varint,8,opt,name=minute,proto3" json:"minute,omitempty"`
Selfid int64 `protobuf:"varint,9,opt,name=selfid,proto3" json:"selfid,omitempty"`
Cron string `protobuf:"bytes,10,opt,name=cron,proto3" json:"cron,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *Timer) Reset() { *m = Timer{} }
func (m *Timer) String() string { return proto.CompactTextString(m) }
func (*Timer) ProtoMessage() {}
func (*Timer) Descriptor() ([]byte, []int) {
return fileDescriptor_ad0307ee16b652d2, []int{0}
}
func (m *Timer) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *Timer) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_Timer.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *Timer) XXX_Merge(src proto.Message) {
xxx_messageInfo_Timer.Merge(m, src)
}
func (m *Timer) XXX_Size() int {
return m.Size()
}
func (m *Timer) XXX_DiscardUnknown() {
xxx_messageInfo_Timer.DiscardUnknown(m)
}
var xxx_messageInfo_Timer proto.InternalMessageInfo
func (m *Timer) GetEnable() bool {
if m != nil {
return m.Enable
}
return false
}
func (m *Timer) GetAlert() string {
if m != nil {
return m.Alert
}
return ""
}
func (m *Timer) GetUrl() string {
if m != nil {
return m.Url
}
return ""
}
func (m *Timer) GetMonth() int32 {
if m != nil {
return m.Month
}
return 0
}
func (m *Timer) GetDay() int32 {
if m != nil {
return m.Day
}
return 0
}
func (m *Timer) GetWeek() int32 {
if m != nil {
return m.Week
}
return 0
}
func (m *Timer) GetHour() int32 {
if m != nil {
return m.Hour
}
return 0
}
func (m *Timer) GetMinute() int32 {
if m != nil {
return m.Minute
}
return 0
}
func (m *Timer) GetSelfid() int64 {
if m != nil {
return m.Selfid
}
return 0
}
func (m *Timer) GetCron() string {
if m != nil {
return m.Cron
}
return ""
}
type TimersMap struct {
Timers map[string]*Timer `protobuf:"bytes,1,rep,name=timers,proto3" json:"timers,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *TimersMap) Reset() { *m = TimersMap{} }
func (m *TimersMap) String() string { return proto.CompactTextString(m) }
func (*TimersMap) ProtoMessage() {}
func (*TimersMap) Descriptor() ([]byte, []int) {
return fileDescriptor_ad0307ee16b652d2, []int{1}
}
func (m *TimersMap) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *TimersMap) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_TimersMap.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *TimersMap) XXX_Merge(src proto.Message) {
xxx_messageInfo_TimersMap.Merge(m, src)
}
func (m *TimersMap) XXX_Size() int {
return m.Size()
}
func (m *TimersMap) XXX_DiscardUnknown() {
xxx_messageInfo_TimersMap.DiscardUnknown(m)
}
var xxx_messageInfo_TimersMap proto.InternalMessageInfo
func (m *TimersMap) GetTimers() map[string]*Timer {
if m != nil {
return m.Timers
}
return nil
}
func init() {
proto.RegisterType((*Timer)(nil), "timer.Timer")
proto.RegisterType((*TimersMap)(nil), "timer.TimersMap")
proto.RegisterMapType((map[string]*Timer)(nil), "timer.TimersMap.TimersEntry")
}
func init() { proto.RegisterFile("timer.proto", fileDescriptor_ad0307ee16b652d2) }
var fileDescriptor_ad0307ee16b652d2 = []byte{
// 289 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x91, 0xcf, 0x4a, 0xfb, 0x40,
0x10, 0xc7, 0x7f, 0xd3, 0x74, 0xf3, 0x6b, 0x26, 0x1e, 0xca, 0x22, 0x32, 0x88, 0x84, 0xd0, 0x53,
0x4e, 0x3d, 0x54, 0x0f, 0xe2, 0x51, 0x10, 0x4f, 0x5e, 0x16, 0x5f, 0x20, 0xb5, 0x2b, 0x2d, 0xcd,
0x9f, 0xb2, 0xd9, 0x28, 0x79, 0x05, 0x9f, 0xc0, 0x47, 0xf2, 0xe8, 0xdd, 0x8b, 0xc4, 0x17, 0x91,
0x99, 0x04, 0xe9, 0xed, 0xf3, 0xfd, 0xe4, 0xcb, 0x32, 0x33, 0xc1, 0xd8, 0xef, 0x4a, 0xeb, 0x96,
0x07, 0x57, 0xfb, 0x5a, 0x2b, 0x09, 0x8b, 0x2f, 0x40, 0xf5, 0xc8, 0xa4, 0xcf, 0x30, 0xb4, 0x55,
0xbe, 0x2e, 0x2c, 0x41, 0x0a, 0xd9, 0xcc, 0x8c, 0x49, 0x9f, 0xa2, 0xca, 0x0b, 0xeb, 0x3c, 0x4d,
0x52, 0xc8, 0x22, 0x33, 0x04, 0x3d, 0xc7, 0xa0, 0x75, 0x05, 0x05, 0xe2, 0x18, 0xb9, 0x57, 0xd6,
0x95, 0xdf, 0xd2, 0x34, 0x85, 0x4c, 0x99, 0x21, 0x70, 0x6f, 0x93, 0x77, 0xa4, 0xc4, 0x31, 0x6a,
0x8d, 0xd3, 0x57, 0x6b, 0xf7, 0x14, 0x8a, 0x12, 0x66, 0xb7, 0xad, 0x5b, 0x47, 0xff, 0x07, 0xc7,
0xcc, 0xf3, 0x94, 0xbb, 0xaa, 0xf5, 0x96, 0x66, 0x62, 0xc7, 0xc4, 0xbe, 0xb1, 0xc5, 0xf3, 0x6e,
0x43, 0x51, 0x0a, 0x59, 0x60, 0xc6, 0xc4, 0x6f, 0x3c, 0xb9, 0xba, 0x22, 0x94, 0x91, 0x84, 0x17,
0x6f, 0x80, 0x91, 0x6c, 0xd7, 0x3c, 0xe4, 0x07, 0x7d, 0x85, 0xa1, 0x2c, 0xdd, 0x10, 0xa4, 0x41,
0x16, 0xaf, 0x2e, 0x96, 0xc3, 0x41, 0xfe, 0x1a, 0x23, 0xdd, 0x55, 0xde, 0x75, 0x66, 0xec, 0x9e,
0xdf, 0x63, 0x7c, 0xa4, 0x79, 0xa1, 0xbd, 0xed, 0xe4, 0x46, 0x91, 0x61, 0xd4, 0x0b, 0x54, 0x2f,
0x79, 0xd1, 0x5a, 0x39, 0x50, 0xbc, 0x3a, 0x39, 0x7e, 0xd5, 0x0c, 0x9f, 0x6e, 0x26, 0xd7, 0x70,
0x3b, 0xff, 0xe8, 0x13, 0xf8, 0xec, 0x13, 0xf8, 0xee, 0x13, 0x78, 0xff, 0x49, 0xfe, 0xad, 0x43,
0xf9, 0x15, 0x97, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x7b, 0xe3, 0x45, 0x55, 0x99, 0x01, 0x00,
0x00,
}
func (m *Timer) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *Timer) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *Timer) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.XXX_unrecognized != nil {
i -= len(m.XXX_unrecognized)
copy(dAtA[i:], m.XXX_unrecognized)
}
if len(m.Cron) > 0 {
i -= len(m.Cron)
copy(dAtA[i:], m.Cron)
i = encodeVarintTimer(dAtA, i, uint64(len(m.Cron)))
i--
dAtA[i] = 0x52
}
if m.Selfid != 0 {
i = encodeVarintTimer(dAtA, i, uint64(m.Selfid))
i--
dAtA[i] = 0x48
}
if m.Minute != 0 {
i = encodeVarintTimer(dAtA, i, uint64(m.Minute))
i--
dAtA[i] = 0x40
}
if m.Hour != 0 {
i = encodeVarintTimer(dAtA, i, uint64(m.Hour))
i--
dAtA[i] = 0x38
}
if m.Week != 0 {
i = encodeVarintTimer(dAtA, i, uint64(m.Week))
i--
dAtA[i] = 0x30
}
if m.Day != 0 {
i = encodeVarintTimer(dAtA, i, uint64(m.Day))
i--
dAtA[i] = 0x28
}
if m.Month != 0 {
i = encodeVarintTimer(dAtA, i, uint64(m.Month))
i--
dAtA[i] = 0x20
}
if len(m.Url) > 0 {
i -= len(m.Url)
copy(dAtA[i:], m.Url)
i = encodeVarintTimer(dAtA, i, uint64(len(m.Url)))
i--
dAtA[i] = 0x1a
}
if len(m.Alert) > 0 {
i -= len(m.Alert)
copy(dAtA[i:], m.Alert)
i = encodeVarintTimer(dAtA, i, uint64(len(m.Alert)))
i--
dAtA[i] = 0x12
}
if m.Enable {
i--
if m.Enable {
dAtA[i] = 1
} else {
dAtA[i] = 0
}
i--
dAtA[i] = 0x8
}
return len(dAtA) - i, nil
}
func (m *TimersMap) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *TimersMap) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *TimersMap) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.XXX_unrecognized != nil {
i -= len(m.XXX_unrecognized)
copy(dAtA[i:], m.XXX_unrecognized)
}
if len(m.Timers) > 0 {
for k := range m.Timers {
v := m.Timers[k]
baseI := i
if v != nil {
{
size, err := v.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintTimer(dAtA, i, uint64(size))
}
i--
dAtA[i] = 0x12
}
i -= len(k)
copy(dAtA[i:], k)
i = encodeVarintTimer(dAtA, i, uint64(len(k)))
i--
dAtA[i] = 0xa
i = encodeVarintTimer(dAtA, i, uint64(baseI-i))
i--
dAtA[i] = 0xa
}
}
return len(dAtA) - i, nil
}
func encodeVarintTimer(dAtA []byte, offset int, v uint64) int {
offset -= sovTimer(v)
base := offset
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
return base
}
func (m *Timer) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.Enable {
n += 2
}
l = len(m.Alert)
if l > 0 {
n += 1 + l + sovTimer(uint64(l))
}
l = len(m.Url)
if l > 0 {
n += 1 + l + sovTimer(uint64(l))
}
if m.Month != 0 {
n += 1 + sovTimer(uint64(m.Month))
}
if m.Day != 0 {
n += 1 + sovTimer(uint64(m.Day))
}
if m.Week != 0 {
n += 1 + sovTimer(uint64(m.Week))
}
if m.Hour != 0 {
n += 1 + sovTimer(uint64(m.Hour))
}
if m.Minute != 0 {
n += 1 + sovTimer(uint64(m.Minute))
}
if m.Selfid != 0 {
n += 1 + sovTimer(uint64(m.Selfid))
}
l = len(m.Cron)
if l > 0 {
n += 1 + l + sovTimer(uint64(l))
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
return n
}
func (m *TimersMap) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if len(m.Timers) > 0 {
for k, v := range m.Timers {
_ = k
_ = v
l = 0
if v != nil {
l = v.Size()
l += 1 + sovTimer(uint64(l))
}
mapEntrySize := 1 + len(k) + sovTimer(uint64(len(k))) + l
n += mapEntrySize + 1 + sovTimer(uint64(mapEntrySize))
}
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
return n
}
func sovTimer(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
}
func sozTimer(x uint64) (n int) {
return sovTimer(uint64((x << 1) ^ uint64((int64(x) >> 63))))
}
func (m *Timer) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: Timer: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: Timer: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Enable", wireType)
}
var v int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
v |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
m.Enable = bool(v != 0)
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Alert", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthTimer
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthTimer
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Alert = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 3:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Url", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthTimer
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthTimer
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Url = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 4:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Month", wireType)
}
m.Month = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Month |= int32(b&0x7F) << shift
if b < 0x80 {
break
}
}
case 5:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Day", wireType)
}
m.Day = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Day |= int32(b&0x7F) << shift
if b < 0x80 {
break
}
}
case 6:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Week", wireType)
}
m.Week = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Week |= int32(b&0x7F) << shift
if b < 0x80 {
break
}
}
case 7:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Hour", wireType)
}
m.Hour = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Hour |= int32(b&0x7F) << shift
if b < 0x80 {
break
}
}
case 8:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Minute", wireType)
}
m.Minute = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Minute |= int32(b&0x7F) << shift
if b < 0x80 {
break
}
}
case 9:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Selfid", wireType)
}
m.Selfid = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Selfid |= int64(b&0x7F) << shift
if b < 0x80 {
break
}
}
case 10:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Cron", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthTimer
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthTimer
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Cron = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipTimer(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthTimer
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *TimersMap) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: TimersMap: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: TimersMap: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Timers", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
msglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if msglen < 0 {
return ErrInvalidLengthTimer
}
postIndex := iNdEx + msglen
if postIndex < 0 {
return ErrInvalidLengthTimer
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.Timers == nil {
m.Timers = make(map[string]*Timer)
}
var mapkey string
var mapvalue *Timer
for iNdEx < postIndex {
entryPreIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
if fieldNum == 1 {
var stringLenmapkey uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLenmapkey |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLenmapkey := int(stringLenmapkey)
if intStringLenmapkey < 0 {
return ErrInvalidLengthTimer
}
postStringIndexmapkey := iNdEx + intStringLenmapkey
if postStringIndexmapkey < 0 {
return ErrInvalidLengthTimer
}
if postStringIndexmapkey > l {
return io.ErrUnexpectedEOF
}
mapkey = string(dAtA[iNdEx:postStringIndexmapkey])
iNdEx = postStringIndexmapkey
} else if fieldNum == 2 {
var mapmsglen int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
mapmsglen |= int(b&0x7F) << shift
if b < 0x80 {
break
}
}
if mapmsglen < 0 {
return ErrInvalidLengthTimer
}
postmsgIndex := iNdEx + mapmsglen
if postmsgIndex < 0 {
return ErrInvalidLengthTimer
}
if postmsgIndex > l {
return io.ErrUnexpectedEOF
}
mapvalue = &Timer{}
if err := mapvalue.Unmarshal(dAtA[iNdEx:postmsgIndex]); err != nil {
return err
}
iNdEx = postmsgIndex
} else {
iNdEx = entryPreIndex
skippy, err := skipTimer(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthTimer
}
if (iNdEx + skippy) > postIndex {
return io.ErrUnexpectedEOF
}
iNdEx += skippy
}
}
m.Timers[mapkey] = mapvalue
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipTimer(dAtA[iNdEx:])
if err != nil {
return err
}
if (skippy < 0) || (iNdEx+skippy) < 0 {
return ErrInvalidLengthTimer
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func skipTimer(dAtA []byte) (n int, err error) {
l := len(dAtA)
iNdEx := 0
depth := 0
for iNdEx < l {
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowTimer
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= (uint64(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
wireType := int(wire & 0x7)
switch wireType {
case 0:
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowTimer
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
iNdEx++
if dAtA[iNdEx-1] < 0x80 {
break
}
}
case 1:
iNdEx += 8
case 2:
var length int
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return 0, ErrIntOverflowTimer
}
if iNdEx >= l {
return 0, io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
length |= (int(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
if length < 0 {
return 0, ErrInvalidLengthTimer
}
iNdEx += length
case 3:
depth++
case 4:
if depth == 0 {
return 0, ErrUnexpectedEndOfGroupTimer
}
depth--
case 5:
iNdEx += 4
default:
return 0, fmt.Errorf("proto: illegal wireType %d", wireType)
}
if iNdEx < 0 {
return 0, ErrInvalidLengthTimer
}
if depth == 0 {
return iNdEx, nil
}
}
return 0, io.ErrUnexpectedEOF
}
var (
ErrInvalidLengthTimer = fmt.Errorf("proto: negative length found during unmarshaling")
ErrIntOverflowTimer = fmt.Errorf("proto: integer overflow")
ErrUnexpectedEndOfGroupTimer = fmt.Errorf("proto: unexpected end of group")
)

View File

@ -0,0 +1,17 @@
package timer
import (
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)
func (ts *Timer) sendmsg(grp int64, ctx *zero.Ctx) {
ctx.Event = new(zero.Event)
ctx.Event.GroupID = grp
if ts.Url == "" {
ctx.SendChain(atall, message.Text(ts.Alert))
} else {
ctx.SendChain(atall, message.Text(ts.Alert), message.Image(ts.Url).Add("cache", "0"))
}
return
}

View File

@ -0,0 +1,147 @@
package timer
import (
"fmt"
"strconv"
"strings"
"unicode"
"github.com/sirupsen/logrus"
)
// GetTimerInfo 获得标准化定时字符串
func (ts *Timer) GetTimerInfo(grp int64) string {
if ts.Cron != "" {
return fmt.Sprintf("[%d]%s", grp, ts.Cron)
}
return fmt.Sprintf("[%d]%d月%d日%d周%d:%d", grp, ts.Month, ts.Day, ts.Week, ts.Hour, ts.Minute)
}
// GetFilledCronTimer 获得以cron填充好的ts
func GetFilledCronTimer(croncmd string, alert string, img string, botqq int64) *Timer {
var ts Timer
ts.Alert = alert
ts.Cron = croncmd
ts.Url = img
ts.Selfid = botqq
return &ts
}
// GetFilledTimer 获得填充好的ts
func GetFilledTimer(dateStrs []string, botqq int64, matchDateOnly bool) *Timer {
monthStr := []rune(dateStrs[1])
dayWeekStr := []rune(dateStrs[2])
hourStr := []rune(dateStrs[3])
minuteStr := []rune(dateStrs[4])
var ts Timer
ts.Month = chineseNum2Int(monthStr)
if (ts.Month != -1 && ts.Month <= 0) || ts.Month > 12 { // 月份非法
logrus.Println("[群管]月份非法!")
return &ts
}
lenOfDW := len(dayWeekStr)
if lenOfDW == 4 { // 包括末尾的"日"
dayWeekStr = []rune{dayWeekStr[0], dayWeekStr[2]} // 去除中间的十
ts.Day = chineseNum2Int(dayWeekStr)
if (ts.Day != -1 && ts.Day <= 0) || ts.Day > 31 { // 日期非法
logrus.Println("[群管]日期非法1")
return &ts
}
} else if dayWeekStr[lenOfDW-1] == rune('日') { // xx日
dayWeekStr = dayWeekStr[:lenOfDW-1]
ts.Day = chineseNum2Int(dayWeekStr)
if (ts.Day != -1 && ts.Day <= 0) || ts.Day > 31 { // 日期非法
logrus.Println("[群管]日期非法2")
return &ts
}
} else if dayWeekStr[0] == rune('每') { // 每周
ts.Week = -1
} else { // 周x
ts.Week = chineseNum2Int(dayWeekStr[1:])
if ts.Week == 7 { // 周天是0
ts.Week = 0
}
if ts.Week < 0 || ts.Week > 6 { // 星期非法
ts.Week = -11
logrus.Println("[群管]星期非法!")
return &ts
}
}
if len(hourStr) == 3 {
hourStr = []rune{hourStr[0], hourStr[2]} // 去除中间的十
}
ts.Hour = chineseNum2Int(hourStr)
if ts.Hour < -1 || ts.Hour > 23 { // 小时非法
logrus.Println("[群管]小时非法!")
return &ts
}
if len(minuteStr) == 3 {
minuteStr = []rune{minuteStr[0], minuteStr[2]} // 去除中间的十
}
ts.Minute = chineseNum2Int(minuteStr)
if ts.Minute < -1 || ts.Minute > 59 { // 分钟非法
logrus.Println("[群管]分钟非法!")
return &ts
}
if !matchDateOnly {
urlStr := dateStrs[5]
if urlStr != "" { // 是图片url
ts.Url = urlStr[3:] // utf-8下用为3字节
logrus.Println("[群管]" + ts.Url)
if !strings.HasPrefix(ts.Url, "http") {
ts.Url = "illegal"
logrus.Println("[群管]url非法")
return &ts
}
}
ts.Alert = dateStrs[6]
ts.Enable = true
}
ts.Selfid = botqq
return &ts
}
// chineseNum2Int 汉字数字转int仅支持-1099最多两位数其中"每"解释为-1"每二"为-2以此类推
func chineseNum2Int(rs []rune) int32 {
r := -1
l := len(rs)
mai := rune('每')
if unicode.IsDigit(rs[0]) { // 默认可能存在的第二位也为int
r, _ = strconv.Atoi(string(rs))
} else {
if rs[0] == mai {
if l == 2 {
r = -chineseChar2Int(rs[1])
}
} else if l == 1 {
r = chineseChar2Int(rs[0])
} else {
ten := chineseChar2Int(rs[0])
if ten != 10 {
ten *= 10
}
ge := chineseChar2Int(rs[1])
if ge == 10 {
ge = 0
}
r = ten + ge
}
}
return int32(r)
}
// chineseChar2Int 处理单个字符的映射0~10
func chineseChar2Int(c rune) int {
if c == rune('日') || c == rune('天') { // 周日/周天
return 7
} else {
match := []rune("零一二三四五六七八九十")
for i, m := range match {
if c == m {
return i
}
}
return 0
}
}

View File

@ -0,0 +1,164 @@
package timer
import (
"time"
"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
)
func firstWeek(date *time.Time, week time.Weekday) (d time.Time) {
d = date.AddDate(0, 0, 1-date.Day())
for d.Weekday() != week {
d = d.AddDate(0, 0, 1)
}
return
}
func (ts *Timer) nextWakeTime() (date time.Time) {
date = time.Now()
m := ts.Month
d := ts.Day
h := ts.Hour
mn := ts.Minute
w := ts.Week
unit := time.Duration(int(ts.Minute)-date.Minute()) * time.Minute
logrus.Debugln("[timer] unit init:", unit)
if mn >= 0 {
switch {
case h < 0:
if unit <= time.Second {
unit += time.Hour
}
case d < 0 || w < 0:
if unit <= time.Second {
unit += time.Hour * 24
}
case d == 0 && w >= 0:
delta := time.Hour * 24 * time.Duration(int(w)-int(date.Weekday()))
if delta < 0 {
delta += time.Hour * 24 * 7
}
unit += delta
case m < 0:
unit = -1
}
} else {
unit = time.Minute
}
logrus.Debugln("[timer] unit:", unit)
stable := 0
if mn < 0 {
mn = int32(date.Minute())
}
if h < 0 {
h = int32(date.Hour())
} else {
stable |= 0x8
}
if d < 0 {
d = int32(date.Day())
} else if d > 0 {
stable |= 0x4
} else {
d = int32(date.Day())
if w >= 0 {
stable |= 0x2
}
}
if m < 0 {
m = int32(date.Month())
} else {
stable |= 0x1
}
switch stable {
case 0b0101:
if ts.Day != int32(time.Now().Day()) || ts.Month != int32(time.Now().Month()) {
h = 0
}
case 0b1001:
if ts.Month != int32(time.Now().Month()) {
d = 0
}
case 0b0001:
if ts.Month != int32(time.Now().Month()) {
d = 0
h = 0
}
}
logrus.Debugln("[timer] stable:", stable)
logrus.Debugln("[timer] m:", m, "d:", d, "h:", h, "mn:", mn, "w:", w)
date = time.Date(date.Year(), time.Month(m), int(d), int(h), int(mn), date.Second(), date.Nanosecond(), date.Location())
logrus.Debugln("[timer] date original:", date)
if unit > 0 {
date = date.Add(unit)
}
logrus.Debugln("[timer] date after add:", date)
if time.Until(date) <= 0 {
if ts.Month < 0 {
if ts.Day > 0 || (ts.Day == 0 && ts.Week >= 0) {
date = date.AddDate(0, 1, 0)
} else if ts.Day < 0 || ts.Week < 0 {
if ts.Hour > 0 {
date = date.AddDate(0, 0, 1)
} else if ts.Minute > 0 {
date = date.Add(time.Hour)
}
}
} else {
date = date.AddDate(1, 0, 0)
}
}
logrus.Debugln("[timer] date after fix:", date)
if stable&0x8 != 0 && date.Hour() != int(h) {
switch {
case stable&0x4 == 0:
date = date.AddDate(0, 0, 1).Add(-time.Hour)
case stable&0x2 == 0:
date = date.AddDate(0, 0, 7).Add(-time.Hour)
case stable*0x1 == 0:
date = date.AddDate(0, 1, 0).Add(-time.Hour)
default:
date = date.AddDate(1, 0, 0).Add(-time.Hour)
}
}
logrus.Debugln("[timer] date after s8:", date)
if stable&0x4 != 0 && date.Day() != int(d) {
switch {
case stable*0x1 == 0:
date = date.AddDate(0, 1, -1)
default:
date = date.AddDate(1, 0, -1)
}
}
logrus.Debugln("[timer] date after s4:", date)
if stable&0x2 != 0 && int32(date.Weekday()) != w {
switch {
case stable*0x1 == 0:
date = date.AddDate(0, 1, 0)
default:
date = date.AddDate(1, 0, 0)
}
date = firstWeek(&date, time.Weekday(w))
}
logrus.Debugln("[timer] date after s2:", date)
if time.Until(date) <= 0 {
date = time.Now().Add(time.Minute)
}
return date
}
func (ts *Timer) judgeHM(grp int64) {
if ts.Hour < 0 || ts.Hour == int32(time.Now().Hour()) {
if ts.Minute < 0 || ts.Minute == int32(time.Now().Minute()) {
if ts.Selfid != 0 {
ts.sendmsg(grp, zero.GetBot(ts.Selfid))
} else {
zero.RangeBot(func(id int64, ctx *zero.Ctx) (_ bool) {
ts.sendmsg(grp, ctx)
return
})
}
}
}
}

View File

@ -2,15 +2,14 @@
package timer package timer
import ( import (
"fmt"
"io" "io"
"os" "os"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
"unicode"
"github.com/fumiama/cron"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot" zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message" "github.com/wdvxdr1123/ZeroBot/message"
@ -23,10 +22,14 @@ type Clock struct {
timersmap TimersMap timersmap TimersMap
// 定时器map // 定时器map
timers *(map[string]*Timer) timers *(map[string]*Timer)
// 读写锁
timersmu sync.RWMutex timersmu sync.RWMutex
// 定时器存储位置 // 定时器存储位置
pbfile *string pbfile *string
// cron 定时器
cron *cron.Cron
// entries key <-> cron
entries map[string]cron.EntryID
entmu sync.Mutex
} }
var ( var (
@ -43,172 +46,14 @@ func NewClock(pbfile string) (c Clock) {
c.loadTimers(pbfile) c.loadTimers(pbfile)
c.timers = &c.timersmap.Timers c.timers = &c.timersmap.Timers
c.pbfile = &pbfile c.pbfile = &pbfile
c.cron = cron.New()
c.entries = make(map[string]cron.EntryID)
return return
} }
func firstWeek(date *time.Time, week time.Weekday) (d time.Time) {
d = date.AddDate(0, 0, 1-date.Day())
for d.Weekday() != week {
d = d.AddDate(0, 0, 1)
}
return
}
func (ts *Timer) nextWakeTime() (date time.Time) {
date = time.Now()
m := ts.Month
d := ts.Day
h := ts.Hour
mn := ts.Minute
w := ts.Week
unit := time.Duration(int(ts.Minute)-date.Minute()) * time.Minute
logrus.Debugln("[timer] unit init:", unit)
if mn >= 0 {
switch {
case h < 0:
if unit <= time.Second {
unit += time.Hour
}
case d < 0 || w < 0:
if unit <= time.Second {
unit += time.Hour * 24
}
case d == 0 && w >= 0:
delta := time.Hour * 24 * time.Duration(int(w)-int(date.Weekday()))
if delta < 0 {
delta += time.Hour * 24 * 7
}
unit += delta
case m < 0:
unit = -1
}
} else {
unit = time.Minute
}
logrus.Debugln("[timer] unit:", unit)
stable := 0
if mn < 0 {
mn = int32(date.Minute())
}
if h < 0 {
h = int32(date.Hour())
} else {
stable |= 0x8
}
if d < 0 {
d = int32(date.Day())
} else if d > 0 {
stable |= 0x4
} else {
d = int32(date.Day())
if w >= 0 {
stable |= 0x2
}
}
if m < 0 {
m = int32(date.Month())
} else {
stable |= 0x1
}
switch stable {
case 0b0101:
if ts.Day != int32(time.Now().Day()) || ts.Month != int32(time.Now().Month()) {
h = 0
}
case 0b1001:
if ts.Month != int32(time.Now().Month()) {
d = 0
}
case 0b0001:
if ts.Month != int32(time.Now().Month()) {
d = 0
h = 0
}
}
logrus.Debugln("[timer] stable:", stable)
logrus.Debugln("[timer] m:", m, "d:", d, "h:", h, "mn:", mn, "w:", w)
date = time.Date(date.Year(), time.Month(m), int(d), int(h), int(mn), date.Second(), date.Nanosecond(), date.Location())
logrus.Debugln("[timer] date original:", date)
if unit > 0 {
date = date.Add(unit)
}
logrus.Debugln("[timer] date after add:", date)
if time.Until(date) <= 0 {
if ts.Month < 0 {
if ts.Day > 0 || (ts.Day == 0 && ts.Week >= 0) {
date = date.AddDate(0, 1, 0)
} else if ts.Day < 0 || ts.Week < 0 {
if ts.Hour > 0 {
date = date.AddDate(0, 0, 1)
} else if ts.Minute > 0 {
date = date.Add(time.Hour)
}
}
} else {
date = date.AddDate(1, 0, 0)
}
}
logrus.Debugln("[timer] date after fix:", date)
if stable&0x8 != 0 && date.Hour() != int(h) {
switch {
case stable&0x4 == 0:
date = date.AddDate(0, 0, 1).Add(-time.Hour)
case stable&0x2 == 0:
date = date.AddDate(0, 0, 7).Add(-time.Hour)
case stable*0x1 == 0:
date = date.AddDate(0, 1, 0).Add(-time.Hour)
default:
date = date.AddDate(1, 0, 0).Add(-time.Hour)
}
}
logrus.Debugln("[timer] date after s8:", date)
if stable&0x4 != 0 && date.Day() != int(d) {
switch {
case stable*0x1 == 0:
date = date.AddDate(0, 1, -1)
default:
date = date.AddDate(1, 0, -1)
}
}
logrus.Debugln("[timer] date after s4:", date)
if stable&0x2 != 0 && int32(date.Weekday()) != w {
switch {
case stable*0x1 == 0:
date = date.AddDate(0, 1, 0)
default:
date = date.AddDate(1, 0, 0)
}
date = firstWeek(&date, time.Weekday(w))
}
logrus.Debugln("[timer] date after s2:", date)
if time.Until(date) <= 0 {
date = time.Now().Add(time.Minute)
}
return date
}
func (ts *Timer) judgeHM() {
if ts.Hour < 0 || ts.Hour == int32(time.Now().Hour()) {
if ts.Minute < 0 || ts.Minute == int32(time.Now().Minute()) {
//zero.GetBot(zero.BotConfig.SelfID)
zero.RangeBot(func(id int64, ctx *zero.Ctx) bool {
ctx.Event = new(zero.Event)
ctx.Event.GroupID = int64(ts.Grpid)
if ts.Url == "" {
ctx.SendChain(atall, message.Text(ts.Alert))
} else {
ctx.SendChain(atall, message.Text(ts.Alert), message.Image(ts.Url).Add("cache", "0"))
}
return false
})
}
}
}
// RegisterTimer 注册计时器 // RegisterTimer 注册计时器
func (c *Clock) RegisterTimer(ts *Timer, save bool) { func (c *Clock) RegisterTimer(ts *Timer, grp int64, save bool) bool {
key := ts.GetTimerInfo() key := ts.GetTimerInfo(grp)
if c.timers != nil {
t, ok := c.GetTimer(key) t, ok := c.GetTimer(key)
if t != ts && ok { // 避免重复注册定时器 if t != ts && ok { // 避免重复注册定时器
t.Enable = false t.Enable = false
@ -219,8 +64,26 @@ func (c *Clock) RegisterTimer(ts *Timer, save bool) {
if save { if save {
c.SaveTimers() c.SaveTimers()
} }
}
logrus.Printf("[群管]注册计时器[%t]%s", ts.Enable, key) logrus.Printf("[群管]注册计时器[%t]%s", ts.Enable, key)
if ts.Cron != "" {
var ctx *zero.Ctx
if ts.Selfid != 0 {
ctx = zero.GetBot(ts.Selfid)
} else {
zero.RangeBot(func(id int64, c *zero.Ctx) bool {
ctx = c
ts.Selfid = id
return false
})
}
eid, err := c.cron.AddFunc(ts.Cron, func() { ts.sendmsg(grp, ctx) })
if err == nil {
c.entmu.Lock()
c.entries[key] = eid
c.entmu.Unlock()
return true
}
} else {
for ts.Enable { for ts.Enable {
nextdate := ts.nextWakeTime() nextdate := ts.nextWakeTime()
sleepsec := time.Until(nextdate) sleepsec := time.Until(nextdate)
@ -229,22 +92,32 @@ func (c *Clock) RegisterTimer(ts *Timer, save bool) {
if ts.Enable { if ts.Enable {
if ts.Month < 0 || ts.Month == int32(time.Now().Month()) { if ts.Month < 0 || ts.Month == int32(time.Now().Month()) {
if ts.Day < 0 || ts.Day == int32(time.Now().Day()) { if ts.Day < 0 || ts.Day == int32(time.Now().Day()) {
ts.judgeHM() ts.judgeHM(grp)
} else if ts.Day == 0 { } else if ts.Day == 0 {
if ts.Week < 0 || ts.Week == int32(time.Now().Weekday()) { if ts.Week < 0 || ts.Week == int32(time.Now().Weekday()) {
ts.judgeHM() ts.judgeHM(grp)
} }
} }
} }
} }
} }
} }
return false
}
// CancelTimer 取消计时器 // CancelTimer 取消计时器
func (c *Clock) CancelTimer(key string) bool { func (c *Clock) CancelTimer(key string) bool {
t, ok := (*c.timers)[key] t, ok := (*c.timers)[key]
if ok { if ok {
if t.Cron != "" {
c.entmu.Lock()
e := c.entries[key]
c.cron.Remove(e)
delete(c.entries, key)
c.entmu.Unlock()
} else {
t.Enable = false t.Enable = false
}
c.timersmu.Lock() c.timersmu.Lock()
delete(*c.timers, key) // 避免重复取消 delete(*c.timers, key) // 避免重复取消
c.timersmu.Unlock() c.timersmu.Unlock()
@ -308,140 +181,24 @@ func (c *Clock) loadTimers(pbfile string) {
if file.IsExist(pbfile) { if file.IsExist(pbfile) {
f, err := os.Open(pbfile) f, err := os.Open(pbfile)
if err == nil { if err == nil {
data, err1 := io.ReadAll(f) data, err := io.ReadAll(f)
if err1 == nil { if err == nil {
if len(data) > 0 { if len(data) > 0 {
c.timersmap.Unmarshal(data) err = c.timersmap.Unmarshal(data)
for _, t := range c.timersmap.Timers { if err == nil {
go c.RegisterTimer(t, false) for str, t := range c.timersmap.Timers {
grp, err := strconv.ParseInt(str[1:strings.Index(str, "]")], 10, 64)
if err == nil {
go c.RegisterTimer(t, grp, false)
}
} }
return return
} }
logrus.Errorln("[群管]读取定时器文件失败将在下一次保存时覆盖原文件。err:", err)
logrus.Errorln("[群管]如不希望被覆盖请运行源码plugin_manager/timers/migrate下的程序将timers.pb刷新为新版")
}
} }
} }
} }
c.timersmap.Timers = make(map[string]*Timer) c.timersmap.Timers = make(map[string]*Timer)
} }
// GetTimerInfo 获得标准化定时字符串
func (ts *Timer) GetTimerInfo() string {
return fmt.Sprintf("[%d]%d月%d日%d周%d:%d", ts.Grpid, ts.Month, ts.Day, ts.Week, ts.Hour, ts.Minute)
}
// GetFilledTimer 获得填充好的ts
func GetFilledTimer(dateStrs []string, matchDateOnly bool) *Timer {
monthStr := []rune(dateStrs[1])
dayWeekStr := []rune(dateStrs[2])
hourStr := []rune(dateStrs[3])
minuteStr := []rune(dateStrs[4])
var ts Timer
ts.Month = chineseNum2Int(monthStr)
if (ts.Month != -1 && ts.Month <= 0) || ts.Month > 12 { // 月份非法
logrus.Println("[群管]月份非法!")
return &ts
}
lenOfDW := len(dayWeekStr)
if lenOfDW == 4 { // 包括末尾的"日"
dayWeekStr = []rune{dayWeekStr[0], dayWeekStr[2]} // 去除中间的十
ts.Day = chineseNum2Int(dayWeekStr)
if (ts.Day != -1 && ts.Day <= 0) || ts.Day > 31 { // 日期非法
logrus.Println("[群管]日期非法1")
return &ts
}
} else if dayWeekStr[lenOfDW-1] == rune('日') { // xx日
dayWeekStr = dayWeekStr[:lenOfDW-1]
ts.Day = chineseNum2Int(dayWeekStr)
if (ts.Day != -1 && ts.Day <= 0) || ts.Day > 31 { // 日期非法
logrus.Println("[群管]日期非法2")
return &ts
}
} else if dayWeekStr[0] == rune('每') { // 每周
ts.Week = -1
} else { // 周x
ts.Week = chineseNum2Int(dayWeekStr[1:])
if ts.Week == 7 { // 周天是0
ts.Week = 0
}
if ts.Week < 0 || ts.Week > 6 { // 星期非法
ts.Week = -11
logrus.Println("[群管]星期非法!")
return &ts
}
}
if len(hourStr) == 3 {
hourStr = []rune{hourStr[0], hourStr[2]} // 去除中间的十
}
ts.Hour = chineseNum2Int(hourStr)
if ts.Hour < -1 || ts.Hour > 23 { // 小时非法
logrus.Println("[群管]小时非法!")
return &ts
}
if len(minuteStr) == 3 {
minuteStr = []rune{minuteStr[0], minuteStr[2]} // 去除中间的十
}
ts.Minute = chineseNum2Int(minuteStr)
if ts.Minute < -1 || ts.Minute > 59 { // 分钟非法
logrus.Println("[群管]分钟非法!")
return &ts
}
if !matchDateOnly {
urlStr := dateStrs[5]
if urlStr != "" { // 是图片url
ts.Url = urlStr[3:] // utf-8下用为3字节
logrus.Println("[群管]" + ts.Url)
if !strings.HasPrefix(ts.Url, "http") {
ts.Url = "illegal"
logrus.Println("[群管]url非法")
return &ts
}
}
ts.Alert = dateStrs[6]
ts.Enable = true
}
return &ts
}
// chineseNum2Int 汉字数字转int仅支持-1099最多两位数其中"每"解释为-1"每二"为-2以此类推
func chineseNum2Int(rs []rune) int32 {
r := -1
l := len(rs)
mai := rune('每')
if unicode.IsDigit(rs[0]) { // 默认可能存在的第二位也为int
r, _ = strconv.Atoi(string(rs))
} else {
if rs[0] == mai {
if l == 2 {
r = -chineseChar2Int(rs[1])
}
} else if l == 1 {
r = chineseChar2Int(rs[0])
} else {
ten := chineseChar2Int(rs[0])
if ten != 10 {
ten *= 10
}
ge := chineseChar2Int(rs[1])
if ge == 10 {
ge = 0
}
r = ten + ge
}
}
return int32(r)
}
// chineseChar2Int 处理单个字符的映射0~10
func chineseChar2Int(c rune) int {
if c == rune('日') || c == rune('天') { // 周日/周天
return 7
} else {
match := []rune("零一二三四五六七八九十")
for i, m := range match {
if c == m {
return i
}
}
return 0
}
}

View File

@ -26,12 +26,13 @@ type Timer struct {
Enable bool `protobuf:"varint,1,opt,name=enable,proto3" json:"enable,omitempty"` Enable bool `protobuf:"varint,1,opt,name=enable,proto3" json:"enable,omitempty"`
Alert string `protobuf:"bytes,2,opt,name=alert,proto3" json:"alert,omitempty"` Alert string `protobuf:"bytes,2,opt,name=alert,proto3" json:"alert,omitempty"`
Url string `protobuf:"bytes,3,opt,name=url,proto3" json:"url,omitempty"` Url string `protobuf:"bytes,3,opt,name=url,proto3" json:"url,omitempty"`
Month int32 `protobuf:"zigzag32,4,opt,name=month,proto3" json:"month,omitempty"` Month int32 `protobuf:"varint,4,opt,name=month,proto3" json:"month,omitempty"`
Day int32 `protobuf:"zigzag32,5,opt,name=day,proto3" json:"day,omitempty"` Day int32 `protobuf:"varint,5,opt,name=day,proto3" json:"day,omitempty"`
Week int32 `protobuf:"zigzag32,6,opt,name=week,proto3" json:"week,omitempty"` Week int32 `protobuf:"varint,6,opt,name=week,proto3" json:"week,omitempty"`
Hour int32 `protobuf:"zigzag32,7,opt,name=hour,proto3" json:"hour,omitempty"` Hour int32 `protobuf:"varint,7,opt,name=hour,proto3" json:"hour,omitempty"`
Minute int32 `protobuf:"zigzag32,8,opt,name=minute,proto3" json:"minute,omitempty"` Minute int32 `protobuf:"varint,8,opt,name=minute,proto3" json:"minute,omitempty"`
Grpid uint64 `protobuf:"varint,9,opt,name=grpid,proto3" json:"grpid,omitempty"` Selfid int64 `protobuf:"varint,9,opt,name=selfid,proto3" json:"selfid,omitempty"`
Cron string `protobuf:"bytes,10,opt,name=cron,proto3" json:"cron,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"` XXX_sizecache int32 `json:"-"`
@ -126,13 +127,20 @@ func (m *Timer) GetMinute() int32 {
return 0 return 0
} }
func (m *Timer) GetGrpid() uint64 { func (m *Timer) GetSelfid() int64 {
if m != nil { if m != nil {
return m.Grpid return m.Selfid
} }
return 0 return 0
} }
func (m *Timer) GetCron() string {
if m != nil {
return m.Cron
}
return ""
}
type TimersMap struct { type TimersMap struct {
Timers map[string]*Timer `protobuf:"bytes,1,rep,name=timers,proto3" json:"timers,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` Timers map[string]*Timer `protobuf:"bytes,1,rep,name=timers,proto3" json:"timers,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
@ -189,25 +197,26 @@ func init() {
func init() { proto.RegisterFile("timer.proto", fileDescriptor_ad0307ee16b652d2) } func init() { proto.RegisterFile("timer.proto", fileDescriptor_ad0307ee16b652d2) }
var fileDescriptor_ad0307ee16b652d2 = []byte{ var fileDescriptor_ad0307ee16b652d2 = []byte{
// 278 bytes of a gzipped FileDescriptorProto // 289 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0xcd, 0x4a, 0xc3, 0x40, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x91, 0xcf, 0x4a, 0xfb, 0x40,
0x10, 0xc7, 0x9d, 0xe6, 0xc3, 0x66, 0xe3, 0xa1, 0x2e, 0x22, 0x83, 0x48, 0x08, 0x39, 0xe5, 0xd4, 0x10, 0xc7, 0x7f, 0xd3, 0x74, 0xf3, 0x6b, 0x26, 0x1e, 0xca, 0x22, 0x32, 0x88, 0x84, 0xd0, 0x53,
0x43, 0xf5, 0x20, 0x1e, 0x05, 0xf1, 0xe4, 0x65, 0xf1, 0x05, 0x52, 0xba, 0xd8, 0xd0, 0x7c, 0xb1, 0x4e, 0x3d, 0x54, 0x0f, 0xe2, 0x51, 0x10, 0x4f, 0x5e, 0x16, 0x5f, 0x20, 0xb5, 0x2b, 0x2d, 0xcd,
0xdd, 0x28, 0x79, 0x05, 0x9f, 0xc0, 0x17, 0x12, 0x3c, 0xfa, 0x08, 0x12, 0x5f, 0x44, 0x66, 0x36, 0x9f, 0xb2, 0xd9, 0x28, 0x79, 0x05, 0x9f, 0xc0, 0x47, 0xf2, 0xe8, 0xdd, 0x8b, 0xc4, 0x17, 0x91,
0x94, 0xde, 0x7e, 0xff, 0x5f, 0xfe, 0x64, 0x67, 0x46, 0xc4, 0xb6, 0xac, 0xb5, 0x59, 0x76, 0xa6, 0x99, 0x04, 0xe9, 0xed, 0xf3, 0xfd, 0xe4, 0xcb, 0x32, 0x33, 0xc1, 0xd8, 0xef, 0x4a, 0xeb, 0x96,
0xb5, 0xad, 0x0c, 0x38, 0x64, 0x5f, 0x20, 0x82, 0x17, 0x22, 0x79, 0x29, 0x42, 0xdd, 0x14, 0xeb, 0x07, 0x57, 0xfb, 0x5a, 0x2b, 0x09, 0x8b, 0x2f, 0x40, 0xf5, 0xc8, 0xa4, 0xcf, 0x30, 0xb4, 0x55,
0x4a, 0x23, 0xa4, 0x90, 0xcf, 0xd5, 0x94, 0xe4, 0x85, 0x08, 0x8a, 0x4a, 0x1b, 0x8b, 0xb3, 0x14, 0xbe, 0x2e, 0x2c, 0x41, 0x0a, 0xd9, 0xcc, 0x8c, 0x49, 0x9f, 0xa2, 0xca, 0x0b, 0xeb, 0x3c, 0x4d,
0xf2, 0x48, 0xb9, 0x20, 0x17, 0xc2, 0xeb, 0x4d, 0x85, 0x1e, 0x3b, 0x42, 0xea, 0xd5, 0x6d, 0x63, 0x52, 0xc8, 0x22, 0x33, 0x04, 0x3d, 0xc7, 0xa0, 0x75, 0x05, 0x05, 0xe2, 0x18, 0xb9, 0x57, 0xd6,
0xb7, 0xe8, 0xa7, 0x90, 0x9f, 0x2b, 0x17, 0xa8, 0xb7, 0x29, 0x06, 0x0c, 0xd8, 0x11, 0x4a, 0x29, 0x95, 0xdf, 0xd2, 0x34, 0x85, 0x4c, 0x99, 0x21, 0x70, 0x6f, 0x93, 0x77, 0xa4, 0xc4, 0x31, 0x6a,
0xfc, 0x77, 0xad, 0x77, 0x18, 0xb2, 0x62, 0x26, 0xb7, 0x6d, 0x7b, 0x83, 0xa7, 0xce, 0x11, 0xd3, 0x8d, 0xd3, 0x57, 0x6b, 0xf7, 0x14, 0x8a, 0x12, 0x66, 0xb7, 0xad, 0x5b, 0x47, 0xff, 0x07, 0xc7,
0x3c, 0x75, 0xd9, 0xf4, 0x56, 0xe3, 0x9c, 0xed, 0x94, 0xe8, 0x9d, 0x57, 0xd3, 0x95, 0x1b, 0x8c, 0xcc, 0xf3, 0x94, 0xbb, 0xaa, 0xf5, 0x96, 0x66, 0x62, 0xc7, 0xc4, 0xbe, 0xb1, 0xc5, 0xf3, 0x6e,
0x52, 0xc8, 0x7d, 0xe5, 0x42, 0xf6, 0x01, 0x22, 0xe2, 0x3d, 0xf6, 0xcf, 0x45, 0x27, 0x6f, 0x45, 0x43, 0x51, 0x0a, 0x59, 0x60, 0xc6, 0xc4, 0x6f, 0x3c, 0xb9, 0xba, 0x22, 0x94, 0x91, 0x84, 0x17,
0xc8, 0xeb, 0xed, 0x11, 0x52, 0x2f, 0x8f, 0x57, 0xd7, 0x4b, 0xb7, 0xfa, 0xa1, 0x31, 0xd1, 0x63, 0x6f, 0x80, 0x91, 0x6c, 0xd7, 0x3c, 0xe4, 0x07, 0x7d, 0x85, 0xa1, 0x2c, 0xdd, 0x10, 0xa4, 0x41,
0x63, 0xcd, 0xa0, 0xa6, 0xee, 0xd5, 0x93, 0x88, 0x8f, 0x34, 0x8d, 0xbe, 0xd3, 0x03, 0x5f, 0x23, 0x16, 0xaf, 0x2e, 0x96, 0xc3, 0x41, 0xfe, 0x1a, 0x23, 0xdd, 0x55, 0xde, 0x75, 0x66, 0xec, 0x9e,
0x52, 0x84, 0x32, 0x13, 0xc1, 0x5b, 0x51, 0xf5, 0x9a, 0x4f, 0x11, 0xaf, 0xce, 0x8e, 0xff, 0xaa, 0xdf, 0x63, 0x7c, 0xa4, 0x79, 0xa1, 0xbd, 0xed, 0xe4, 0x46, 0x91, 0x61, 0xd4, 0x0b, 0x54, 0x2f,
0xdc, 0xa7, 0xfb, 0xd9, 0x1d, 0x3c, 0x2c, 0xbe, 0xc7, 0x04, 0x7e, 0xc6, 0x04, 0x7e, 0xc7, 0x04, 0x79, 0xd1, 0x5a, 0x39, 0x50, 0xbc, 0x3a, 0x39, 0x7e, 0xd5, 0x0c, 0x9f, 0x6e, 0x26, 0xd7, 0x70,
0x3e, 0xff, 0x92, 0x93, 0x75, 0xc8, 0x47, 0xbf, 0xf9, 0x0f, 0x00, 0x00, 0xff, 0xff, 0xe0, 0xc7, 0x3b, 0xff, 0xe8, 0x13, 0xf8, 0xec, 0x13, 0xf8, 0xee, 0x13, 0x78, 0xff, 0x49, 0xfe, 0xad, 0x43,
0xad, 0xf8, 0x83, 0x01, 0x00, 0x00, 0xf9, 0x15, 0x97, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, 0x7b, 0xe3, 0x45, 0x55, 0x99, 0x01, 0x00,
0x00,
} }
func (m *Timer) Marshal() (dAtA []byte, err error) { func (m *Timer) Marshal() (dAtA []byte, err error) {
@ -234,33 +243,40 @@ func (m *Timer) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i -= len(m.XXX_unrecognized) i -= len(m.XXX_unrecognized)
copy(dAtA[i:], m.XXX_unrecognized) copy(dAtA[i:], m.XXX_unrecognized)
} }
if m.Grpid != 0 { if len(m.Cron) > 0 {
i = encodeVarintTimer(dAtA, i, uint64(m.Grpid)) i -= len(m.Cron)
copy(dAtA[i:], m.Cron)
i = encodeVarintTimer(dAtA, i, uint64(len(m.Cron)))
i--
dAtA[i] = 0x52
}
if m.Selfid != 0 {
i = encodeVarintTimer(dAtA, i, uint64(m.Selfid))
i-- i--
dAtA[i] = 0x48 dAtA[i] = 0x48
} }
if m.Minute != 0 { if m.Minute != 0 {
i = encodeVarintTimer(dAtA, i, uint64((uint32(m.Minute)<<1)^uint32((m.Minute>>31)))) i = encodeVarintTimer(dAtA, i, uint64(m.Minute))
i-- i--
dAtA[i] = 0x40 dAtA[i] = 0x40
} }
if m.Hour != 0 { if m.Hour != 0 {
i = encodeVarintTimer(dAtA, i, uint64((uint32(m.Hour)<<1)^uint32((m.Hour>>31)))) i = encodeVarintTimer(dAtA, i, uint64(m.Hour))
i-- i--
dAtA[i] = 0x38 dAtA[i] = 0x38
} }
if m.Week != 0 { if m.Week != 0 {
i = encodeVarintTimer(dAtA, i, uint64((uint32(m.Week)<<1)^uint32((m.Week>>31)))) i = encodeVarintTimer(dAtA, i, uint64(m.Week))
i-- i--
dAtA[i] = 0x30 dAtA[i] = 0x30
} }
if m.Day != 0 { if m.Day != 0 {
i = encodeVarintTimer(dAtA, i, uint64((uint32(m.Day)<<1)^uint32((m.Day>>31)))) i = encodeVarintTimer(dAtA, i, uint64(m.Day))
i-- i--
dAtA[i] = 0x28 dAtA[i] = 0x28
} }
if m.Month != 0 { if m.Month != 0 {
i = encodeVarintTimer(dAtA, i, uint64((uint32(m.Month)<<1)^uint32((m.Month>>31)))) i = encodeVarintTimer(dAtA, i, uint64(m.Month))
i-- i--
dAtA[i] = 0x20 dAtA[i] = 0x20
} }
@ -373,22 +389,26 @@ func (m *Timer) Size() (n int) {
n += 1 + l + sovTimer(uint64(l)) n += 1 + l + sovTimer(uint64(l))
} }
if m.Month != 0 { if m.Month != 0 {
n += 1 + sozTimer(uint64(m.Month)) n += 1 + sovTimer(uint64(m.Month))
} }
if m.Day != 0 { if m.Day != 0 {
n += 1 + sozTimer(uint64(m.Day)) n += 1 + sovTimer(uint64(m.Day))
} }
if m.Week != 0 { if m.Week != 0 {
n += 1 + sozTimer(uint64(m.Week)) n += 1 + sovTimer(uint64(m.Week))
} }
if m.Hour != 0 { if m.Hour != 0 {
n += 1 + sozTimer(uint64(m.Hour)) n += 1 + sovTimer(uint64(m.Hour))
} }
if m.Minute != 0 { if m.Minute != 0 {
n += 1 + sozTimer(uint64(m.Minute)) n += 1 + sovTimer(uint64(m.Minute))
} }
if m.Grpid != 0 { if m.Selfid != 0 {
n += 1 + sovTimer(uint64(m.Grpid)) n += 1 + sovTimer(uint64(m.Selfid))
}
l = len(m.Cron)
if l > 0 {
n += 1 + l + sovTimer(uint64(l))
} }
if m.XXX_unrecognized != nil { if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized) n += len(m.XXX_unrecognized)
@ -544,7 +564,7 @@ func (m *Timer) Unmarshal(dAtA []byte) error {
if wireType != 0 { if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Month", wireType) return fmt.Errorf("proto: wrong wireType = %d for field Month", wireType)
} }
var v int32 m.Month = 0
for shift := uint(0); ; shift += 7 { for shift := uint(0); ; shift += 7 {
if shift >= 64 { if shift >= 64 {
return ErrIntOverflowTimer return ErrIntOverflowTimer
@ -554,18 +574,16 @@ func (m *Timer) Unmarshal(dAtA []byte) error {
} }
b := dAtA[iNdEx] b := dAtA[iNdEx]
iNdEx++ iNdEx++
v |= int32(b&0x7F) << shift m.Month |= int32(b&0x7F) << shift
if b < 0x80 { if b < 0x80 {
break break
} }
} }
v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31))
m.Month = v
case 5: case 5:
if wireType != 0 { if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Day", wireType) return fmt.Errorf("proto: wrong wireType = %d for field Day", wireType)
} }
var v int32 m.Day = 0
for shift := uint(0); ; shift += 7 { for shift := uint(0); ; shift += 7 {
if shift >= 64 { if shift >= 64 {
return ErrIntOverflowTimer return ErrIntOverflowTimer
@ -575,18 +593,16 @@ func (m *Timer) Unmarshal(dAtA []byte) error {
} }
b := dAtA[iNdEx] b := dAtA[iNdEx]
iNdEx++ iNdEx++
v |= int32(b&0x7F) << shift m.Day |= int32(b&0x7F) << shift
if b < 0x80 { if b < 0x80 {
break break
} }
} }
v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31))
m.Day = v
case 6: case 6:
if wireType != 0 { if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Week", wireType) return fmt.Errorf("proto: wrong wireType = %d for field Week", wireType)
} }
var v int32 m.Week = 0
for shift := uint(0); ; shift += 7 { for shift := uint(0); ; shift += 7 {
if shift >= 64 { if shift >= 64 {
return ErrIntOverflowTimer return ErrIntOverflowTimer
@ -596,18 +612,16 @@ func (m *Timer) Unmarshal(dAtA []byte) error {
} }
b := dAtA[iNdEx] b := dAtA[iNdEx]
iNdEx++ iNdEx++
v |= int32(b&0x7F) << shift m.Week |= int32(b&0x7F) << shift
if b < 0x80 { if b < 0x80 {
break break
} }
} }
v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31))
m.Week = v
case 7: case 7:
if wireType != 0 { if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Hour", wireType) return fmt.Errorf("proto: wrong wireType = %d for field Hour", wireType)
} }
var v int32 m.Hour = 0
for shift := uint(0); ; shift += 7 { for shift := uint(0); ; shift += 7 {
if shift >= 64 { if shift >= 64 {
return ErrIntOverflowTimer return ErrIntOverflowTimer
@ -617,18 +631,16 @@ func (m *Timer) Unmarshal(dAtA []byte) error {
} }
b := dAtA[iNdEx] b := dAtA[iNdEx]
iNdEx++ iNdEx++
v |= int32(b&0x7F) << shift m.Hour |= int32(b&0x7F) << shift
if b < 0x80 { if b < 0x80 {
break break
} }
} }
v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31))
m.Hour = v
case 8: case 8:
if wireType != 0 { if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Minute", wireType) return fmt.Errorf("proto: wrong wireType = %d for field Minute", wireType)
} }
var v int32 m.Minute = 0
for shift := uint(0); ; shift += 7 { for shift := uint(0); ; shift += 7 {
if shift >= 64 { if shift >= 64 {
return ErrIntOverflowTimer return ErrIntOverflowTimer
@ -638,18 +650,16 @@ func (m *Timer) Unmarshal(dAtA []byte) error {
} }
b := dAtA[iNdEx] b := dAtA[iNdEx]
iNdEx++ iNdEx++
v |= int32(b&0x7F) << shift m.Minute |= int32(b&0x7F) << shift
if b < 0x80 { if b < 0x80 {
break break
} }
} }
v = int32((uint32(v) >> 1) ^ uint32(((v&1)<<31)>>31))
m.Minute = v
case 9: case 9:
if wireType != 0 { if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Grpid", wireType) return fmt.Errorf("proto: wrong wireType = %d for field Selfid", wireType)
} }
m.Grpid = 0 m.Selfid = 0
for shift := uint(0); ; shift += 7 { for shift := uint(0); ; shift += 7 {
if shift >= 64 { if shift >= 64 {
return ErrIntOverflowTimer return ErrIntOverflowTimer
@ -659,11 +669,43 @@ func (m *Timer) Unmarshal(dAtA []byte) error {
} }
b := dAtA[iNdEx] b := dAtA[iNdEx]
iNdEx++ iNdEx++
m.Grpid |= uint64(b&0x7F) << shift m.Selfid |= int64(b&0x7F) << shift
if b < 0x80 { if b < 0x80 {
break break
} }
} }
case 10:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Cron", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowTimer
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthTimer
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthTimer
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Cron = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default: default:
iNdEx = preIndex iNdEx = preIndex
skippy, err := skipTimer(dAtA[iNdEx:]) skippy, err := skipTimer(dAtA[iNdEx:])

View File

@ -5,12 +5,13 @@ message Timer {
bool enable = 1; bool enable = 1;
string alert = 2; string alert = 2;
string url = 3; string url = 3;
sint32 month = 4; int32 month = 4;
sint32 day = 5; int32 day = 5;
sint32 week = 6; int32 week = 6;
sint32 hour = 7; int32 hour = 7;
sint32 minute = 8; int32 minute = 8;
uint64 grpid = 9; int64 selfid = 9;
string cron = 10;
} }
message TimersMap { message TimersMap {