diff --git a/bot.go b/bot.go index a72d468..8b3187b 100644 --- a/bot.go +++ b/bot.go @@ -1592,6 +1592,59 @@ func botTimer(m *tb.Message) { } + r := regexp.MustCompile("^(?P([0-9]+)(?P([0-9]*(s|m|h))+) \"(?P(.*))\"$") + if r.MatchString(m.Payload) { + if clt.TGUserID64 != cfg.Bot.Admin { + c := TGCommand{ + Type: commandReplyMsg, + Text: "Admin only", + FromMsgID64: int64(m.ID), + FromChatID64: m.Chat.ID, + } + TGCmdQueue <- c + return + } + d, err := time.ParseDuration(r.ReplaceAllString(m.Payload, "${Duration}")) + if err != nil { + c := TGCommand{ + Type: commandReplyMsg, + Text: fmt.Sprintf("%s", err), + FromMsgID64: int64(m.ID), + FromChatID64: m.Chat.ID, + } + TGCmdQueue <- c + } else { + userID, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${User}"), 10, 64) + p := JobPayloadMsgClient{ + Text: r.ReplaceAllString(m.Payload, "${Msg}"), + MsgID64: int64(m.ID), + ChatID64: m.Chat.ID, + } + b, _ := json.Marshal(p) + t := time.Now().UTC().Add(d) + objID64, err := createJob(cacheObjSubType[`job_msg_client`], objJobPriority, userID, 0, t, b) + logOnError(err, "botTimer : createJob") + if err != nil { + c := TGCommand{ + Type: commandReplyMsg, + Text: fmt.Sprintf("%s", err), + FromMsgID64: int64(m.ID), + FromChatID64: m.Chat.ID, + } + TGCmdQueue <- c + } else { + c := TGCommand{ + Type: commandReplyMsg, + Text: fmt.Sprintf("Job #%d scheduled at %s", objID64, t.Format(time.RFC850)), + FromMsgID64: int64(m.ID), + FromChatID64: m.Chat.ID, + } + TGCmdQueue <- c + } + } + + } + return }