From 77aeb38927d8b3e0e0990185e19a2bb6472ff28c Mon Sep 17 00:00:00 2001 From: fumiama Date: Sun, 6 Jun 2021 01:19:48 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=8C=96utils=E3=80=81?= =?UTF-8?q?=E5=BC=95=E5=85=A5protobuf?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/timer/timer.pb.go | 916 ++++++++++++++++++++++++++++++++++ api/timer/timer.proto | 17 + api/{pixiv => utils}/utils.go | 2 +- go.mod | 13 +- go.sum | 55 +- main.go | 4 +- manager/manager.go | 10 +- manager/timer.go | 115 +++-- picsearcher/utils/ascii2d.go | 3 +- setutime/setu_geter.go | 13 +- 10 files changed, 1068 insertions(+), 80 deletions(-) create mode 100644 api/timer/timer.pb.go create mode 100644 api/timer/timer.proto rename api/{pixiv => utils}/utils.go (98%) diff --git a/api/timer/timer.pb.go b/api/timer/timer.pb.go new file mode 100644 index 00000000..e4ae608f --- /dev/null +++ b/api/timer/timer.pb.go @@ -0,0 +1,916 @@ +// Code generated by protoc-gen-gogo. DO NOT EDIT. +// source: timer.proto + +package timer + +import ( + fmt "fmt" + proto "github.com/golang/protobuf/proto" + io "io" + math "math" + math_bits "math/bits" +) + +// 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:"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"` + 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 +} + +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{ + // 267 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0x4f, 0x4a, 0xc3, 0x40, + 0x14, 0xc6, 0x7d, 0x4d, 0x27, 0x36, 0x2f, 0x2e, 0xea, 0x20, 0x32, 0x88, 0x84, 0x90, 0x55, 0x56, + 0x5d, 0x54, 0x17, 0xe2, 0x52, 0x10, 0x57, 0x6e, 0x06, 0x2f, 0x30, 0xc5, 0x81, 0x96, 0xe6, 0x4f, + 0x99, 0x4e, 0x94, 0x5c, 0xc1, 0x13, 0x78, 0x0b, 0xaf, 0xe1, 0xd2, 0x23, 0x48, 0xbc, 0x88, 0xbc, + 0x37, 0xa1, 0x74, 0xf7, 0xfb, 0x7e, 0xf9, 0x08, 0xef, 0x1b, 0x4c, 0xfd, 0xa6, 0xb6, 0x6e, 0xb1, + 0x73, 0xad, 0x6f, 0xa5, 0xe0, 0x50, 0x7c, 0x01, 0x8a, 0x17, 0x22, 0x79, 0x89, 0xb1, 0x6d, 0xcc, + 0xaa, 0xb2, 0x0a, 0x72, 0x28, 0x67, 0x7a, 0x4c, 0xf2, 0x02, 0x85, 0xa9, 0xac, 0xf3, 0x6a, 0x92, + 0x43, 0x99, 0xe8, 0x10, 0xe4, 0x1c, 0xa3, 0xce, 0x55, 0x2a, 0x62, 0x47, 0x48, 0xbd, 0xba, 0x6d, + 0xfc, 0x5a, 0x4d, 0x73, 0x28, 0xcf, 0x75, 0x08, 0xd4, 0x7b, 0x35, 0xbd, 0x12, 0xec, 0x08, 0xa5, + 0xc4, 0xe9, 0xbb, 0xb5, 0x5b, 0x15, 0xb3, 0x62, 0x26, 0xb7, 0x6e, 0x3b, 0xa7, 0x4e, 0x83, 0x23, + 0xa6, 0x7b, 0xea, 0x4d, 0xd3, 0x79, 0xab, 0x66, 0x6c, 0xc7, 0x54, 0x7c, 0x00, 0x26, 0x7c, 0xf1, + 0xfe, 0xd9, 0xec, 0xe4, 0x2d, 0xc6, 0x3c, 0x64, 0xaf, 0x20, 0x8f, 0xca, 0x74, 0x79, 0xbd, 0x08, + 0x23, 0x0f, 0x8d, 0x91, 0x1e, 0x1b, 0xef, 0x7a, 0x3d, 0x76, 0xaf, 0x9e, 0x30, 0x3d, 0xd2, 0x74, + 0xe4, 0xd6, 0xf6, 0xbc, 0x3b, 0xd1, 0x84, 0xb2, 0x40, 0xf1, 0x66, 0xaa, 0xce, 0xf2, 0xe8, 0x74, + 0x79, 0x76, 0xfc, 0x57, 0x1d, 0x3e, 0xdd, 0x4f, 0xee, 0xe0, 0x61, 0xfe, 0x3d, 0x64, 0xf0, 0x33, + 0x64, 0xf0, 0x3b, 0x64, 0xf0, 0xf9, 0x97, 0x9d, 0xac, 0x62, 0x7e, 0xde, 0x9b, 0xff, 0x00, 0x00, + 0x00, 0xff, 0xff, 0x8f, 0x73, 0x63, 0x18, 0x6d, 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 m.Minute != 0 { + i = encodeVarintTimer(dAtA, i, uint64((uint32(m.Minute)<<1)^uint32((m.Minute>>31)))) + i-- + dAtA[i] = 0x40 + } + if m.Hour != 0 { + i = encodeVarintTimer(dAtA, i, uint64((uint32(m.Hour)<<1)^uint32((m.Hour>>31)))) + i-- + dAtA[i] = 0x38 + } + if m.Week != 0 { + i = encodeVarintTimer(dAtA, i, uint64((uint32(m.Week)<<1)^uint32((m.Week>>31)))) + i-- + dAtA[i] = 0x30 + } + if m.Day != 0 { + i = encodeVarintTimer(dAtA, i, uint64((uint32(m.Day)<<1)^uint32((m.Day>>31)))) + i-- + dAtA[i] = 0x28 + } + if m.Month != 0 { + i = encodeVarintTimer(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 = 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 + sozTimer(uint64(m.Month)) + } + if m.Day != 0 { + n += 1 + sozTimer(uint64(m.Day)) + } + if m.Week != 0 { + n += 1 + sozTimer(uint64(m.Week)) + } + if m.Hour != 0 { + n += 1 + sozTimer(uint64(m.Hour)) + } + if m.Minute != 0 { + n += 1 + sozTimer(uint64(m.Minute)) + } + 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) + } + var v int32 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTimer + } + 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 ErrIntOverflowTimer + } + 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 ErrIntOverflowTimer + } + 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 ErrIntOverflowTimer + } + 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 ErrIntOverflowTimer + } + 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 + 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") +) diff --git a/api/timer/timer.proto b/api/timer/timer.proto new file mode 100644 index 00000000..aa2b3a60 --- /dev/null +++ b/api/timer/timer.proto @@ -0,0 +1,17 @@ +syntax = "proto3"; +package timer; + +message Timer { + bool enable = 1; + string alert = 2; + string url = 3; + sint32 month = 4; + sint32 day = 5; + sint32 week = 6; + sint32 hour = 7; + sint32 minute = 8; +} + +message TimersMap { + map timers = 1; +} \ No newline at end of file diff --git a/api/pixiv/utils.go b/api/utils/utils.go similarity index 98% rename from api/pixiv/utils.go rename to api/utils/utils.go index 21e1733d..e4c4013c 100644 --- a/api/pixiv/utils.go +++ b/api/utils/utils.go @@ -1,4 +1,4 @@ -package pixiv +package utils import ( "os" diff --git a/go.mod b/go.mod index 615440ec..61d9028c 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,16 @@ go 1.15 require ( github.com/antchfx/htmlquery v1.2.3 - github.com/mattn/go-sqlite3 v1.14.6 + github.com/antchfx/xpath v1.2.0 // indirect + github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/protobuf v1.5.2 + github.com/mattn/go-sqlite3 v1.14.7 + github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/sirupsen/logrus v1.8.1 github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 - github.com/tidwall/gjson v1.7.4 - github.com/wdvxdr1123/ZeroBot v1.1.2 + github.com/tidwall/gjson v1.8.0 + github.com/tidwall/pretty v1.1.1 // indirect + github.com/wdvxdr1123/ZeroBot v1.2.0 + golang.org/x/net v0.0.0-20210525063256-abc453219eb5 // indirect + golang.org/x/sys v0.0.0-20210603125802-9665404d3644 // indirect ) diff --git a/go.sum b/go.sum index 254ee7f5..e8ced15e 100644 --- a/go.sum +++ b/go.sum @@ -1,29 +1,37 @@ github.com/antchfx/htmlquery v1.2.3 h1:sP3NFDneHx2stfNXCKbhHFo8XgNjCACnU/4AO5gWz6M= github.com/antchfx/htmlquery v1.2.3/go.mod h1:B0ABL+F5irhhMWg54ymEZinzMSi0Kt3I2if0BLYa3V0= -github.com/antchfx/xpath v1.1.6 h1:6sVh6hB5T6phw1pFpHRQ+C4bd8sNI+O58flqtg7h0R0= github.com/antchfx/xpath v1.1.6/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk= +github.com/antchfx/xpath v1.2.0 h1:mbwv7co+x0RwgeGAOHdrKy89GvHaGvxxBtPK0uF9Zr8= +github.com/antchfx/xpath v1.2.0/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e h1:1r7pUrabqp18hOBcwBwiTsbnFeTZHV9eER/QT5JVZxY= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= +github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc= github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= -github.com/json-iterator/go v1.1.10 h1:Kz6Cvnvv2wGdaG/V8yMvfkmNiXq9Ya2KUv4rouJJr68= -github.com/json-iterator/go v1.1.10/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/json-iterator/go v1.1.11 h1:uVUAXhF2To8cbw/3xN3pxj6kk7TYKs98NIrTqPlMWAQ= +github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg= -github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= -github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc= +github.com/mattn/go-sqlite3 v1.14.7 h1:fxWBnXkxfM6sRiuH3bqJ4CfzZojMOLVc0UTsTglEghA= +github.com/mattn/go-sqlite3 v1.14.7/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= -github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI= -github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/modern-go/reflect2 v1.0.2-0.20210109003243-333559e1834b h1:6Xjqolv/0DDdUqlpnsTomXQvjvvkz7Ux7TcMALvozEw= +github.com/modern-go/reflect2 v1.0.2-0.20210109003243-333559e1834b/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= @@ -41,27 +49,40 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 h1:J6v8awz+me+xeb/cUTotKgceAYouhIB3pjzgRd6IlGk= github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go.mod h1:tzym/CEb5jnFI+Q0k4Qq3+LvRF4gO3E2pxS8fHP8jcA= -github.com/tidwall/gjson v1.7.4 h1:19cchw8FOxkG5mdLRkGf9jqIqEyqdZhPqW60XfyFxk8= -github.com/tidwall/gjson v1.7.4/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk= +github.com/tidwall/gjson v1.8.0 h1:Qt+orfosKn0rbNTZqHYDqBrmm3UDA4KRkv70fDzG+PQ= +github.com/tidwall/gjson v1.8.0/go.mod h1:5/xDoumyyDNerp2U36lyolv46b3uF/9Bu6OfyQ9GImk= github.com/tidwall/match v1.0.3 h1:FQUVvBImDutD8wJLN6c5eMzWtjgONK9MwIBCOrUJKeE= github.com/tidwall/match v1.0.3/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= -github.com/tidwall/pretty v1.1.0 h1:K3hMW5epkdAVwibsQEfR/7Zj0Qgt4DxtNumTq/VloO8= github.com/tidwall/pretty v1.1.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= -github.com/wdvxdr1123/ZeroBot v1.1.2 h1:SGl7lSdFatdSCcVPXTIC56xoMUtXwyz1xWBSkPOAgEU= -github.com/wdvxdr1123/ZeroBot v1.1.2/go.mod h1:N4bGSEHCKOrplRHNM8XJFXcXFsK0OUSvmTVakomS+k8= +github.com/tidwall/pretty v1.1.1 h1:nt6/Ot5LtZnJCWwEFlelOixPo0xhPFsuZlKyOL3Xfnc= +github.com/tidwall/pretty v1.1.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= +github.com/wdvxdr1123/ZeroBot v1.2.0 h1:GmCkbzMMq3iugViKDtLbsL7joi29uG3/tp1554nboWI= +github.com/wdvxdr1123/ZeroBot v1.2.0/go.mod h1:83nHtG8V5TAxPwH/LCDxLpZk4khIgs29dkr5TBWf7fc= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= -golang.org/x/net v0.0.0-20200421231249-e086a090c8fd h1:QPwSajcTUrFriMF1nJ3XzgoqakqQEsnZf9LdXdi2nkI= golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5 h1:wjuX4b5yYQnEQHzd+CBcrcC6OVR2J1CN6mUy0oSxIPo= +golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210603125802-9665404d3644 h1:CA1DEQ4NdKphKeL70tvsWNdT5oFh1lOjihRcEDROi0I= +golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= diff --git a/main.go b/main.go index e6fbb5ae..7256cf3f 100644 --- a/main.go +++ b/main.go @@ -27,8 +27,8 @@ import ( _ "github.com/Yiwen-Chan/ZeroBot-Plugin/picsearcher" // 搜图 _ "github.com/Yiwen-Chan/ZeroBot-Plugin/randimg" //简易随机图片 - _ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime" // 涩图 - _ "github.com/Yiwen-Chan/ZeroBot-Plugin/shindan" // 测定 + //_ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime" // 涩图 + _ "github.com/Yiwen-Chan/ZeroBot-Plugin/shindan" // 测定 ) func init() { diff --git a/manager/manager.go b/manager/manager.go index 31dbe9a8..33bd4952 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -236,12 +236,12 @@ func init() { // 插件主体 Handle(func(ctx *zero.Ctx) { dateStrs := ctx.State["regex_matched"].([]string) ts := getFilledTimeStamp(dateStrs, false) - if ts.enable { + if ts.Enable { go timer(ts, func() { - if ts.url == "" { - ctx.SendChain(msgext.AtAll(), message.Text(ts.alert)) + if ts.Url == "" { + ctx.SendChain(msgext.AtAll(), message.Text(ts.Alert)) } else { - ctx.SendChain(msgext.AtAll(), message.Text(ts.alert), msgext.ImageNoCache(ts.url)) + ctx.SendChain(msgext.AtAll(), message.Text(ts.Alert), msgext.ImageNoCache(ts.Url)) } }) ctx.Send("记住了~") @@ -258,7 +258,7 @@ func init() { // 插件主体 ti := getTimerInfo(&ts) t, ok := timers[ti] if ok { - t.enable = false + t.Enable = false delete(timers, ti) //避免重复取消 ctx.Send("取消成功~") } else { diff --git a/manager/timer.go b/manager/timer.go index 5bed7bae..e8737d80 100644 --- a/manager/timer.go +++ b/manager/timer.go @@ -2,47 +2,54 @@ package manager import ( "fmt" + "os" "strconv" "strings" "time" "unicode" + + tm "github.com/Yiwen-Chan/ZeroBot-Plugin/api/timer" + "github.com/Yiwen-Chan/ZeroBot-Plugin/api/utils" ) -type TimeStamp struct { - enable bool - alert string - url string - month int8 - day int8 - week int8 - hour int8 - minute int8 -} +type TimeStamp = tm.Timer -//记录每个定时器以便取消 -var timers = make(map[string]*TimeStamp) +var ( + //记录每个定时器以便取消 + timersmap tm.TimersMap + timers = timersmap.Timers + //定时器存储位置 + BOTPATH = utils.PathExecute() // 当前bot运行目录 + DATAPATH = BOTPATH + "data/manager/" // 数据目录 + PBFILE = DATAPATH + "timers.pb" +) + +func init() { + utils.CreatePath(DATAPATH) +} func timer(ts TimeStamp, onTimeReached func()) { key := getTimerInfo(&ts) fmt.Printf("[群管]注册计时器: %s\n", key) t, ok := timers[key] if ok { //避免重复注册定时器 - t.enable = false + t.Enable = false } timers[key] = &ts + saveTimers() judgeHM := func() { - if ts.hour < 0 || ts.hour == int8(time.Now().Hour()) { - if ts.minute < 0 || ts.minute == int8(time.Now().Minute()) { + if ts.Hour < 0 || ts.Hour == int32(time.Now().Hour()) { + if ts.Minute < 0 || ts.Minute == int32(time.Now().Minute()) { onTimeReached() } } } - for ts.enable { - if ts.month < 0 || ts.month == int8(time.Now().Month()) { - if ts.day < 0 || ts.day == int8(time.Now().Day()) { + for ts.Enable { + if ts.Month < 0 || ts.Month == int32(time.Now().Month()) { + if ts.Day < 0 || ts.Day == int32(time.Now().Day()) { judgeHM() - } else if ts.day == 0 { - if ts.week < 0 || ts.week == int8(time.Now().Weekday()) { + } else if ts.Day == 0 { + if ts.Week < 0 || ts.Week == int32(time.Now().Weekday()) { judgeHM() } } @@ -51,9 +58,27 @@ func timer(ts TimeStamp, onTimeReached func()) { } } +func saveTimers() error { + data, err := timersmap.Marshal() + if err != nil { + return err + } else if utils.PathExists(DATAPATH) { + f, err1 := os.OpenFile(PBFILE, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) + if err1 != nil { + return err1 + } else { + defer f.Close() + _, err2 := f.Write(data) + return err2 + } + } else { + return nil + } +} + //获得标准化定时字符串 func getTimerInfo(ts *TimeStamp) string { - return fmt.Sprintf("%d月%d日%d周%d:%d", ts.month, ts.day, ts.week, ts.hour, ts.minute) + return fmt.Sprintf("%d月%d日%d周%d:%d", ts.Month, ts.Day, ts.Week, ts.Hour, ts.Minute) } //获得填充好的ts @@ -64,35 +89,35 @@ func getFilledTimeStamp(dateStrs []string, matchDateOnly bool) TimeStamp { minuteStr := []rune(dateStrs[4]) var ts TimeStamp - ts.month = chineseNum2Int(monthStr) - if (ts.month != -1 && ts.month <= 0) || ts.month > 12 { //月份非法 + ts.Month = chineseNum2Int(monthStr) + if (ts.Month != -1 && ts.Month <= 0) || ts.Month > 12 { //月份非法 fmt.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 { //日期非法 + ts.Day = chineseNum2Int(dayWeekStr) + if (ts.Day != -1 && ts.Day <= 0) || ts.Day > 31 { //日期非法 fmt.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 { //日期非法 + ts.Day = chineseNum2Int(dayWeekStr) + if (ts.Day != -1 && ts.Day <= 0) || ts.Day > 31 { //日期非法 fmt.Println("[群管]日期非法2!") return ts } } else if dayWeekStr[0] == rune('每') { //每周 - ts.week = -1 + ts.Week = -1 } else { //周x - ts.week = chineseNum2Int(dayWeekStr[1:]) - if ts.week == 7 { //周天是0 - ts.week = 0 + ts.Week = chineseNum2Int(dayWeekStr[1:]) + if ts.Week == 7 { //周天是0 + ts.Week = 0 } - if ts.week < 0 || ts.week > 6 { //星期非法 - ts.week = -11 + if ts.Week < 0 || ts.Week > 6 { //星期非法 + ts.Week = -11 fmt.Println("[群管]星期非法!") return ts } @@ -100,38 +125,38 @@ func getFilledTimeStamp(dateStrs []string, matchDateOnly bool) TimeStamp { if len(hourStr) == 3 { hourStr = []rune{hourStr[0], hourStr[2]} //去除中间的十 } - ts.hour = chineseNum2Int(hourStr) - if ts.hour < -1 || ts.hour > 23 { //小时非法 + ts.Hour = chineseNum2Int(hourStr) + if ts.Hour < -1 || ts.Hour > 23 { //小时非法 fmt.Println("[群管]小时非法!") return ts } if len(minuteStr) == 3 { minuteStr = []rune{minuteStr[0], minuteStr[2]} //去除中间的十 } - ts.minute = chineseNum2Int(minuteStr) - if ts.minute < -1 || ts.minute > 59 { //分钟非法 + ts.Minute = chineseNum2Int(minuteStr) + if ts.Minute < -1 || ts.Minute > 59 { //分钟非法 fmt.Println("[群管]分钟非法!") return ts } if !matchDateOnly { urlStr := dateStrs[5] if urlStr != "" { //是图片url - ts.url = urlStr[3:] //utf-8下用为3字节 - fmt.Println("[群管]" + ts.url) - if !strings.HasPrefix(ts.url, "http") { - ts.url = "illegal" + ts.Url = urlStr[3:] //utf-8下用为3字节 + fmt.Println("[群管]" + ts.Url) + if !strings.HasPrefix(ts.Url, "http") { + ts.Url = "illegal" fmt.Println("[群管]url非法!") return ts } } - ts.alert = dateStrs[6] - ts.enable = true + ts.Alert = dateStrs[6] + ts.Enable = true } return ts } //汉字数字转int,仅支持-10~99,最多两位数,其中"每"解释为-1,"每两"为-2,以此类推 -func chineseNum2Int(rs []rune) int8 { +func chineseNum2Int(rs []rune) int32 { r := -1 l := len(rs) mai := rune('每') @@ -156,7 +181,7 @@ func chineseNum2Int(rs []rune) int8 { r = ten + ge } } - return int8(r) + return int32(r) } //处理单个字符的映射0~10 diff --git a/picsearcher/utils/ascii2d.go b/picsearcher/utils/ascii2d.go index d4c3a6ef..4258b9a6 100644 --- a/picsearcher/utils/ascii2d.go +++ b/picsearcher/utils/ascii2d.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/Yiwen-Chan/ZeroBot-Plugin/api/pixiv" + "github.com/Yiwen-Chan/ZeroBot-Plugin/api/utils" xpath "github.com/antchfx/htmlquery" "github.com/wdvxdr1123/ZeroBot/message" ) @@ -72,7 +73,7 @@ func Ascii2dSearch(pic string) (message.Message, error) { if link == "" || index == -1 { return nil, fmt.Errorf("Ascii2d not found") } - var id = pixiv.Str2Int(link[index+1:]) + var id = utils.Str2Int(link[index+1:]) if id == 0 { return nil, fmt.Errorf("convert to pid error") } diff --git a/setutime/setu_geter.go b/setutime/setu_geter.go index cb0a44fa..7db33b32 100644 --- a/setutime/setu_geter.go +++ b/setutime/setu_geter.go @@ -10,13 +10,14 @@ import ( "github.com/wdvxdr1123/ZeroBot/extension/rate" "github.com/Yiwen-Chan/ZeroBot-Plugin/api/pixiv" + apiutils "github.com/Yiwen-Chan/ZeroBot-Plugin/api/utils" "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime/utils" ) var limit = rate.NewManager(time.Minute*1, 5) var ( - BOTPATH = pixiv.PathExecute() // 当前bot运行目录 + BOTPATH = apiutils.PathExecute() // 当前bot运行目录 DATAPATH = BOTPATH + "data/SetuTime/" // 数据目录 DBPATH = DATAPATH + "SetuTime.db" // 数据库路径 @@ -34,8 +35,8 @@ func init() { PoolsCache.Group = CACHEGROUP // 图片缓冲群 PoolsCache.Path = CACHEPATH // 缓冲图片路径 - pixiv.CreatePath(DBPATH) - pixiv.CreatePath(CACHEPATH) + apiutils.CreatePath(DBPATH) + apiutils.CreatePath(CACHEPATH) for i := range PoolList { if err := DB.Create(PoolList[i], &pixiv.Illust{}); err != nil { @@ -54,7 +55,7 @@ func init() { // 插件主体 var type_ = ctx.State["regex_matched"].([]string)[1] // 补充池子 go func() { - times := pixiv.Min(PoolsCache.Max-PoolsCache.Size(type_), 2) + times := apiutils.Min(PoolsCache.Max-PoolsCache.Size(type_), 2) for i := 0; i < times; i++ { illust := &pixiv.Illust{} // 查询出一张图片 @@ -97,7 +98,7 @@ func init() { // 插件主体 Handle(func(ctx *zero.Ctx) { var ( type_ = ctx.State["regex_matched"].([]string)[1] - id = pixiv.Str2Int(ctx.State["regex_matched"].([]string)[2]) + id = apiutils.Str2Int(ctx.State["regex_matched"].([]string)[2]) illust = &pixiv.Illust{} ) ctx.Send("少女祈祷中......") @@ -130,7 +131,7 @@ func init() { // 插件主体 Handle(func(ctx *zero.Ctx) { var ( type_ = ctx.State["regex_matched"].([]string)[1] - id = pixiv.Str2Int(ctx.State["regex_matched"].([]string)[2]) + id = apiutils.Str2Int(ctx.State["regex_matched"].([]string)[2]) ) // 查询数据库 if err := DB.Delete(type_, fmt.Sprintf("WHERE pid=%d", id)); err != nil { From 5cc7c404173378490b117f5cf0a59f5697f8dcd8 Mon Sep 17 00:00:00 2001 From: fumiama Date: Sun, 6 Jun 2021 14:27:16 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E7=BE=A4=E7=AE=A1=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E5=99=A8=E4=BF=9D=E5=AD=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +- api/pixiv/download.go | 10 +-- {manager => api/timer}/timer.go | 108 ++++++++++++++++++++++---------- api/timer/timer.pb.go | 72 +++++++++++++++------ api/timer/timer.proto | 1 + main.go | 2 +- manager/manager.go | 22 +++---- picsearcher/pic_searcher.go | 5 +- 8 files changed, 152 insertions(+), 73 deletions(-) rename {manager => api/timer}/timer.go (69%) diff --git a/.gitignore b/.gitignore index 0dedc1a0..e54b5208 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -data/chat/* -data/SetuTime/cache/* +data/chat +data/SetuTime/cache +data/manager main.exe .DS_Store diff --git a/api/pixiv/download.go b/api/pixiv/download.go index 68abb1c8..dd92a218 100644 --- a/api/pixiv/download.go +++ b/api/pixiv/download.go @@ -10,6 +10,8 @@ import ( "net/http" "os" "strings" + + "github.com/Yiwen-Chan/ZeroBot-Plugin/api/utils" ) // urlCache 缓存并返回缓存路径 @@ -20,9 +22,9 @@ func (this *Illust) PixivPicDown(path string) (savePath string, err error) { url = strings.ReplaceAll(url, "_p0", "_p0_master1200") url = strings.ReplaceAll(url, ".png", ".jpg") // 文件名为url的hash值 - savePath = path + Int2Str(pid) + ".jpg" + savePath = path + utils.Int2Str(pid) + ".jpg" // 文件存在或文件大小大于10kb - if PathExists(savePath) && FileSize(savePath) > 10240 { + if utils.PathExists(savePath) && utils.FileSize(savePath) > 10240 { return savePath, nil } @@ -80,9 +82,9 @@ func (this *Illust) RmPic(path string) (err error) { url = strings.ReplaceAll(url, "_p0", "_p0_master1200") url = strings.ReplaceAll(url, ".png", ".jpg") // 文件名为url的hash值 - savePath := path + Int2Str(pid) + ".jpg" + savePath := path + utils.Int2Str(pid) + ".jpg" // 文件存在或文件大小大于10kb - if PathExists(savePath) { + if utils.PathExists(savePath) { return os.Remove(savePath) } else { return nil diff --git a/manager/timer.go b/api/timer/timer.go similarity index 69% rename from manager/timer.go rename to api/timer/timer.go index e8737d80..c0082cfc 100644 --- a/manager/timer.go +++ b/api/timer/timer.go @@ -1,23 +1,29 @@ -package manager +package timer import ( "fmt" + "io" "os" "strconv" "strings" "time" "unicode" - tm "github.com/Yiwen-Chan/ZeroBot-Plugin/api/timer" + "github.com/Yiwen-Chan/ZeroBot-Plugin/api/msgext" "github.com/Yiwen-Chan/ZeroBot-Plugin/api/utils" + zero "github.com/wdvxdr1123/ZeroBot" + "github.com/wdvxdr1123/ZeroBot/message" ) -type TimeStamp = tm.Timer +type ( + TimeStamp = Timer + Ctx = zero.Ctx +) var ( //记录每个定时器以便取消 - timersmap tm.TimersMap - timers = timersmap.Timers + timersmap TimersMap + Timers *(map[string]*Timer) //定时器存储位置 BOTPATH = utils.PathExecute() // 当前bot运行目录 DATAPATH = BOTPATH + "data/manager/" // 数据目录 @@ -25,32 +31,49 @@ var ( ) func init() { - utils.CreatePath(DATAPATH) + go func() { + time.Sleep(time.Second) + utils.CreatePath(DATAPATH) + loadTimers() + Timers = &timersmap.Timers + }() } -func timer(ts TimeStamp, onTimeReached func()) { - key := getTimerInfo(&ts) - fmt.Printf("[群管]注册计时器: %s\n", key) - t, ok := timers[key] - if ok { //避免重复注册定时器 - t.Enable = false - } - timers[key] = &ts - saveTimers() - judgeHM := func() { - if ts.Hour < 0 || ts.Hour == int32(time.Now().Hour()) { - if ts.Minute < 0 || ts.Minute == int32(time.Now().Minute()) { - onTimeReached() - } +func judgeHM(ts *TimeStamp) { + if ts.Hour < 0 || ts.Hour == int32(time.Now().Hour()) { + if ts.Minute < 0 || ts.Minute == int32(time.Now().Minute()) { + 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(msgext.AtAll(), message.Text(ts.Alert)) + } else { + ctx.SendChain(msgext.AtAll(), message.Text(ts.Alert), msgext.ImageNoCache(ts.Url)) + } + return false + }) } } +} + +func RegisterTimer(ts *TimeStamp, save bool) { + key := GetTimerInfo(ts) + t, ok := (*Timers)[key] + if t != ts && ok { //避免重复注册定时器 + t.Enable = false + } + (*Timers)[key] = ts + if save { + SaveTimers() + } + fmt.Printf("[群管]注册计时器[%t]%s\n", ts.Enable, key) for ts.Enable { if ts.Month < 0 || ts.Month == int32(time.Now().Month()) { if ts.Day < 0 || ts.Day == int32(time.Now().Day()) { - judgeHM() + judgeHM(ts) } else if ts.Day == 0 { if ts.Week < 0 || ts.Week == int32(time.Now().Weekday()) { - judgeHM() + judgeHM(ts) } } } @@ -58,7 +81,7 @@ func timer(ts TimeStamp, onTimeReached func()) { } } -func saveTimers() error { +func SaveTimers() error { data, err := timersmap.Marshal() if err != nil { return err @@ -76,13 +99,32 @@ func saveTimers() error { } } +func loadTimers() { + if utils.PathExists(PBFILE) { + f, err := os.Open(PBFILE) + if err == nil { + data, err1 := io.ReadAll(f) + if err1 == nil { + if len(data) > 0 { + timersmap.Unmarshal(data) + for _, t := range timersmap.Timers { + go RegisterTimer(t, false) + } + return + } + } + } + } + timersmap.Timers = make(map[string]*Timer) +} + //获得标准化定时字符串 -func getTimerInfo(ts *TimeStamp) string { +func GetTimerInfo(ts *TimeStamp) string { return fmt.Sprintf("%d月%d日%d周%d:%d", ts.Month, ts.Day, ts.Week, ts.Hour, ts.Minute) } //获得填充好的ts -func getFilledTimeStamp(dateStrs []string, matchDateOnly bool) TimeStamp { +func GetFilledTimeStamp(dateStrs []string, matchDateOnly bool) *TimeStamp { monthStr := []rune(dateStrs[1]) dayWeekStr := []rune(dateStrs[2]) hourStr := []rune(dateStrs[3]) @@ -92,7 +134,7 @@ func getFilledTimeStamp(dateStrs []string, matchDateOnly bool) TimeStamp { ts.Month = chineseNum2Int(monthStr) if (ts.Month != -1 && ts.Month <= 0) || ts.Month > 12 { //月份非法 fmt.Println("[群管]月份非法!") - return ts + return &ts } lenOfDW := len(dayWeekStr) if lenOfDW == 4 { //包括末尾的"日" @@ -100,14 +142,14 @@ func getFilledTimeStamp(dateStrs []string, matchDateOnly bool) TimeStamp { ts.Day = chineseNum2Int(dayWeekStr) if (ts.Day != -1 && ts.Day <= 0) || ts.Day > 31 { //日期非法 fmt.Println("[群管]日期非法1!") - return ts + 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 { //日期非法 fmt.Println("[群管]日期非法2!") - return ts + return &ts } } else if dayWeekStr[0] == rune('每') { //每周 ts.Week = -1 @@ -119,7 +161,7 @@ func getFilledTimeStamp(dateStrs []string, matchDateOnly bool) TimeStamp { if ts.Week < 0 || ts.Week > 6 { //星期非法 ts.Week = -11 fmt.Println("[群管]星期非法!") - return ts + return &ts } } if len(hourStr) == 3 { @@ -128,7 +170,7 @@ func getFilledTimeStamp(dateStrs []string, matchDateOnly bool) TimeStamp { ts.Hour = chineseNum2Int(hourStr) if ts.Hour < -1 || ts.Hour > 23 { //小时非法 fmt.Println("[群管]小时非法!") - return ts + return &ts } if len(minuteStr) == 3 { minuteStr = []rune{minuteStr[0], minuteStr[2]} //去除中间的十 @@ -136,7 +178,7 @@ func getFilledTimeStamp(dateStrs []string, matchDateOnly bool) TimeStamp { ts.Minute = chineseNum2Int(minuteStr) if ts.Minute < -1 || ts.Minute > 59 { //分钟非法 fmt.Println("[群管]分钟非法!") - return ts + return &ts } if !matchDateOnly { urlStr := dateStrs[5] @@ -146,13 +188,13 @@ func getFilledTimeStamp(dateStrs []string, matchDateOnly bool) TimeStamp { if !strings.HasPrefix(ts.Url, "http") { ts.Url = "illegal" fmt.Println("[群管]url非法!") - return ts + return &ts } } ts.Alert = dateStrs[6] ts.Enable = true } - return ts + return &ts } //汉字数字转int,仅支持-10~99,最多两位数,其中"每"解释为-1,"每两"为-2,以此类推 diff --git a/api/timer/timer.pb.go b/api/timer/timer.pb.go index e4ae608f..0c7bdfbf 100644 --- a/api/timer/timer.pb.go +++ b/api/timer/timer.pb.go @@ -31,6 +31,7 @@ type Timer struct { 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:"-"` @@ -125,6 +126,13 @@ func (m *Timer) GetMinute() int32 { return 0 } +func (m *Timer) GetGrpid() uint64 { + if m != nil { + return m.Grpid + } + return 0 +} + 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:"-"` @@ -181,24 +189,25 @@ func init() { func init() { proto.RegisterFile("timer.proto", fileDescriptor_ad0307ee16b652d2) } var fileDescriptor_ad0307ee16b652d2 = []byte{ - // 267 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x4c, 0x90, 0x4f, 0x4a, 0xc3, 0x40, - 0x14, 0xc6, 0x7d, 0x4d, 0x27, 0x36, 0x2f, 0x2e, 0xea, 0x20, 0x32, 0x88, 0x84, 0x90, 0x55, 0x56, - 0x5d, 0x54, 0x17, 0xe2, 0x52, 0x10, 0x57, 0x6e, 0x06, 0x2f, 0x30, 0xc5, 0x81, 0x96, 0xe6, 0x4f, - 0x99, 0x4e, 0x94, 0x5c, 0xc1, 0x13, 0x78, 0x0b, 0xaf, 0xe1, 0xd2, 0x23, 0x48, 0xbc, 0x88, 0xbc, - 0x37, 0xa1, 0x74, 0xf7, 0xfb, 0x7e, 0xf9, 0x08, 0xef, 0x1b, 0x4c, 0xfd, 0xa6, 0xb6, 0x6e, 0xb1, - 0x73, 0xad, 0x6f, 0xa5, 0xe0, 0x50, 0x7c, 0x01, 0x8a, 0x17, 0x22, 0x79, 0x89, 0xb1, 0x6d, 0xcc, - 0xaa, 0xb2, 0x0a, 0x72, 0x28, 0x67, 0x7a, 0x4c, 0xf2, 0x02, 0x85, 0xa9, 0xac, 0xf3, 0x6a, 0x92, - 0x43, 0x99, 0xe8, 0x10, 0xe4, 0x1c, 0xa3, 0xce, 0x55, 0x2a, 0x62, 0x47, 0x48, 0xbd, 0xba, 0x6d, - 0xfc, 0x5a, 0x4d, 0x73, 0x28, 0xcf, 0x75, 0x08, 0xd4, 0x7b, 0x35, 0xbd, 0x12, 0xec, 0x08, 0xa5, - 0xc4, 0xe9, 0xbb, 0xb5, 0x5b, 0x15, 0xb3, 0x62, 0x26, 0xb7, 0x6e, 0x3b, 0xa7, 0x4e, 0x83, 0x23, - 0xa6, 0x7b, 0xea, 0x4d, 0xd3, 0x79, 0xab, 0x66, 0x6c, 0xc7, 0x54, 0x7c, 0x00, 0x26, 0x7c, 0xf1, - 0xfe, 0xd9, 0xec, 0xe4, 0x2d, 0xc6, 0x3c, 0x64, 0xaf, 0x20, 0x8f, 0xca, 0x74, 0x79, 0xbd, 0x08, - 0x23, 0x0f, 0x8d, 0x91, 0x1e, 0x1b, 0xef, 0x7a, 0x3d, 0x76, 0xaf, 0x9e, 0x30, 0x3d, 0xd2, 0x74, - 0xe4, 0xd6, 0xf6, 0xbc, 0x3b, 0xd1, 0x84, 0xb2, 0x40, 0xf1, 0x66, 0xaa, 0xce, 0xf2, 0xe8, 0x74, - 0x79, 0x76, 0xfc, 0x57, 0x1d, 0x3e, 0xdd, 0x4f, 0xee, 0xe0, 0x61, 0xfe, 0x3d, 0x64, 0xf0, 0x33, - 0x64, 0xf0, 0x3b, 0x64, 0xf0, 0xf9, 0x97, 0x9d, 0xac, 0x62, 0x7e, 0xde, 0x9b, 0xff, 0x00, 0x00, - 0x00, 0xff, 0xff, 0x8f, 0x73, 0x63, 0x18, 0x6d, 0x01, 0x00, 0x00, + // 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 *Timer) Marshal() (dAtA []byte, err error) { @@ -225,6 +234,11 @@ func (m *Timer) MarshalToSizedBuffer(dAtA []byte) (int, error) { i -= len(m.XXX_unrecognized) copy(dAtA[i:], m.XXX_unrecognized) } + if m.Grpid != 0 { + i = encodeVarintTimer(dAtA, i, uint64(m.Grpid)) + i-- + dAtA[i] = 0x48 + } if m.Minute != 0 { i = encodeVarintTimer(dAtA, i, uint64((uint32(m.Minute)<<1)^uint32((m.Minute>>31)))) i-- @@ -373,6 +387,9 @@ func (m *Timer) Size() (n int) { if m.Minute != 0 { n += 1 + sozTimer(uint64(m.Minute)) } + if m.Grpid != 0 { + n += 1 + sovTimer(uint64(m.Grpid)) + } if m.XXX_unrecognized != nil { n += len(m.XXX_unrecognized) } @@ -628,6 +645,25 @@ func (m *Timer) Unmarshal(dAtA []byte) error { } 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 ErrIntOverflowTimer + } + 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 := skipTimer(dAtA[iNdEx:]) diff --git a/api/timer/timer.proto b/api/timer/timer.proto index aa2b3a60..2d95f12e 100644 --- a/api/timer/timer.proto +++ b/api/timer/timer.proto @@ -10,6 +10,7 @@ message Timer { sint32 week = 6; sint32 hour = 7; sint32 minute = 8; + uint64 grpid = 9; } message TimersMap { diff --git a/main.go b/main.go index 7256cf3f..604bbca3 100644 --- a/main.go +++ b/main.go @@ -53,7 +53,7 @@ func main() { CommandPrefix: "/", SuperUsers: os.Args[1:], // 必须修改,否则无权限 Driver: []zero.Driver{ - driver.NewWebSocketClient("127.0.0.1", "6700", ""), + driver.NewWebSocketClient("ws://192.168.8.1:6700/", ""), }, }) // 帮助 diff --git a/manager/manager.go b/manager/manager.go index 33bd4952..bfbb7093 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -4,7 +4,7 @@ import ( "strconv" "strings" - "github.com/Yiwen-Chan/ZeroBot-Plugin/api/msgext" + "github.com/Yiwen-Chan/ZeroBot-Plugin/api/timer" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/message" ) @@ -235,15 +235,10 @@ func init() { // 插件主体 zero.OnRegex(`^在(.{1,2})月(.{1,3}日|每?周.?)的(.{1,3})点(.{1,3})分时(用.+)?提醒大家(.*)`, zero.SuperUserPermission).SetBlock(true).SetPriority(40). Handle(func(ctx *zero.Ctx) { dateStrs := ctx.State["regex_matched"].([]string) - ts := getFilledTimeStamp(dateStrs, false) + ts := timer.GetFilledTimeStamp(dateStrs, false) + ts.Grpid = uint64(ctx.Event.GroupID) if ts.Enable { - go timer(ts, func() { - if ts.Url == "" { - ctx.SendChain(msgext.AtAll(), message.Text(ts.Alert)) - } else { - ctx.SendChain(msgext.AtAll(), message.Text(ts.Alert), msgext.ImageNoCache(ts.Url)) - } - }) + go timer.RegisterTimer(ts, true) ctx.Send("记住了~") } else { ctx.Send("参数非法!") @@ -254,12 +249,13 @@ func init() { // 插件主体 zero.OnRegex(`^取消在(.{1,2})月(.{1,3}日|每?周.?)的(.{1,3})点(.{1,3})分的提醒`, zero.SuperUserPermission).SetBlock(true).SetPriority(40). Handle(func(ctx *zero.Ctx) { dateStrs := ctx.State["regex_matched"].([]string) - ts := getFilledTimeStamp(dateStrs, true) - ti := getTimerInfo(&ts) - t, ok := timers[ti] + ts := timer.GetFilledTimeStamp(dateStrs, true) + ti := timer.GetTimerInfo(ts) + t, ok := (*timer.Timers)[ti] if ok { t.Enable = false - delete(timers, ti) //避免重复取消 + delete(*timer.Timers, ti) //避免重复取消 + timer.SaveTimers() ctx.Send("取消成功~") } else { ctx.Send("没有这个定时器哦~") diff --git a/picsearcher/pic_searcher.go b/picsearcher/pic_searcher.go index 287e3548..4fd7d1ac 100644 --- a/picsearcher/pic_searcher.go +++ b/picsearcher/pic_searcher.go @@ -10,17 +10,18 @@ import ( "github.com/wdvxdr1123/ZeroBot/message" "github.com/Yiwen-Chan/ZeroBot-Plugin/api/pixiv" + apiutils "github.com/Yiwen-Chan/ZeroBot-Plugin/api/utils" utils "github.com/Yiwen-Chan/ZeroBot-Plugin/picsearcher/utils" ) var CACHEPATH = "/tmp/picsch/" // 缓冲图片路径 func init() { // 插件主体 - pixiv.CreatePath(CACHEPATH) + apiutils.CreatePath(CACHEPATH) // 根据PID搜图 zero.OnRegex(`^搜图(\d+)$`).SetBlock(true).SetPriority(30). Handle(func(ctx *zero.Ctx) { - id := pixiv.Str2Int(ctx.State["regex_matched"].([]string)[1]) + id := apiutils.Str2Int(ctx.State["regex_matched"].([]string)[1]) ctx.Send("少女祈祷中......") // 获取P站插图信息 illust := &pixiv.Illust{} From a382dea51f8c2a23cc66ae17b55c070ad976d478 Mon Sep 17 00:00:00 2001 From: fumiama Date: Sun, 6 Jun 2021 14:27:53 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=81=A2=E5=A4=8Dmain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 604bbca3..2d6072c2 100644 --- a/main.go +++ b/main.go @@ -27,8 +27,8 @@ import ( _ "github.com/Yiwen-Chan/ZeroBot-Plugin/picsearcher" // 搜图 _ "github.com/Yiwen-Chan/ZeroBot-Plugin/randimg" //简易随机图片 - //_ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime" // 涩图 - _ "github.com/Yiwen-Chan/ZeroBot-Plugin/shindan" // 测定 + _ "github.com/Yiwen-Chan/ZeroBot-Plugin/setutime" // 涩图 + _ "github.com/Yiwen-Chan/ZeroBot-Plugin/shindan" // 测定 ) func init() { @@ -53,7 +53,7 @@ func main() { CommandPrefix: "/", SuperUsers: os.Args[1:], // 必须修改,否则无权限 Driver: []zero.Driver{ - driver.NewWebSocketClient("ws://192.168.8.1:6700/", ""), + driver.NewWebSocketClient("ws://127.0.0.1:6700/", ""), }, }) // 帮助 From 77cad0915c26bed1a968d7f834b97dd3612a374d Mon Sep 17 00:00:00 2001 From: fumiama Date: Sun, 6 Jun 2021 14:46:58 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E5=B0=86timer=E5=88=86=E7=A6=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/timer/timer.go | 242 ----------- api/timer/timer.pb.go | 952 ------------------------------------------ api/timer/timer.proto | 18 - go.mod | 3 +- go.sum | 2 + manager/manager.go | 2 +- 6 files changed, 5 insertions(+), 1214 deletions(-) delete mode 100644 api/timer/timer.go delete mode 100644 api/timer/timer.pb.go delete mode 100644 api/timer/timer.proto diff --git a/api/timer/timer.go b/api/timer/timer.go deleted file mode 100644 index c0082cfc..00000000 --- a/api/timer/timer.go +++ /dev/null @@ -1,242 +0,0 @@ -package timer - -import ( - "fmt" - "io" - "os" - "strconv" - "strings" - "time" - "unicode" - - "github.com/Yiwen-Chan/ZeroBot-Plugin/api/msgext" - "github.com/Yiwen-Chan/ZeroBot-Plugin/api/utils" - zero "github.com/wdvxdr1123/ZeroBot" - "github.com/wdvxdr1123/ZeroBot/message" -) - -type ( - TimeStamp = Timer - Ctx = zero.Ctx -) - -var ( - //记录每个定时器以便取消 - timersmap TimersMap - Timers *(map[string]*Timer) - //定时器存储位置 - BOTPATH = utils.PathExecute() // 当前bot运行目录 - DATAPATH = BOTPATH + "data/manager/" // 数据目录 - PBFILE = DATAPATH + "timers.pb" -) - -func init() { - go func() { - time.Sleep(time.Second) - utils.CreatePath(DATAPATH) - loadTimers() - Timers = &timersmap.Timers - }() -} - -func judgeHM(ts *TimeStamp) { - if ts.Hour < 0 || ts.Hour == int32(time.Now().Hour()) { - if ts.Minute < 0 || ts.Minute == int32(time.Now().Minute()) { - 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(msgext.AtAll(), message.Text(ts.Alert)) - } else { - ctx.SendChain(msgext.AtAll(), message.Text(ts.Alert), msgext.ImageNoCache(ts.Url)) - } - return false - }) - } - } -} - -func RegisterTimer(ts *TimeStamp, save bool) { - key := GetTimerInfo(ts) - t, ok := (*Timers)[key] - if t != ts && ok { //避免重复注册定时器 - t.Enable = false - } - (*Timers)[key] = ts - if save { - SaveTimers() - } - fmt.Printf("[群管]注册计时器[%t]%s\n", ts.Enable, key) - for ts.Enable { - if ts.Month < 0 || ts.Month == int32(time.Now().Month()) { - if ts.Day < 0 || ts.Day == int32(time.Now().Day()) { - judgeHM(ts) - } else if ts.Day == 0 { - if ts.Week < 0 || ts.Week == int32(time.Now().Weekday()) { - judgeHM(ts) - } - } - } - time.Sleep(time.Minute) - } -} - -func SaveTimers() error { - data, err := timersmap.Marshal() - if err != nil { - return err - } else if utils.PathExists(DATAPATH) { - f, err1 := os.OpenFile(PBFILE, os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644) - if err1 != nil { - return err1 - } else { - defer f.Close() - _, err2 := f.Write(data) - return err2 - } - } else { - return nil - } -} - -func loadTimers() { - if utils.PathExists(PBFILE) { - f, err := os.Open(PBFILE) - if err == nil { - data, err1 := io.ReadAll(f) - if err1 == nil { - if len(data) > 0 { - timersmap.Unmarshal(data) - for _, t := range timersmap.Timers { - go RegisterTimer(t, false) - } - return - } - } - } - } - timersmap.Timers = make(map[string]*Timer) -} - -//获得标准化定时字符串 -func GetTimerInfo(ts *TimeStamp) string { - return fmt.Sprintf("%d月%d日%d周%d:%d", ts.Month, ts.Day, ts.Week, ts.Hour, ts.Minute) -} - -//获得填充好的ts -func GetFilledTimeStamp(dateStrs []string, matchDateOnly bool) *TimeStamp { - monthStr := []rune(dateStrs[1]) - dayWeekStr := []rune(dateStrs[2]) - hourStr := []rune(dateStrs[3]) - minuteStr := []rune(dateStrs[4]) - - var ts TimeStamp - ts.Month = chineseNum2Int(monthStr) - if (ts.Month != -1 && ts.Month <= 0) || ts.Month > 12 { //月份非法 - fmt.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 { //日期非法 - fmt.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 { //日期非法 - fmt.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 - fmt.Println("[群管]星期非法!") - return &ts - } - } - if len(hourStr) == 3 { - hourStr = []rune{hourStr[0], hourStr[2]} //去除中间的十 - } - ts.Hour = chineseNum2Int(hourStr) - if ts.Hour < -1 || ts.Hour > 23 { //小时非法 - fmt.Println("[群管]小时非法!") - return &ts - } - if len(minuteStr) == 3 { - minuteStr = []rune{minuteStr[0], minuteStr[2]} //去除中间的十 - } - ts.Minute = chineseNum2Int(minuteStr) - if ts.Minute < -1 || ts.Minute > 59 { //分钟非法 - fmt.Println("[群管]分钟非法!") - return &ts - } - if !matchDateOnly { - urlStr := dateStrs[5] - if urlStr != "" { //是图片url - ts.Url = urlStr[3:] //utf-8下用为3字节 - fmt.Println("[群管]" + ts.Url) - if !strings.HasPrefix(ts.Url, "http") { - ts.Url = "illegal" - fmt.Println("[群管]url非法!") - return &ts - } - } - ts.Alert = dateStrs[6] - ts.Enable = true - } - return &ts -} - -//汉字数字转int,仅支持-10~99,最多两位数,其中"每"解释为-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) -} - -//处理单个字符的映射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 - } -} diff --git a/api/timer/timer.pb.go b/api/timer/timer.pb.go deleted file mode 100644 index 0c7bdfbf..00000000 --- a/api/timer/timer.pb.go +++ /dev/null @@ -1,952 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: timer.proto - -package timer - -import ( - fmt "fmt" - proto "github.com/golang/protobuf/proto" - io "io" - math "math" - math_bits "math/bits" -) - -// 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:"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 *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) GetGrpid() uint64 { - if m != nil { - return m.Grpid - } - return 0 -} - -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{ - // 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 *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 m.Grpid != 0 { - i = encodeVarintTimer(dAtA, i, uint64(m.Grpid)) - i-- - dAtA[i] = 0x48 - } - if m.Minute != 0 { - i = encodeVarintTimer(dAtA, i, uint64((uint32(m.Minute)<<1)^uint32((m.Minute>>31)))) - i-- - dAtA[i] = 0x40 - } - if m.Hour != 0 { - i = encodeVarintTimer(dAtA, i, uint64((uint32(m.Hour)<<1)^uint32((m.Hour>>31)))) - i-- - dAtA[i] = 0x38 - } - if m.Week != 0 { - i = encodeVarintTimer(dAtA, i, uint64((uint32(m.Week)<<1)^uint32((m.Week>>31)))) - i-- - dAtA[i] = 0x30 - } - if m.Day != 0 { - i = encodeVarintTimer(dAtA, i, uint64((uint32(m.Day)<<1)^uint32((m.Day>>31)))) - i-- - dAtA[i] = 0x28 - } - if m.Month != 0 { - i = encodeVarintTimer(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 = 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 + sozTimer(uint64(m.Month)) - } - if m.Day != 0 { - n += 1 + sozTimer(uint64(m.Day)) - } - if m.Week != 0 { - n += 1 + sozTimer(uint64(m.Week)) - } - if m.Hour != 0 { - n += 1 + sozTimer(uint64(m.Hour)) - } - if m.Minute != 0 { - n += 1 + sozTimer(uint64(m.Minute)) - } - if m.Grpid != 0 { - n += 1 + sovTimer(uint64(m.Grpid)) - } - 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) - } - var v int32 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowTimer - } - 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 ErrIntOverflowTimer - } - 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 ErrIntOverflowTimer - } - 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 ErrIntOverflowTimer - } - 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 ErrIntOverflowTimer - } - 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 ErrIntOverflowTimer - } - 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 := 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") -) diff --git a/api/timer/timer.proto b/api/timer/timer.proto deleted file mode 100644 index 2d95f12e..00000000 --- a/api/timer/timer.proto +++ /dev/null @@ -1,18 +0,0 @@ -syntax = "proto3"; -package timer; - -message Timer { - bool enable = 1; - string alert = 2; - string url = 3; - sint32 month = 4; - sint32 day = 5; - sint32 week = 6; - sint32 hour = 7; - sint32 minute = 8; - uint64 grpid = 9; -} - -message TimersMap { - map timers = 1; -} \ No newline at end of file diff --git a/go.mod b/go.mod index 61d9028c..f6bd3c74 100644 --- a/go.mod +++ b/go.mod @@ -5,8 +5,9 @@ go 1.15 require ( github.com/antchfx/htmlquery v1.2.3 github.com/antchfx/xpath v1.2.0 // indirect + github.com/fumiama/ZeroBot-Plugin-Timer v0.0.0-20210606064339-d55b94d71eee github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect - github.com/golang/protobuf v1.5.2 + github.com/golang/protobuf v1.5.2 // indirect github.com/mattn/go-sqlite3 v1.14.7 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/sirupsen/logrus v1.8.1 diff --git a/go.sum b/go.sum index e8ced15e..c878779e 100644 --- a/go.sum +++ b/go.sum @@ -7,6 +7,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fumiama/ZeroBot-Plugin-Timer v0.0.0-20210606064339-d55b94d71eee h1:IfBMBcPUUbmEzXjIVkDiSSPoUBkH8Xbk1K9PllgrAfo= +github.com/fumiama/ZeroBot-Plugin-Timer v0.0.0-20210606064339-d55b94d71eee/go.mod h1:RN0gCtafWRu2d7lMg9/5UfZDhtsPgdeUovsyuSwl+oQ= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= diff --git a/manager/manager.go b/manager/manager.go index bfbb7093..d71df744 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -4,7 +4,7 @@ import ( "strconv" "strings" - "github.com/Yiwen-Chan/ZeroBot-Plugin/api/timer" + timer "github.com/fumiama/ZeroBot-Plugin-Timer" zero "github.com/wdvxdr1123/ZeroBot" "github.com/wdvxdr1123/ZeroBot/message" )