chirpnest/bot.go

1862 lines
44 KiB
Go
Raw Normal View History

2019-05-03 05:58:36 +02:00
package main
import (
2019-05-10 15:58:56 +02:00
"encoding/json"
2019-05-03 05:58:36 +02:00
"fmt"
2019-05-11 07:08:12 +02:00
"log"
2020-02-14 04:08:19 +01:00
"os"
2019-05-10 13:05:25 +02:00
"regexp"
2019-05-18 09:46:34 +02:00
"strconv"
2019-05-03 05:58:36 +02:00
"time"
2019-05-18 09:46:34 +02:00
tb "gopkg.in/tucnak/telebot.v2"
2019-05-03 05:58:36 +02:00
)
2019-05-11 05:37:33 +02:00
func BotHandlers(b *tb.Bot) {
2019-05-10 04:43:54 +02:00
2019-05-17 10:30:01 +02:00
b.Handle("/test", botTest)
2019-08-23 08:03:22 +02:00
b.Handle("/test_delay", botTestDelay)
2019-06-10 11:05:59 +02:00
b.Handle("/test_html", botTestHTML)
2020-02-01 13:02:02 +01:00
b.Handle("/test_user", botTestUser)
2019-05-17 10:30:01 +02:00
b.Handle("/msg_rescan", botMsgRescan)
2019-05-16 05:35:37 +02:00
b.Handle("/msg_rescan_all", botMsgRescanAll)
2019-05-18 09:44:25 +02:00
b.Handle("/msg_dump", botMsgDump)
2019-05-10 04:58:28 +02:00
2019-05-25 16:36:14 +02:00
b.Handle("/parse_rules", botListParsingRules)
b.Handle("/parse_rule", botListParsingRule)
2019-05-26 13:30:21 +02:00
b.Handle("/timer", botTimer)
2019-08-16 12:29:07 +02:00
b.Handle("/g_deposit_all", botGDepositAll)
2019-10-02 06:43:27 +02:00
b.Handle("/g_withdraw", botGWithdraw)
2019-09-14 10:27:38 +02:00
b.Handle("/save_res", botSaveRes)
2019-05-31 12:41:26 +02:00
2019-06-11 16:50:01 +02:00
b.Handle("/backup_export", botBackupExport)
b.Handle("/backup_import", botBackupImport)
2019-06-09 10:47:44 +02:00
b.Handle("/help", botHelp)
2019-06-08 17:28:07 +02:00
2019-06-28 13:04:08 +02:00
b.Handle("/get_item_id", botGetItemId)
2019-07-09 09:48:21 +02:00
b.Handle("/clients", botGetClients)
2019-06-28 13:04:08 +02:00
2019-10-10 12:14:29 +02:00
b.Handle("/vault", botVaultHelp)
2019-10-11 06:00:25 +02:00
b.Handle("/vault_all", botVaultAll)
b.Handle("/vault_res", botVaultRes)
b.Handle("/vault_alch", botVaultAlch)
b.Handle("/vault_misc", botVaultMisc)
b.Handle("/vault_rec", botVaultRec)
b.Handle("/vault_part", botVaultPart)
b.Handle("/vault_other", botVaultOther)
2019-10-12 07:47:40 +02:00
b.Handle("/vault_item", botVaultItem)
2019-10-10 12:14:29 +02:00
2020-05-08 16:02:18 +02:00
b.Handle("/restart_job", botRestartJob)
2020-10-11 12:53:15 +02:00
b.Handle("/cleanup_job", botCleanupJob)
2020-05-08 16:02:18 +02:00
2019-05-03 05:58:36 +02:00
b.Handle(tb.OnPhoto, botPhoto)
b.Handle(tb.OnChannelPost, botChannelPost)
b.Handle(tb.OnQuery, botQuery)
b.Handle(tb.OnText, botText)
2019-05-26 09:57:45 +02:00
b.Handle(tb.OnDocument, botDocument)
2019-05-03 05:58:36 +02:00
b.Start()
}
2020-01-14 04:34:29 +01:00
func PrintText(m *tb.Message) {
log.Printf("[%d] %s(%d) | %s(%d) : %s\n", m.ID, m.Chat.Title, m.Chat.ID, m.Sender.Username, m.Sender.ID, m.Text)
return
}
2019-05-03 05:58:36 +02:00
func botPhoto(m *tb.Message) {
2019-05-10 04:26:37 +02:00
fmt.Println("botPhoto :", m.Text)
2019-05-03 05:58:36 +02:00
// photos only
}
2019-05-26 09:57:45 +02:00
func botDocument(m *tb.Message) {
2019-05-31 17:06:31 +02:00
fmt.Printf("botDocument : %s (%d bytes)\n", m.Document.FileName, m.Document.File.FileSize)
2019-05-26 09:57:45 +02:00
// documents only
}
2019-05-03 05:58:36 +02:00
func botChannelPost(m *tb.Message) {
PrintText(m)
2019-10-13 09:20:23 +02:00
b, _ := json.Marshal(m)
log.Printf("botChannelPost : %s\n", string(b))
2019-05-03 05:58:36 +02:00
// channel posts only
}
func botQuery(q *tb.Query) {
2019-05-10 04:26:37 +02:00
fmt.Println("botQuery")
2019-05-03 05:58:36 +02:00
// incoming inline queries
}
func botText(m *tb.Message) {
PrintText(m)
2019-10-12 11:29:19 +02:00
2020-02-01 13:44:46 +01:00
if m.Chat.ID == cfg.Bot.Depositchat && m.IsForwarded() && m.OriginalSender != nil && int64(m.OriginalSender.ID) == chtwrsbotID64 {
cwm := ChatWarsMessage{
TGUserID64: int64(bot.Me.ID),
TGSenderUserID64: int64(m.Sender.ID),
ID64: int64(m.ID),
ChatID64: int64(m.Chat.ID),
Text: m.Text,
Date: m.Time().UTC(),
IsForwarded: true,
}
MQCWMsgQueue <- cwm
} else if m.IsForwarded() && m.OriginalSender != nil && int64(m.OriginalSender.ID) == chtwrsbotID64 {
2019-10-21 04:25:41 +02:00
cwm := ChatWarsMessage{
TGUserID64: int64(m.Sender.ID),
TGSenderUserID64: chtwrsbotID64,
ID64: int64(m.ID),
ChatID64: int64(m.Chat.ID),
Text: m.Text,
Date: m.Time().UTC(),
IsForwarded: true,
2019-10-12 11:29:19 +02:00
}
2019-10-21 04:25:41 +02:00
MQCWMsgQueue <- cwm
2020-01-14 07:23:27 +01:00
} else if (m.Chat.ID == cfg.Bot.Depositchat || m.Chat.ID == cfg.Bot.Mainchat) && !m.IsForwarded() {
cwm := ChatWarsMessage{
TGUserID64: int64(m.Sender.ID),
TGSenderUserID64: int64(m.Sender.ID),
ID64: int64(m.ID),
ChatID64: int64(m.Chat.ID),
Text: m.Text,
Date: m.Time().UTC(),
IsForwarded: false,
}
MQCWMsgQueue <- cwm
2020-01-26 12:09:27 +01:00
} else if m.Private() {
cwm := ChatWarsMessage{
TGUserID64: int64(m.Sender.ID),
TGSenderUserID64: int64(m.Sender.ID),
ID64: int64(m.ID),
ChatID64: int64(m.Chat.ID),
Text: m.Text,
Date: m.Time().UTC(),
IsForwarded: false,
}
MQCWMsgQueue <- cwm
2019-10-21 04:25:41 +02:00
}
2019-05-03 05:58:36 +02:00
// all the text messages that weren't
// captured by existing handlers
}
2019-05-10 04:26:37 +02:00
2019-06-09 10:47:44 +02:00
func botHelp(m *tb.Message) {
if !m.Private() {
return
}
c := TGCommand{
Type: commandReplyMsg,
2019-06-09 10:49:32 +02:00
Text: `/help - this help
/msg_rescan <id> - rescan one message
/msg_rescan_all - rescan all messages
2019-10-03 12:43:15 +02:00
/msg_dump <id> - dump msg
2019-06-09 10:49:32 +02:00
/parse_rules - list parsing rules\n
/parse_rule <id> - detail for one rule
/timer <ETA> "msg" - schedule msg for client in ETA
/g_stock - check guild's vault
2019-06-11 17:59:09 +02:00
/backup_export - export message database
2019-07-09 09:48:21 +02:00
/backup_import <URL> - import message database from URL
/get_item_id <string> - identify item_id from string
2019-08-30 09:11:49 +02:00
/clients - list all connected clients
2019-10-04 12:38:03 +02:00
/g_deposit_all - deposit all res to vault
2019-10-10 12:14:29 +02:00
/g_withdraw <item> <qty> .. - withdraw items
/vault - Deposit and withdrawal stats`,
2019-06-09 10:47:44 +02:00
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2020-02-01 13:02:02 +01:00
func botTestUser(m *tb.Message) {
if !m.Private() {
return
}
c, err := bot.ChatByID(m.Payload)
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("%s", err),
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
ParseMode: cmdParseModeHTML,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: c.Username,
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
ParseMode: cmdParseModeHTML,
}
TGCmdQueue <- c
}
return
}
2019-06-10 11:05:59 +02:00
func botTestHTML(m *tb.Message) {
if !m.Private() {
return
}
c := TGCommand{
2019-06-10 11:31:53 +02:00
Type: commandReplyMsg,
2019-06-10 11:34:46 +02:00
Text: `<b>bold</b>,
<strong>bold</strong>,
<i>italic</i>,
<em>italic</em>,
<a href="https://t.me/share/url?url=/tu_def jgm2v8">inline URL</a>,
<code>inline fixed-width code</code>,
2019-06-10 11:31:53 +02:00
<pre>pre-formatted fixed-width code block</pre>`,
2019-06-10 11:05:59 +02:00
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
ParseMode: cmdParseModeHTML,
}
TGCmdQueue <- c
return
}
2019-05-17 10:30:01 +02:00
func botTest(m *tb.Message) {
2019-05-10 04:26:37 +02:00
if !m.Private() {
2019-05-17 10:30:01 +02:00
return
}
2019-07-31 08:24:52 +02:00
if clt, ok := getLockedClient(m.Chat.ID, false); ok {
clt.Mux.Unlock()
2019-05-30 06:12:01 +02:00
clientSendCWMsg(m.Chat.ID, "🏅Me")
2019-05-17 10:30:01 +02:00
2019-05-30 06:13:50 +02:00
c := TGCommand{
2019-05-17 10:30:01 +02:00
Type: commandReplyMsg,
Text: "Test sent",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
2019-08-23 08:03:22 +02:00
Text: "Client not registered",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
return
}
func botTestDelay(m *tb.Message) {
if !m.Private() {
return
}
if clt, ok := getLockedClient(m.Chat.ID, false); ok {
clt.Mux.Unlock()
2019-08-24 08:08:31 +02:00
clientSendCWMsgDelay(m.Chat.ID, "🏅Me", 5*time.Second)
2019-08-23 08:03:22 +02:00
c := TGCommand{
Type: commandReplyMsg,
Text: "Test sent",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
2019-05-17 10:30:01 +02:00
Text: "Client not registered",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
return
}
2019-07-09 09:48:21 +02:00
func botGetClients(m *tb.Message) {
if !m.Private() {
return
}
2019-07-31 07:07:12 +02:00
if clt, ok := getLockedClient(m.Chat.ID, false); ok {
2019-07-31 08:19:09 +02:00
clt.Mux.Unlock()
2019-07-31 07:07:12 +02:00
muxClients.RLock()
2020-02-05 11:31:39 +01:00
ret := fmt.Sprintf("<code>Version %s (%s)\n", githash, buildstamp)
2020-02-05 11:49:41 +01:00
for id, c := range clients {
chat, err := bot.ChatByID(strconv.FormatInt(id, 10))
2020-02-05 11:47:17 +01:00
logOnError(err, "botGetClients : ChatByID")
var status string
2019-07-31 07:07:12 +02:00
if c.Active {
2020-02-05 11:47:17 +01:00
status = `online`
2019-07-09 10:06:02 +02:00
} else {
2020-02-05 11:47:17 +01:00
status = `offline`
2019-07-09 10:01:02 +02:00
}
2020-02-05 11:48:28 +01:00
ret = fmt.Sprintf("%s%s (%s) | @%s (%s)\n", ret, c.Login, c.Build, chat.Username, status)
2019-07-31 07:07:12 +02:00
}
2020-02-05 11:27:12 +01:00
ret = fmt.Sprintf("%s</code>", ret)
2019-07-31 07:07:12 +02:00
muxClients.RUnlock()
2019-07-09 09:48:21 +02:00
c := TGCommand{
Type: commandReplyMsg,
Text: ret,
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
2019-07-09 10:01:02 +02:00
ParseMode: cmdParseModeHTML,
2019-07-09 09:48:21 +02:00
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: "Client not registered",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
return
}
2019-05-17 10:30:01 +02:00
func botMsgRescan(m *tb.Message) {
if !m.Private() {
return
2019-05-10 04:26:37 +02:00
}
2019-07-31 07:07:12 +02:00
clt, ok := getLockedClient(m.Chat.ID, false)
if !ok {
2019-06-11 17:39:04 +02:00
c := TGCommand{
Type: commandReplyMsg,
Text: "Client not registered",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2019-07-31 08:19:09 +02:00
clt.Mux.Unlock()
2019-07-31 07:07:12 +02:00
if clt.TGUserID64 != cfg.Bot.Admin {
c := TGCommand{
Type: commandReplyMsg,
Text: "Admin only",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2019-05-10 13:04:21 +02:00
r := regexp.MustCompile("^[0-9]+$")
if r.MatchString(m.Payload) {
2019-05-11 07:14:59 +02:00
p := JobPayloadRescanMsg{
2020-01-02 16:33:41 +01:00
Query: fmt.Sprintf("SELECT o.id FROM obj o WHERE o.id = %s AND o.obj_type_id = %d AND o.obj_sub_type_id = %d;", m.Payload, cacheObjType[`msg`], cacheObjSubType[`msg`]),
2019-05-16 04:49:34 +02:00
MsgID64: int64(m.ID),
ChatID64: m.Chat.ID,
2019-05-11 07:14:59 +02:00
}
2019-05-10 15:57:01 +02:00
b, _ := json.Marshal(p)
2019-05-11 07:14:59 +02:00
log.Printf("botMsgRescan : json : %s\n", string(b))
2020-01-02 13:04:12 +01:00
_, err := createJob(cacheObjSubType[`job_rescan_msg`], objJobPriorityRescanMsg, int64(m.Sender.ID), 0, time.Now().UTC(), b)
logOnError(err, "botMsgRescan : createJob(cacheObjSubType[`job_rescan_msg`])")
2019-05-10 15:57:01 +02:00
if err != nil {
2019-05-17 10:30:01 +02:00
c := TGCommand{
Type: commandReplyMsg,
2019-05-18 13:15:50 +02:00
Text: fmt.Sprintf("Error scheduling the rescan for msg #%s", m.Payload),
2019-05-17 10:30:01 +02:00
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
2019-05-10 15:57:01 +02:00
} else {
2019-05-17 10:30:01 +02:00
c := TGCommand{
2019-05-17 10:31:13 +02:00
Type: commandReplyMsg,
2019-05-18 13:15:50 +02:00
Text: fmt.Sprintf("Rescaning msg #%s", m.Payload),
2019-05-17 10:30:01 +02:00
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
2019-05-10 15:57:01 +02:00
}
2019-05-10 13:04:21 +02:00
}
2019-05-10 13:05:25 +02:00
r = regexp.MustCompile("^all$")
2019-05-10 13:04:21 +02:00
if r.MatchString(m.Payload) {
2019-05-17 10:30:01 +02:00
botMsgRescanAll(m)
2019-05-10 13:04:21 +02:00
}
2019-05-17 10:30:01 +02:00
return
2019-05-10 04:26:37 +02:00
}
2019-05-11 12:45:05 +02:00
2019-05-16 05:35:37 +02:00
func botMsgRescanAll(m *tb.Message) {
2019-05-11 12:45:05 +02:00
if !m.Private() {
2019-05-16 05:35:37 +02:00
return
2019-05-11 12:45:05 +02:00
}
2019-07-31 07:07:12 +02:00
clt, ok := getLockedClient(m.Chat.ID, false)
if !ok {
2019-06-11 17:39:04 +02:00
c := TGCommand{
Type: commandReplyMsg,
Text: "Client not registered",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2019-07-31 08:19:09 +02:00
clt.Mux.Unlock()
2019-07-31 07:07:12 +02:00
if clt.TGUserID64 != cfg.Bot.Admin {
c := TGCommand{
Type: commandReplyMsg,
Text: "Admin only",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2020-02-06 03:23:50 +01:00
var p JobPayloadRescanMsg
if len(m.Payload) > 0 {
r := regexp.MustCompile("^\"(?P<Filter>(.*))\"$")
if r.MatchString(m.Payload) {
2020-02-06 03:26:24 +01:00
p.Query = fmt.Sprintf("SELECT o.id FROM obj o, obj_msg om WHERE o.obj_type_id = %d AND o.obj_sub_type_id = %d AND om.obj_id = o.id AND om.text like '%s' ORDER BY o.id ASC;", cacheObjType[`msg`], cacheObjSubType[`msg`], r.ReplaceAllString(m.Payload, "${Filter}"))
2020-02-06 03:23:50 +01:00
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: "Wrong format",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
} else {
p.Query = fmt.Sprintf("SELECT o.id FROM obj o WHERE o.obj_type_id = %d AND o.obj_sub_type_id = %d ORDER BY o.id ASC;", cacheObjType[`msg`], cacheObjSubType[`msg`])
2019-05-11 12:45:05 +02:00
}
2020-02-06 03:23:50 +01:00
2020-02-06 03:25:44 +01:00
log.Printf("botMsgRescanAll : Query : %s\n", p.Query)
2020-02-06 03:23:50 +01:00
p.MsgID64 = int64(m.ID)
p.ChatID64 = m.Chat.ID
2019-05-11 12:45:05 +02:00
b, _ := json.Marshal(p)
2020-01-02 13:04:12 +01:00
_, err := createJob(cacheObjSubType[`job_rescan_msg`], objJobPriorityRescanAllMsg, int64(m.Sender.ID), 0, time.Now().UTC(), b)
logOnError(err, "botMsgRescan : createJob(cacheObjSubType[`job_rescan_msg`])")
2019-05-16 05:35:37 +02:00
2019-05-11 12:45:05 +02:00
if err != nil {
2019-05-16 05:35:37 +02:00
c := TGCommand{
Type: commandReplyMsg,
Text: "Error scheduling the rescan for all msg.",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
2019-05-11 12:45:05 +02:00
} else {
2019-05-16 05:35:37 +02:00
c := TGCommand{
Type: commandReplyMsg,
Text: "Rescaning all msg scheduled.",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
2019-05-11 12:45:05 +02:00
}
2019-05-16 05:35:37 +02:00
return
2019-05-11 12:45:05 +02:00
}
2019-05-18 09:44:25 +02:00
2019-06-11 17:39:04 +02:00
func botBackupExport(m *tb.Message) {
2019-06-08 17:28:07 +02:00
if !m.Private() {
return
}
2019-07-31 07:07:12 +02:00
clt, ok := getLockedClient(m.Chat.ID, false)
if !ok {
2019-06-08 17:28:07 +02:00
c := TGCommand{
Type: commandReplyMsg,
2019-06-11 17:39:04 +02:00
Text: "Client not registered",
2019-06-08 17:28:07 +02:00
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2019-07-31 08:19:09 +02:00
clt.Mux.Unlock()
2019-07-31 07:07:12 +02:00
if clt.TGUserID64 != cfg.Bot.Admin {
c := TGCommand{
Type: commandReplyMsg,
Text: "Admin only",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2019-06-08 17:28:07 +02:00
2019-06-11 17:39:04 +02:00
p := JobPayloadBackupExport{
MsgID64: int64(m.ID),
ChatID64: m.Chat.ID,
2019-06-08 17:28:07 +02:00
}
2019-06-11 17:39:04 +02:00
b, _ := json.Marshal(p)
2020-01-02 13:04:12 +01:00
_, err := createJob(cacheObjSubType[`job_backup_export`], objJobPriorityBackup, int64(m.Sender.ID), 0, time.Now().UTC(), b)
logOnError(err, "botBackupExport : createJob(cacheObjSubType[`job_backup_export`])")
2019-06-08 17:28:07 +02:00
return
}
2019-06-11 17:39:04 +02:00
func botBackupImport(m *tb.Message) {
2019-06-09 10:47:44 +02:00
if !m.Private() {
return
}
2019-07-31 07:07:12 +02:00
clt, ok := getLockedClient(m.Chat.ID, false)
if !ok {
2019-06-10 11:05:59 +02:00
c := TGCommand{
Type: commandReplyMsg,
2019-06-11 17:39:04 +02:00
Text: "Client not registered",
2019-06-10 11:05:59 +02:00
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
2019-06-11 17:39:04 +02:00
return
}
2019-07-31 08:19:09 +02:00
clt.Mux.Unlock()
2019-07-31 07:07:12 +02:00
if clt.TGUserID64 != cfg.Bot.Admin {
c := TGCommand{
Type: commandReplyMsg,
Text: "Admin only",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2019-10-20 07:05:46 +02:00
/*
r := regexp.MustCompile(`^((http[s]?\:)\/\/)?([^\?\:\/#]+)(\:([0-9]+))?(\/[^\?\#]*)?(\?([^#]*))?(#.*)?.zip$`)
if !r.MatchString(m.Payload) {
c := TGCommand{
Type: commandReplyMsg,
Text: "URL not valid.",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
2019-06-09 15:00:15 +02:00
}
2019-10-20 07:05:46 +02:00
*/
2019-06-09 14:17:05 +02:00
2019-06-11 17:55:31 +02:00
p := JobPayloadBackupImport{
2019-06-11 17:39:04 +02:00
URL: m.Payload,
MsgID64: int64(m.ID),
ChatID64: m.Chat.ID,
}
b, _ := json.Marshal(p)
2020-01-02 13:04:12 +01:00
_, err := createJob(cacheObjSubType[`job_backup_import`], objJobPriorityBackup, int64(m.Sender.ID), 0, time.Now().UTC(), b)
logOnError(err, "botBackupImport : createJob(cacheObjSubType[`job_backup_import`])")
2019-06-09 10:47:44 +02:00
return
2019-06-11 17:39:04 +02:00
2019-06-09 10:47:44 +02:00
}
2019-05-18 09:44:25 +02:00
func botMsgDump(m *tb.Message) {
var res string
2019-07-31 07:07:12 +02:00
if !m.Private() {
return
}
clt, ok := getLockedClient(m.Chat.ID, false)
if !ok {
c := TGCommand{
Type: commandReplyMsg,
Text: "Client not registered",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2019-07-31 08:19:09 +02:00
clt.Mux.Unlock()
2019-07-31 07:07:12 +02:00
if clt.TGUserID64 != cfg.Bot.Admin {
c := TGCommand{
Type: commandReplyMsg,
Text: "Admin only",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2019-05-18 09:44:25 +02:00
r := regexp.MustCompile("^[0-9]+$")
if r.MatchString(m.Payload) {
objId, _ := strconv.ParseInt(m.Payload, 10, 64)
2019-05-18 10:12:29 +02:00
objTypeId, err := getObjTypeId(objId)
logOnError(err, "botMsgDump : getObjSubTypeId")
2019-05-18 09:44:25 +02:00
if err != nil {
2019-05-18 10:12:29 +02:00
res = `Error retrieving the message`
2020-01-02 16:33:41 +01:00
} else if objTypeId != cacheObjType[`msg`] {
2019-05-18 09:44:25 +02:00
res = `This is not a message reference`
} else {
2019-06-09 14:17:05 +02:00
cwm, _ := getObjMsg(objId)
2019-05-18 09:44:25 +02:00
b, _ := json.Marshal(cwm)
res = string(b)
}
} else {
res = `/msg_dump <msg_id>`
}
c := TGCommand{
Type: commandReplyMsg,
Text: res,
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2019-05-25 16:36:14 +02:00
func botListParsingRules(m *tb.Message) {
2019-05-25 16:41:07 +02:00
var s string = ""
2019-05-25 16:36:14 +02:00
if !m.Private() {
return
}
2019-07-31 07:07:12 +02:00
clt, ok := getLockedClient(m.Chat.ID, false)
if !ok {
c := TGCommand{
Type: commandReplyMsg,
Text: "Client not registered",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2019-07-31 08:19:09 +02:00
clt.Mux.Unlock()
2019-07-31 07:07:12 +02:00
if clt.TGUserID64 != cfg.Bot.Admin {
c := TGCommand{
Type: commandReplyMsg,
Text: "Admin only",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2019-05-25 16:36:14 +02:00
2019-05-25 16:36:48 +02:00
for _, v := range msgParsingRules {
2019-05-25 16:41:07 +02:00
s = fmt.Sprintf("%s[%d] %s\n", s, v.ID, v.Description)
2019-10-20 11:11:36 +02:00
if len(s) > 3000 {
c := TGCommand{
Type: commandReplyMsg,
Text: s,
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
2019-10-20 11:12:01 +02:00
s = ``
2019-10-20 11:11:36 +02:00
}
2019-05-25 16:36:14 +02:00
}
c := TGCommand{
Type: commandReplyMsg,
Text: s,
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
func botListParsingRule(m *tb.Message) {
2019-05-31 12:41:26 +02:00
if !m.Private() {
return
}
2019-07-31 07:07:12 +02:00
clt, ok := getLockedClient(m.Chat.ID, false)
if !ok {
c := TGCommand{
Type: commandReplyMsg,
Text: "Client not registered",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2019-07-31 08:19:09 +02:00
clt.Mux.Unlock()
2019-07-31 07:07:12 +02:00
if clt.TGUserID64 != cfg.Bot.Admin {
c := TGCommand{
Type: commandReplyMsg,
Text: "Admin only",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2019-05-25 16:36:14 +02:00
r := regexp.MustCompile("^[0-9]+$")
if r.MatchString(m.Payload) {
i, _ := strconv.ParseInt(m.Payload, 10, 64)
2019-05-25 16:36:48 +02:00
for _, v := range msgParsingRules {
2019-05-25 16:37:54 +02:00
if int64(v.ID) == i {
2019-05-25 16:36:14 +02:00
c := TGCommand{
Type: commandReplyMsg,
2019-05-25 16:38:46 +02:00
Text: fmt.Sprintf("%s\n", v.Rule),
2019-05-25 16:36:14 +02:00
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
}
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("Could not find rule %s\n", m.Payload),
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("/parse_rule <id>\n"),
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
return
}
2019-05-26 13:30:21 +02:00
2020-01-26 14:50:41 +01:00
func botGStock(m *ChatWarsMessage) {
2020-02-29 04:16:40 +01:00
if hasUnfinishedJob(cacheObjSubType[`job_gstock`]) {
c := TGCommand{
Type: commandReplyMsg,
Text: "GStock is already running",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
return
}
2019-12-15 08:37:58 +01:00
clt, err := getLockedIdleClient()
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: "Busy, please retry later.",
2020-01-26 14:40:20 +01:00
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
2019-12-15 08:37:58 +01:00
}
TGCmdQueue <- c
2020-01-13 09:03:01 +01:00
return
2019-12-15 08:37:58 +01:00
}
2020-01-27 05:05:38 +01:00
userID64 := clt.TGUserID64
2019-12-15 08:37:58 +01:00
clt.Mux.Unlock()
2019-08-08 14:39:23 +02:00
p := JobPayloadGStock{
2020-01-26 14:40:20 +01:00
MsgID64: m.ID64,
ChatID64: m.ChatID64,
2020-01-26 14:47:13 +01:00
Status: 0,
2019-08-08 14:39:23 +02:00
}
b, _ := json.Marshal(p)
t := time.Now().UTC().Add(1 * time.Second)
2020-01-02 13:04:12 +01:00
_, err = createJob(cacheObjSubType[`job_gstock`], objJobPriority, userID64, 0, t, b)
2019-05-31 12:45:24 +02:00
2019-08-12 09:36:28 +02:00
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("%s", err),
2020-01-26 14:40:20 +01:00
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
2019-08-12 09:36:28 +02:00
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: "Stock requested",
2020-01-26 14:40:20 +01:00
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
2019-08-12 09:36:28 +02:00
}
TGCmdQueue <- c
2019-05-31 12:45:24 +02:00
}
2019-08-12 09:36:28 +02:00
2019-05-31 12:41:26 +02:00
return
}
2020-02-06 11:57:46 +01:00
func botShops(m *ChatWarsMessage) {
2020-02-29 04:16:40 +01:00
if hasUnfinishedJob(cacheObjSubType[`job_shops`]) {
c := TGCommand{
Type: commandReplyMsg,
Text: "Shops is already running",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
return
}
2020-02-06 11:57:46 +01:00
2020-02-29 04:16:40 +01:00
// fan out to all active and non idle clients
2020-02-06 16:23:54 +01:00
clts, err := getAllIdleClientID64()
2020-02-13 09:50:41 +01:00
if err != nil || len(clts) == 0 {
2020-02-06 16:23:54 +01:00
c := TGCommand{
Type: commandReplyMsg,
Text: "Busy, please retry later.",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
2020-02-06 11:57:46 +01:00
}
2020-02-06 16:23:54 +01:00
TGCmdQueue <- c
return
}
2020-02-06 11:57:46 +01:00
2020-02-06 16:23:54 +01:00
j := JobPayloadShops{
Status: 0,
ChatID64: m.ChatID64,
MsgID64: m.ID64,
2020-02-07 03:54:01 +01:00
Msgs: make([]ChatWarsMessage, 0),
2020-02-06 16:23:54 +01:00
}
b, err := json.Marshal(j)
logOnError(err, "botShops : Marshal")
jobID64, err := createJob(cacheObjSubType[`job_shops`], objJobPriority, clts[0], 0, time.Unix(maxUnixTimestamp, 0).UTC(), b)
for i, id := range clts {
j2 := JobPayloadShopsSlave{
JobCallbackID64: jobID64,
Status: 0,
2020-02-06 16:25:48 +01:00
Slaves: int64(len(clts)),
2020-02-06 16:23:54 +01:00
Shops: make([]string, 0),
}
2020-02-11 03:00:00 +01:00
for j, s := range cfg.Bot.Shops {
2020-02-13 09:50:41 +01:00
if (j % len(clts)) == i {
2020-02-11 03:00:00 +01:00
j2.Shops = append(j2.Shops, s.Link)
2020-02-06 11:57:46 +01:00
}
}
2020-02-06 16:23:54 +01:00
b, err = json.Marshal(j2)
logOnError(err, "botShops : Marshal Slave")
_, err = createJob(cacheObjSubType[`job_shops_slave`], objJobPriority, id, 0, time.Now().UTC(), b)
}
2020-02-06 11:57:46 +01:00
c := TGCommand{
Type: commandReplyMsg,
2020-05-08 16:02:18 +02:00
Text: fmt.Sprintf("Shops coming (ETA : %ds)", (len(cfg.Bot.Shops)/len(clts))*8),
2020-02-06 11:57:46 +01:00
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
2020-02-06 16:23:54 +01:00
2020-02-06 11:57:46 +01:00
return
}
2021-01-21 14:52:40 +01:00
func botBrewItem(m *ChatWarsMessage, r *regexp.Regexp) {
2021-01-23 22:40:18 +01:00
/*
if hasUnfinishedJob(cacheObjSubType[`job_brew_item`]) {
c := TGCommand{
Type: commandReplyMsg,
Text: "Brew Item is already running",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
return
2021-01-21 15:15:50 +01:00
}
2021-01-23 22:40:18 +01:00
*/
2021-01-21 14:52:40 +01:00
clt, err := getLockedIdleClient()
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: "Busy, please retry later.",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
return
}
clt.Mux.Unlock()
p := JobPayloadBrewItem{
MsgID64: m.ID64,
ChatID64: m.ChatID64,
Status: 0,
}
2021-01-21 16:36:44 +01:00
p.ObjItemID64 = getObjItemID(r.ReplaceAllString(m.Text, "${Code}"), "")
2021-01-21 14:52:40 +01:00
b, _ := json.Marshal(p)
t := time.Now().UTC().Add(1 * time.Second)
2021-01-21 15:30:39 +01:00
_, err = createJob(cacheObjSubType[`job_brew_item`], objJobPriority, m.TGSenderUserID64, 0, t, b)
2021-01-21 14:52:40 +01:00
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("%s", err),
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: "Brew item coming",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
}
return
}
2020-01-27 05:40:33 +01:00
func botCraftItem(m *ChatWarsMessage, r *regexp.Regexp) {
2020-02-29 04:16:40 +01:00
if hasUnfinishedJob(cacheObjSubType[`job_craft_item`]) {
c := TGCommand{
Type: commandReplyMsg,
Text: "Craft Item is already running",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
return
}
2020-01-27 05:05:38 +01:00
clt, err := getLockedIdleClient()
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: "Busy, please retry later.",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
return
}
userID64 := clt.TGUserID64
clt.Mux.Unlock()
p := JobPayloadCraftItem{
2020-01-27 05:10:21 +01:00
MsgID64: m.ID64,
ChatID64: m.ChatID64,
Status: 0,
}
2020-01-27 05:39:16 +01:00
p.ObjItemID64, err = getCraftItemID(r.ReplaceAllString(m.Text, "${Cmd}"))
logOnError(err, "botCraftItem : getCraftItemID")
2020-01-27 05:41:58 +01:00
2020-01-27 05:42:21 +01:00
if len(r.ReplaceAllString(m.Text, "${Quantity}")) > 0 {
2020-01-27 05:41:58 +01:00
p.Quantity, err = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Quantity}"), 10, 64)
logOnError(err, "botCraftItem : ParseInt")
} else {
p.Quantity = 1
}
2020-01-27 05:39:32 +01:00
2020-01-27 05:10:21 +01:00
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("%s", err),
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
return
2020-01-27 05:05:38 +01:00
}
2020-01-27 05:10:21 +01:00
2020-01-27 05:05:38 +01:00
b, _ := json.Marshal(p)
t := time.Now().UTC().Add(1 * time.Second)
_, err = createJob(cacheObjSubType[`job_craft_item`], objJobPriority, userID64, 0, t, b)
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("%s", err),
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: "Craft summary coming",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
}
return
}
2020-02-10 05:28:16 +01:00
func botUserConfigPillage(m *ChatWarsMessage, set bool) {
clt, _ := getLockedClient(m.TGUserID64, false)
clt.Config.InterceptPillage = set
clt.Mux.Unlock()
botUserConfig(m)
return
}
2020-06-17 12:15:54 +02:00
func botUserConfigDeposit(m *ChatWarsMessage, set bool) {
clt, _ := getLockedClient(m.TGUserID64, false)
clt.Config.AutoDeposit = set
clt.Mux.Unlock()
botUserConfig(m)
return
}
2020-04-07 04:40:53 +02:00
func botUserConfigWartime(m *ChatWarsMessage, set string) {
clt, _ := getLockedClient(m.TGUserID64, false)
clt.Config.Wartime = set
clt.Mux.Unlock()
botUserConfig(m)
return
}
2020-02-10 03:56:05 +01:00
func botUserConfig(m *ChatWarsMessage) {
2020-02-10 05:18:40 +01:00
clt, _ := getLockedClient(m.TGUserID64, false)
clt.Mux.Unlock()
2020-02-10 05:21:35 +01:00
out := fmt.Sprintf("Config for %s (running build %s):\n", clt.Login, clt.Build)
2020-02-10 05:18:40 +01:00
if clt.Config.InterceptPillage {
2020-02-10 05:19:05 +01:00
out = fmt.Sprintf("%s Pillage : ON (<a href=\"https://t.me/share/url?url=/config_pillage_off\">set off</a>)\n", out)
2020-02-10 05:18:40 +01:00
} else {
2020-02-10 05:19:05 +01:00
out = fmt.Sprintf("%s Pillage : OFF (<a href=\"https://t.me/share/url?url=/config_pillage_on\">set on</a>)\n", out)
2020-02-10 05:18:40 +01:00
}
2020-04-07 04:14:20 +02:00
if clt.Config.Wartime == `🛡Defend` {
out = fmt.Sprintf("%s Wartime : DEFEND CASTLE (<a href=\"https://t.me/share/url?url=/config_def_guild\">set to guild</a>)\n", out)
} else {
out = fmt.Sprintf("%s Wartime : DEFEND GUILD (<a href=\"https://t.me/share/url?url=/config_def_castle\">set to castle</a>)\n", out)
}
2020-06-16 19:04:45 +02:00
if clt.Config.AutoDeposit {
out = fmt.Sprintf("%s Deposit : ON (<a href=\"https://t.me/share/url?url=/config_deposit_off\">set off</a>)\n", out)
if len(clt.Config.AutoDepositItems) == 0 {
out = fmt.Sprintf("%s <a href=\"https://t.me/share/url?url=/config_dep_add_item\">Add individual items</a>\n", out)
} else {
out = fmt.Sprintf("%s Individual items\n", out)
for _, v := range clt.Config.AutoDepositItems {
2020-06-16 19:08:40 +02:00
o, err := getObjItem(getObjItemID(v, ``))
2020-06-16 19:07:12 +02:00
logOnError(err, "botUserConfig : getObjItem("+v+")")
2020-06-17 13:14:40 +02:00
out = fmt.Sprintf("%s %s (<a href=\"https://t.me/share/url?url=/config_dep_del_item %s\">remove</a>)\n", out, o.Names[0], o.Code)
2020-06-16 19:04:45 +02:00
}
}
if len(clt.Config.AutoDepositTypes) == 0 {
out = fmt.Sprintf("%s <a href=\"https://t.me/share/url?url=/config_dep_add_type\">Add item types</a>\n", out)
} else {
out = fmt.Sprintf("%s Item types\n", out)
2020-06-16 19:09:51 +02:00
for _, v := range clt.Config.AutoDepositTypes {
2020-06-17 13:14:40 +02:00
out = fmt.Sprintf("%s %s (<a href=\"https://t.me/share/url?url=/config_dep_del_type %s\">remove</a>)\n", out, v, v)
2020-06-16 19:04:45 +02:00
}
}
} else {
out = fmt.Sprintf("%s Deposit : OFF (<a href=\"https://t.me/share/url?url=/config_deposit_on\">set on</a>)\n", out)
}
2020-02-10 03:56:05 +01:00
c := TGCommand{
Type: commandReplyMsg,
2020-02-10 05:18:40 +01:00
Text: out,
2020-02-10 03:56:05 +01:00
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
2020-02-10 05:20:29 +01:00
ParseMode: cmdParseModeHTML,
2020-02-10 03:56:05 +01:00
}
TGCmdQueue <- c
return
}
2020-06-26 11:45:56 +02:00
func botRefreshMsg(m *ChatWarsMessage, r *regexp.Regexp) {
p := JobPayloadMsgRefresh{}
p.ObjID64, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${MsgID}"), 10, 64)
b, _ := json.Marshal(p)
t := time.Now().UTC().Add(1 * time.Second)
_, err := createJob(cacheObjSubType[`job_msg_refresh`], objJobPriority, m.TGSenderUserID64, 0, t, b)
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("%s", err),
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: "Refresh scheduled",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
}
return
}
2020-06-28 13:12:05 +02:00
func botVaultVal(m *ChatWarsMessage) {
p := JobPayloadVaultVal{
MsgID64: m.ID64,
ChatID64: m.ChatID64,
Status: 0,
}
b, _ := json.Marshal(p)
t := time.Now().UTC().Add(1 * time.Second)
2020-06-28 13:19:39 +02:00
_, err := createJob(cacheObjSubType[`job_vault_val`], objJobPriority, m.TGSenderUserID64, 0, t, b)
2020-06-28 13:12:05 +02:00
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("%s", err),
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: "Vault val coming",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
}
return
}
2020-08-08 12:02:21 +02:00
func botVaultValOth(m *ChatWarsMessage) {
p := JobPayloadVaultValOth{
MsgID64: m.ID64,
ChatID64: m.ChatID64,
Status: 0,
}
b, _ := json.Marshal(p)
t := time.Now().UTC().Add(1 * time.Second)
_, err := createJob(cacheObjSubType[`job_vault_val_oth`], objJobPriority, m.TGSenderUserID64, 0, t, b)
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("%s", err),
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: "Vault val (other) coming",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
}
return
}
2020-02-29 09:43:04 +01:00
func botAlchAll(m *ChatWarsMessage) {
p := JobPayloadAlchAll{
MsgID64: m.ID64,
ChatID64: m.ChatID64,
Status: 0,
2020-02-29 11:25:48 +01:00
ManaNow: 0,
2020-02-29 09:47:15 +01:00
ManaMax: 0,
2020-02-29 09:43:04 +01:00
}
b, _ := json.Marshal(p)
t := time.Now().UTC().Add(1 * time.Second)
2020-02-29 09:47:15 +01:00
_, err := createJob(cacheObjSubType[`job_alch_all`], objJobPriority, m.TGSenderUserID64, 0, t, b)
2020-02-29 09:43:04 +01:00
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("%s", err),
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: "Alch all coming",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
}
return
}
2020-02-01 08:25:33 +01:00
func botCraftAll(m *ChatWarsMessage, r *regexp.Regexp) {
2020-02-29 04:16:40 +01:00
if hasUnfinishedJob(cacheObjSubType[`job_craft_all`]) {
c := TGCommand{
Type: commandReplyMsg,
Text: "Craft All is already running",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
return
}
2020-02-01 08:25:33 +01:00
clt, err := getLockedIdleClient()
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: "Busy, please retry later.",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
return
}
userID64 := clt.TGUserID64
clt.Mux.Unlock()
p := JobPayloadCraftAll{
MsgID64: m.ID64,
ChatID64: m.ChatID64,
Status: 0,
}
b, _ := json.Marshal(p)
t := time.Now().UTC().Add(1 * time.Second)
_, err = createJob(cacheObjSubType[`job_craft_all`], objJobPriority, userID64, 0, t, b)
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("%s", err),
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: "Craft all coming",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
}
return
}
2020-06-19 21:28:59 +02:00
func botGetStash(m *ChatWarsMessage, r *regexp.Regexp) {
2020-06-19 21:44:10 +02:00
var (
2020-06-19 21:44:29 +02:00
userID64 int64 = 0
2020-06-19 21:44:10 +02:00
userBusyUntil time.Time
)
2020-06-19 21:28:59 +02:00
if hasUnfinishedJob(cacheObjSubType[`job_get_stash`]) {
c := TGCommand{
Type: commandReplyMsg,
Text: "Get Stash is already running",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
return
}
p := JobPayloadGetStash{
MsgID64: m.ID64,
ChatID64: m.ChatID64,
ClientCount: 0,
2020-06-29 12:53:06 +02:00
Stash: make(map[int64]int64),
2020-06-19 21:28:59 +02:00
}
busy := time.Now().UTC()
muxClients.RLock()
for _, c := range clients {
if c.Active {
p.ClientCount++
p.ClientID64 = append(p.ClientID64, c.TGUserID64)
2020-06-19 21:44:10 +02:00
if userID64 == 0 {
userID64 = c.TGUserID64
userBusyUntil = c.CWBusyUntil
} else if userBusyUntil.After(c.CWBusyUntil) {
userID64 = c.TGUserID64
userBusyUntil = c.CWBusyUntil
}
2020-06-19 21:30:38 +02:00
if c.CWBusyUntil.After(busy) {
2020-06-19 21:28:59 +02:00
busy = c.CWBusyUntil
}
}
}
muxClients.RUnlock()
2020-06-19 21:44:10 +02:00
if p.ClientCount == 0 {
c := TGCommand{
Type: commandReplyMsg,
Text: "No clients online.",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
return
}
2020-06-19 21:28:59 +02:00
b, _ := json.Marshal(p)
t := time.Now().UTC().Add(1 * time.Second)
2020-06-19 21:44:47 +02:00
_, err := createJob(cacheObjSubType[`job_get_stash`], objJobPriority, userID64, 0, t, b)
2020-06-19 21:28:59 +02:00
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("%s", err),
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
} else if busy.After(time.Now().UTC()) {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("Clients busy, delayed for %v.", busy.Sub(time.Now().UTC())),
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: "Stash coming.",
FromMsgID64: m.ID64,
FromChatID64: m.ChatID64,
}
TGCmdQueue <- c
}
return
}
2019-09-14 10:27:38 +02:00
func botSaveRes(m *tb.Message) {
if !m.Private() {
return
}
c := TGCommand{
Type: commandReplyMsg,
Text: "Not coded yet.",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
2019-10-10 12:18:44 +02:00
func botVaultHelp(m *tb.Message) {
2019-10-11 10:20:10 +02:00
if !(m.Private() || m.Chat.ID == cfg.Bot.Mainchat) {
2019-10-10 12:18:44 +02:00
return
}
c := TGCommand{
Type: commandReplyMsg,
Text: `
/vault_all <user> - All items
/vault_res <user> - Resources
/vault_alch <user> - Alchemy
/vault_misc <user> - Miscellaneous
/vault_rec <user> - Recipes
/vault_part <user> - Parts
2019-10-13 09:25:02 +02:00
/vault_other <user> - Other
/vault_item <code>... - Specific items`,
2019-10-10 12:18:44 +02:00
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
2019-10-11 06:00:25 +02:00
func botVaultAll(m *tb.Message) {
2020-01-02 13:10:17 +01:00
l := []int64{cacheObjSubType[`item_res`], cacheObjSubType[`item_alch`], cacheObjSubType[`item_misc`], cacheObjSubType[`item_recipe`], cacheObjSubType[`item_part`], cacheObjSubType[`item_other`]}
2019-10-11 06:00:25 +02:00
botVault(m, l)
}
func botVaultRes(m *tb.Message) {
2020-01-02 13:10:17 +01:00
l := []int64{cacheObjSubType[`item_res`]}
2019-10-11 06:00:25 +02:00
botVault(m, l)
}
func botVaultAlch(m *tb.Message) {
2020-01-02 13:10:17 +01:00
l := []int64{cacheObjSubType[`item_alch`]}
2019-10-11 06:00:25 +02:00
botVault(m, l)
}
func botVaultMisc(m *tb.Message) {
2020-01-02 13:10:17 +01:00
l := []int64{cacheObjSubType[`item_misc`]}
2019-10-11 06:00:25 +02:00
botVault(m, l)
}
func botVaultRec(m *tb.Message) {
2020-01-02 13:10:17 +01:00
l := []int64{cacheObjSubType[`item_recipe`]}
2019-10-11 06:00:25 +02:00
botVault(m, l)
}
func botVaultPart(m *tb.Message) {
2020-01-02 13:10:17 +01:00
l := []int64{cacheObjSubType[`item_part`]}
2019-10-11 06:00:25 +02:00
botVault(m, l)
}
func botVaultOther(m *tb.Message) {
2020-01-02 13:10:17 +01:00
l := []int64{cacheObjSubType[`item_other`]}
2019-10-11 06:00:25 +02:00
botVault(m, l)
}
2019-10-12 07:47:40 +02:00
func botVaultItem(m *tb.Message) {
2019-10-13 09:20:23 +02:00
if !(m.Private() || m.Chat.ID == cfg.Bot.Mainchat) {
return
}
p := JobPayloadVaultItemStatus{
ItemListID64: nil,
DepositChatID64: cfg.Bot.Depositchat,
UserID64: int64(m.Sender.ID),
}
2020-01-18 08:59:26 +01:00
r := regexp.MustCompile("([a-z][0-9]{2}[a-e]{0,1}|([0-9]{2}))")
2019-10-13 09:21:51 +02:00
for _, l := range r.FindAllStringSubmatch(m.Payload, -1) {
2019-10-13 09:20:23 +02:00
item := getObjItemID(l[1], ``)
if item != 0 {
p.ItemListID64 = append(p.ItemListID64, item)
}
}
if len(p.ItemListID64) > 0 {
b, _ := json.Marshal(p)
t := time.Now().UTC()
2020-01-02 13:04:12 +01:00
_, err := createJob(cacheObjSubType[`job_vault_item_status`], objJobPriority, int64(m.Sender.ID), 0, t, b)
2019-10-13 09:20:23 +02:00
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: `/vault_item <code> ...`,
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
return
2019-10-12 07:47:40 +02:00
}
2019-10-11 07:42:33 +02:00
func botVault(m *tb.Message, itemTypeList []int64) {
2019-10-11 06:00:25 +02:00
/*
b, _ := json.Marshal(m)
log.Printf("botVault (msg) :\n%s\n", string(b))
for _, e := range m.Entities {
if e.Type == tb.EntityMention {
log.Printf("botVault (user) : %s\n", m.Text[e.Offset:e.Offset+e.Length])
}
2019-10-11 04:39:26 +02:00
}
2019-10-11 06:00:25 +02:00
*/
2019-10-11 10:19:13 +02:00
if !(m.Private() || m.Chat.ID == cfg.Bot.Mainchat) {
2019-10-10 12:18:44 +02:00
return
}
2019-10-12 07:47:40 +02:00
p := JobPayloadVaultUserStatus{
2019-10-11 10:28:25 +02:00
UserID64: int64(m.Sender.ID),
2019-10-11 07:42:33 +02:00
UserListID64: nil,
ItemTypeListID64: nil,
DepositChatID64: cfg.Bot.Depositchat,
2019-10-10 12:18:44 +02:00
}
2019-10-11 07:46:41 +02:00
p.UserListID64 = append(p.UserListID64, int64(m.Sender.ID))
2019-10-11 07:45:03 +02:00
p.ItemTypeListID64 = append(p.ItemTypeListID64, itemTypeList...)
2019-10-11 07:42:33 +02:00
b, _ := json.Marshal(p)
t := time.Now().UTC()
2020-01-02 13:04:12 +01:00
_, err := createJob(cacheObjSubType[`job_vault_user_status`], objJobPriority, int64(m.Sender.ID), 0, t, b)
2019-10-11 07:42:33 +02:00
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("%s", err),
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
return
2019-10-10 12:18:44 +02:00
}
2019-08-16 12:29:07 +02:00
func botGDepositAll(m *tb.Message) {
if !m.Private() {
return
}
p := JobPayloadGDeposit{
2019-08-19 12:41:43 +02:00
MsgID64: int64(m.ID),
ChatID64: m.Chat.ID,
ResObjID64: nil,
2019-08-21 05:46:42 +02:00
Status: 0,
2019-08-16 12:29:07 +02:00
}
2019-08-19 12:41:43 +02:00
2019-08-29 14:15:26 +02:00
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`01`, `Thread`))
2019-10-19 11:55:16 +02:00
if m.Sender.ID != 480149577 {
2019-10-19 11:54:39 +02:00
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`02`, `Stick`))
}
2019-08-30 04:50:06 +02:00
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`03`, `Pelt`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`04`, `Bone`))
2020-01-23 07:09:07 +01:00
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`05`, `Coal`))
2019-08-30 04:50:06 +02:00
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`07`, `Powder`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`08`, `Iron Ore`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`09`, `Cloth`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`10`, `Silver Ore`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`11`, `Bauxite`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`13`, `Magic Stone`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`14`, `Wooden Shaft`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`15`, `Sapphire`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`17`, `Ruby`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`18`, `Hardener`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`19`, `Steel`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`21`, `Bone Powder`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`22`, `String`))
2019-10-19 11:55:16 +02:00
if m.Sender.ID != 480149577 {
2019-10-19 11:54:39 +02:00
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`23`, `Coke`))
}
2019-08-30 04:50:06 +02:00
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`24`, `Purified Powder`))
2020-01-28 10:54:26 +01:00
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`28`, `Silver mold`))
2019-08-30 04:50:06 +02:00
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`31`, `Rope`))
2019-10-11 08:56:10 +02:00
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`33`, `Metal Plate`))
2019-09-09 08:18:03 +02:00
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`34`, `Metallic Fiber`))
2019-09-09 08:15:59 +02:00
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`35`, `Crafted Leather`))
2019-08-30 05:07:37 +02:00
2020-01-02 13:10:17 +01:00
list := getSQLListID64(fmt.Sprintf("select o.id from obj o where o.obj_sub_type_id = %d;", cacheObjSubType[`item_recipe`]))
2019-08-30 05:07:37 +02:00
p.ResObjID64 = append(p.ResObjID64, list...)
2020-01-02 13:10:17 +01:00
list = getSQLListID64(fmt.Sprintf("select o.id from obj o where o.obj_sub_type_id = %d;", cacheObjSubType[`item_part`]))
2019-08-30 05:07:37 +02:00
p.ResObjID64 = append(p.ResObjID64, list...)
2019-08-29 14:15:26 +02:00
/*
2019-08-30 04:50:06 +02:00
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`39`, `Stinky Sumac`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`s01`, `📕Scroll of Rage`))
p.ResObjID64 = append(p.ResObjID64, getObjItemID(`w07`, `Rapier`))
2019-08-29 14:15:26 +02:00
*/
2019-08-19 12:41:43 +02:00
2019-08-16 12:29:07 +02:00
b, _ := json.Marshal(p)
t := time.Now().UTC()
2020-01-02 13:04:12 +01:00
_, err := createJob(cacheObjSubType[`job_gdeposit`], objJobPriority, int64(m.Chat.ID), 0, t, b)
2019-08-16 12:29:07 +02:00
2019-08-30 12:19:13 +02:00
//log.Printf("botGDepositAll : json : %s\n", string(b))
2019-08-21 06:08:11 +02:00
2019-08-16 12:29:07 +02:00
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: "Deposit started",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
2019-08-16 12:29:07 +02:00
}
return
}
2019-10-02 06:43:27 +02:00
func botGWithdraw(m *tb.Message) {
if !m.Private() {
return
}
2019-10-04 12:38:03 +02:00
2020-01-13 09:03:01 +01:00
clt, err := getLockedIdleClient()
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: "Busy, please retry later.",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2020-01-14 07:30:25 +01:00
userID64 := clt.TGUserID64
2020-01-13 09:03:01 +01:00
clt.Mux.Unlock()
2019-10-04 12:38:03 +02:00
r := regexp.MustCompile("^(( )*[a-z0-9]+ [0-9]+( )*)+$")
if r.MatchString(m.Payload) {
2020-01-05 10:42:29 +01:00
rx := regexp.MustCompile("(?P<Item>[a-z0-9]+) (?P<Quantity>[0-9]+)")
2019-10-02 06:47:17 +02:00
p := JobPayloadGWithdraw{
2020-01-14 05:10:52 +01:00
MsgID64: int64(m.ID),
ChatID64: m.Chat.ID,
2020-01-17 05:24:07 +01:00
UserID64: int64(m.Sender.ID),
2020-01-14 05:10:52 +01:00
Status: 0,
Validated: false,
2019-10-02 06:47:17 +02:00
}
2020-01-14 04:34:29 +01:00
items := []JobPayloadGWithdrawItem{}
2020-01-05 07:23:36 +01:00
for _, l := range rx.FindAllStringSubmatch(m.Payload, -1) {
2020-01-05 10:45:54 +01:00
log.Printf("botGWithdraw : %s / %s / %s\n", l[0], l[1], l[2])
2020-01-05 10:46:50 +01:00
i := l[1]
q, _ := strconv.ParseInt(l[2], 10, 64)
2020-01-14 04:34:29 +01:00
item := JobPayloadGWithdrawItem{
Code: i,
Required: q,
2020-01-05 10:44:49 +01:00
}
items = append(items, item)
2020-01-05 07:23:36 +01:00
}
2020-01-14 04:34:29 +01:00
p.Items = items
2020-01-05 07:23:36 +01:00
2019-10-04 12:38:03 +02:00
b, _ := json.Marshal(p)
t := time.Now().UTC()
2020-01-14 07:30:04 +01:00
_, err := createJob(cacheObjSubType[`job_gwithdraw`], objJobPriority, userID64, 0, t, b)
//_, err := createJob(cacheObjSubType[`job_gwithdraw`], objJobPriority, cfg.Bot.Admin, 0, t, b)
2019-10-09 04:12:19 +02:00
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("%s", err),
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
2020-01-05 08:27:07 +01:00
} else {
log.Printf("botGWithdraw : %s\n", string(b))
2019-10-02 06:43:27 +02:00
}
2019-10-09 04:12:19 +02:00
2019-10-02 06:43:27 +02:00
} else {
c := TGCommand{
Type: commandReplyMsg,
2019-10-09 04:12:19 +02:00
Text: "Wrong format",
2019-10-02 06:43:27 +02:00
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
return
}
2019-05-26 13:30:21 +02:00
func botTimer(m *tb.Message) {
2019-07-31 07:07:12 +02:00
if !m.Private() {
return
}
clt, ok := getLockedClient(m.Chat.ID, false)
if !ok {
c := TGCommand{
Type: commandReplyMsg,
Text: "Client not registered",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2019-07-31 08:19:09 +02:00
clt.Mux.Unlock()
2019-07-31 07:07:12 +02:00
2019-05-26 14:02:27 +02:00
r := regexp.MustCompile("^(?P<Duration>([0-9]*(s|m|h))+) \"(?P<Msg>(.*))\"$")
2019-05-26 13:30:21 +02:00
if r.MatchString(m.Payload) {
2019-05-26 14:40:37 +02:00
d, err := time.ParseDuration(r.ReplaceAllString(m.Payload, "${Duration}"))
if err != nil {
c := TGCommand{
Type: commandReplyMsg,
2019-05-26 14:41:35 +02:00
Text: fmt.Sprintf("%s", err),
2019-05-26 14:40:37 +02:00
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
} else {
2019-05-30 06:12:01 +02:00
p := JobPayloadMsgClient{
2019-06-03 03:01:18 +02:00
Text: r.ReplaceAllString(m.Payload, "${Msg}"),
MsgID64: int64(m.ID),
ChatID64: m.Chat.ID,
2019-05-26 15:06:12 +02:00
}
2019-05-30 06:12:01 +02:00
b, _ := json.Marshal(p)
2019-08-08 14:39:23 +02:00
t := time.Now().UTC().Add(d)
2020-01-02 13:04:12 +01:00
objID64, err := createJob(cacheObjSubType[`job_msg_client`], objJobPriority, int64(m.Chat.ID), 0, t, b)
2019-05-26 15:08:14 +02:00
logOnError(err, "botTimer : createJob")
2019-05-26 15:46:54 +02:00
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,
2020-07-19 16:55:55 +02:00
Text: fmt.Sprintf("Job #%d scheduled at %s", objID64, t.Format(time.RFC850)),
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
}
}
2020-07-19 16:58:27 +02:00
r = regexp.MustCompile("^(?P<User>([0-9]+)) (?P<Duration>([0-9]*(s|m|h))+) \"(?P<Msg>(.*))\"$")
2020-07-19 16:55:55 +02:00
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 {
2020-07-19 16:57:39 +02:00
userID, _ := strconv.ParseInt(r.ReplaceAllString(m.Text, "${User}"), 10, 64)
2020-07-19 16:55:55 +02:00
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,
2019-05-26 15:47:35 +02:00
Text: fmt.Sprintf("Job #%d scheduled at %s", objID64, t.Format(time.RFC850)),
2019-05-26 15:46:54 +02:00
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
2019-05-26 14:40:37 +02:00
}
2019-05-26 13:30:21 +02:00
}
2019-05-26 15:06:12 +02:00
2019-05-26 13:30:21 +02:00
return
}
2019-06-28 13:04:08 +02:00
2020-10-11 12:53:15 +02:00
func botCleanupJob(m *tb.Message) {
if !m.Private() {
return
}
clt, ok := getLockedClient(m.Chat.ID, false)
if !ok {
c := TGCommand{
Type: commandReplyMsg,
Text: "Client not registered",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
clt.Mux.Unlock()
c := TGCommand{
Type: commandReplyMsg,
Text: "Cleanup started",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
cleanupJobData()
return
}
2020-05-08 16:02:18 +02:00
func botRestartJob(m *tb.Message) {
if !m.Private() {
return
}
clt, ok := getLockedClient(m.Chat.ID, false)
if !ok {
c := TGCommand{
Type: commandReplyMsg,
Text: "Client not registered",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
clt.Mux.Unlock()
if len(m.Payload) > 0 {
jobID64, err := strconv.ParseInt(m.Payload, 10, 64)
if err != nil {
logOnError(err, "botRestartJob : ParseInt")
c := TGCommand{
Type: commandReplyMsg,
Text: "error",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
2020-05-08 16:05:01 +02:00
err = rescheduleJob(jobID64, 0, time.Now().UTC())
2020-05-08 16:02:18 +02:00
c := TGCommand{
Type: commandReplyMsg,
Text: "done",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
}
c := TGCommand{
Type: commandReplyMsg,
Text: "no Job ID",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
return
return
}
2019-06-28 13:04:08 +02:00
func botGetItemId(m *tb.Message) {
if len(m.Payload) > 0 {
objItemID64 := getObjItemID(``, m.Payload)
if objItemID64 != 0 {
c := TGCommand{
Type: commandReplyMsg,
Text: fmt.Sprintf("Identified item #%d", objItemID64),
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: "Can''t identify item",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
} else {
c := TGCommand{
Type: commandReplyMsg,
Text: "No item name to identify",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
}
return
}
2020-02-14 04:08:19 +01:00
func botShutdown() {
os.Exit(0)
}