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"
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
b . Handle ( "/hello" , func ( m * tb . Message ) {
2019-05-10 04:52:14 +02:00
s , err := botHello ( m )
logOnError ( err , "/hello" )
if err == nil {
b . Send ( m . Sender , s )
}
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 )
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-05-31 12:41:26 +02:00
b . Handle ( "/g_stock" , botGStock )
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
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 ( )
}
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-10 04:50:40 +02:00
func botHello ( m * tb . Message ) ( string , error ) {
2019-05-10 04:26:37 +02:00
fmt . Println ( "botHello :" , m . Text )
2019-05-03 05:58:36 +02:00
if ! m . Private ( ) {
2019-05-10 04:26:37 +02:00
fmt . Println ( "botHello : !m.Private()" )
2019-05-10 04:51:15 +02:00
return ` ` , nil
2019-05-03 05:58:36 +02:00
}
// fmt.Println("Hello payload :", m.Payload) // <PAYLOAD>
PrintText ( m )
2019-05-10 04:51:15 +02:00
return ` hello world ` , nil
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
2019-12-29 12:04:23 +01:00
if ( m . Chat . ID == cfg . Bot . Depositchat || m . Chat . ID == cfg . Bot . Mainchat ) && m . IsForwarded ( ) && 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
}
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
}
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 ( )
2019-07-09 09:49:02 +02:00
var ret string
2019-07-31 07:07:12 +02:00
for id , c := range clients {
if c . Active {
2019-07-31 09:53:04 +02:00
ret = fmt . Sprintf ( "%s%s | UserID : %d | TelegramID : %d (online)\n" , ret , c . Login , c . CWUserID64 , id )
2019-07-09 10:06:02 +02:00
} else {
2019-07-31 09:53:04 +02:00
ret = fmt . Sprintf ( "%s%s | UserID : %d | TelegramID : %d (offline)\n" , ret , c . Login , c . CWUserID64 , id )
2019-07-09 10:01:02 +02:00
}
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
}
2019-05-11 12:45:05 +02:00
p := JobPayloadRescanMsg {
2020-01-02 16:33:41 +01:00
Query : fmt . Sprintf ( "SELECT o.id FROM obj o WHERE o.obj_type_id = %d AND o.obj_sub_type_id = %d ORDER BY id ASC;" , cacheObjType [ ` msg ` ] , cacheObjSubType [ ` msg ` ] ) ,
2019-05-15 12:31:03 +02:00
MsgID64 : int64 ( m . ID ) ,
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
2019-05-31 12:41:26 +02:00
func botGStock ( m * tb . Message ) {
2019-12-14 07:58:28 +01:00
if m . Private ( ) {
clt , ok := getLockedClient ( m . Chat . ID , false )
if ! ok {
return
}
clt . Mux . Unlock ( )
} else if m . Chat . ID != cfg . Bot . Mainchat {
2019-05-31 12:41:26 +02:00
return
}
2019-08-08 14:39:23 +02:00
2019-12-15 08:37:58 +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
}
userID64 := clt . TGUserID64
clt . Mux . Unlock ( )
2019-08-08 14:39:23 +02:00
p := JobPayloadGStock {
MsgID64 : int64 ( m . ID ) ,
ChatID64 : m . Chat . ID ,
2019-12-13 12:19:52 +01:00
Progress : 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 ) ,
FromMsgID64 : int64 ( m . ID ) ,
FromChatID64 : m . Chat . ID ,
}
TGCmdQueue <- c
} else {
c := TGCommand {
Type : commandReplyMsg ,
Text : "Stock requested" ,
FromMsgID64 : int64 ( m . ID ) ,
FromChatID64 : m . Chat . ID ,
}
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
}
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 ) ,
}
r := regexp . MustCompile ( "([a-z][0-9]{2}[a-e]{0,1})" )
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 ` ) )
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 ` ) )
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
2019-08-30 09:26:32 +02:00
} 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
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 {
MsgID64 : int64 ( m . ID ) ,
ChatID64 : m . Chat . ID ,
Status : 0 ,
}
2020-01-05 07:23:36 +01:00
items := [ ] ChatWarsItems { }
for _ , l := range rx . FindAllStringSubmatch ( m . Payload , - 1 ) {
2020-01-05 10:43:23 +01:00
log . Printf ( "botGWithdraw : %v\n" , l )
/ *
i := r . ReplaceAllString ( l , "${Item}" )
q , _ := strconv . ParseInt ( r . ReplaceAllString ( l , "${Quantity}" ) , 10 , 64 )
item := ChatWarsItems {
Item : i ,
Quantity : q ,
}
items = append ( items , item )
* /
2020-01-05 07:23:36 +01:00
}
p . Request = items
2019-10-04 12:38:03 +02:00
b , _ := json . Marshal ( p )
t := time . Now ( ) . UTC ( )
2020-01-02 13:04:12 +01:00
_ , err := createJob ( cacheObjSubType [ ` job_gwithdraw ` ] , objJobPriority , int64 ( m . Chat . ID ) , 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 ,
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
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
}