2019-04-15 12:55:00 +02:00
package main
import (
2019-05-03 10:00:30 +02:00
"crypto/md5"
"encoding/base32"
"encoding/json"
"fmt"
"math/rand"
"regexp"
"strconv"
"strings"
"sync"
"time"
"github.com/Arman92/go-tdlib"
// "github.com/go-web/tokenizer"
// "database/sql"
// _ "github.com/go-sql-driver/mysql"
2019-04-15 12:55:00 +02:00
)
type ChatWarsWithdraw struct {
2019-05-03 10:00:30 +02:00
Item string ` json:"item" `
Quantity int64 ` json:"quantity" `
UserID64 int64 ` json:"user_id" `
Time time . Time ` json:"time" `
2019-04-15 12:55:00 +02:00
}
2019-05-03 10:00:30 +02:00
const user_chtwrsbot = 408101137
const user_botnestbot = 541634211
2019-04-15 12:55:00 +02:00
const user_chtwrscastlebot = 526586204
2019-05-03 10:00:30 +02:00
const chat_darkwing = - 1001152534174
const chat_guild_deposit = - 1001179598662
const chat_guild = - 1001152534174
const chat_private = - 1001092914472
2019-04-15 12:55:00 +02:00
var ownUserID64 = int64 ( 0 )
var ownUserID32 = int32 ( 0 )
var msgMutex sync . Mutex
var msgID64 = int64 ( 0 )
var msgUserID64 = int64 ( 0 )
var msgText string
var vault Vault
var size int
var withdrawItem string
var withdrawUserID64 int64
var withdrawTime time . Time
var aesKey [ ] byte
var hmacKey [ ] byte
var withdrawals = map [ string ] ChatWarsWithdraw { }
var TgEncoding * base32 . Encoding
func main ( ) {
2019-05-03 10:00:30 +02:00
// msgMutex = &sync.Mutex{}
tdlib . SetLogVerbosityLevel ( 1 )
tdlib . SetFilePath ( "./errors.txt" )
TgEncoding = base32 . StdEncoding . WithPadding ( base32 . NoPadding )
// Create new instance of client
client := tdlib . NewClient ( tdlib . Config {
APIID : "187786" ,
APIHash : "e782045df67ba48e441ccb105da8fc85" ,
SystemLanguageCode : "en" ,
DeviceModel : "Shoogram" ,
SystemVersion : "1.3.3.7" ,
ApplicationVersion : "3.1.3.3.7" ,
UseMessageDatabase : true ,
UseFileDatabase : true ,
UseChatInfoDatabase : true ,
UseTestDataCenter : false ,
DatabaseDirectory : "./tdlib-db" ,
FileDirectory : "./tdlib-files" ,
IgnoreFileNames : false ,
} )
for {
currentState , _ := client . Authorize ( )
if currentState . GetAuthorizationStateEnum ( ) == tdlib . AuthorizationStateWaitPhoneNumberType {
fmt . Print ( "Enter phone: " )
var number string
fmt . Scanln ( & number )
_ , err := client . SendPhoneNumber ( number )
if err != nil {
fmt . Printf ( "Error sending phone number: %v" , err )
}
} else if currentState . GetAuthorizationStateEnum ( ) == tdlib . AuthorizationStateWaitCodeType {
fmt . Print ( "Enter code: " )
var code string
fmt . Scanln ( & code )
_ , err := client . SendAuthCode ( code )
if err != nil {
fmt . Printf ( "Error sending auth code : %v" , err )
}
} else if currentState . GetAuthorizationStateEnum ( ) == tdlib . AuthorizationStateWaitPasswordType {
fmt . Print ( "Enter Password: " )
var password string
fmt . Scanln ( & password )
_ , err := client . SendAuthPassword ( password )
if err != nil {
fmt . Printf ( "Error sending auth password: %v" , err )
}
} else if currentState . GetAuthorizationStateEnum ( ) == tdlib . AuthorizationStateReadyType {
fmt . Println ( "Authorization Ready! Let's rock" )
break
}
}
ownUserID32 = OwnUserID ( client )
ownUserID64 = int64 ( OwnUserID ( client ) )
go PillageKnight ( client )
go ListenDarkwing ( client )
go ListenCW ( client )
2019-11-10 10:56:43 +01:00
// go ListenAll(client)
2019-05-03 10:00:30 +02:00
go ListenGuild ( client )
// go ForwardOwnMsg(client)
fmt . Println ( "Started !" )
// Main loop
for {
time . Sleep ( 30 * time . Second )
}
2019-04-15 12:55:00 +02:00
}
func PillageKnight ( c * tdlib . Client ) {
2019-05-03 10:00:30 +02:00
eventFilter := func ( msg * tdlib . TdMessage ) bool {
updateMsg := ( * msg ) . ( * tdlib . UpdateNewMessage )
chatID := updateMsg . Message . ChatID
senderUserID := updateMsg . Message . SenderUserID
// viaBotUserID := updateMsg.Message.ViaBotUserID
// fmt.Println("UpdateNewMessage : chatID : ", chatID)
// fmt.Println("UpdateNewMessage : senderUserID : ", senderUserID)
// fmt.Println("UpdateNewMessage : viaBotUserID : ", viaBotUserID)
if senderUserID == user_chtwrsbot && chatID == user_chtwrsbot {
return true
}
return false
}
2019-04-15 12:55:00 +02:00
2019-05-03 10:00:30 +02:00
receiver := c . AddEventReceiver ( & tdlib . UpdateNewMessage { } , eventFilter , 100 )
for newMsg := range receiver . Chan {
updateMsg := ( newMsg ) . ( * tdlib . UpdateNewMessage )
// senderUserID := updateMsg.Message.SenderUserID
mType := updateMsg . Message . Content . GetMessageContentEnum ( )
if mType == "messageText" {
/ *
user , err := c . GetUser ( senderUserID )
if err != nil {
fmt . Println ( "Pillage:" , err . Error ( ) )
continue
}
* /
txt := updateMsg . Message . Content . ( * tdlib . MessageText ) . Text . Text
for _ , line := range strings . Split ( strings . TrimSuffix ( txt , "\n" ) , "\n" ) {
match , _ := regexp . MatchString ( "You were strolling around on your horse.*To stop him click /go.*" , line )
if match {
fmt . Println ( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! PILLAGE KNIGHT INCOMING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" )
time . Sleep ( 1 * time . Second )
fwdMsg := ForwardMsg ( c , updateMsg . Message . ID , updateMsg . Message . ChatID , ownUserID64 )
delay := rand . Intn ( 20 )
fmt . Println ( "Delaying reply by" , delay + 5 , "seconds" )
time . Sleep ( time . Duration ( delay ) * time . Second )
c . SetOption ( "online" , tdlib . NewOptionValueBoolean ( true ) )
time . Sleep ( 5 * time . Second )
inputMsgTxt := tdlib . NewInputMessageText ( tdlib . NewFormattedText ( "/go\n" , nil ) , true , true )
msgMutex . Lock ( )
sendMsg , _ := c . SendMessage ( updateMsg . Message . ChatID , 0 , false , false , nil , inputMsgTxt )
msgID64 = sendMsg . ID
msgText = string ( "/go" )
fmt . Println ( "send msgID64 (go) : " , msgID64 )
delay = rand . Intn ( 10 ) + 20
time . Sleep ( time . Duration ( delay ) * time . Second )
inputMsgTxt = tdlib . NewInputMessageText ( tdlib . NewFormattedText ( "🛡Defend\n" , nil ) , true , true )
msgMutex . Lock ( )
sendMsg , _ = c . SendMessage ( updateMsg . Message . ChatID , 0 , false , false , nil , inputMsgTxt )
msgID64 = sendMsg . ID
msgText = string ( "🛡Defend" )
fmt . Println ( "send msgID64 (defend) : " , msgID64 )
time . Sleep ( 1 * time . Second )
DeleteMsg ( c , ownUserID64 , fwdMsg )
time . Sleep ( 7 * time . Second )
// c.SetOption("online", tdlib.NewOptionValueBoolean(false))
break
}
match , _ = regexp . MatchString ( ".*/pledge.*" , line )
if match {
fmt . Println ( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! PLEDGE INCOMING !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" )
time . Sleep ( 1 * time . Second )
fwdMsg := ForwardMsg ( c , updateMsg . Message . ID , updateMsg . Message . ChatID , ownUserID64 )
delay := rand . Intn ( 20 )
fmt . Println ( "Delaying reply by" , delay , "seconds" )
time . Sleep ( time . Duration ( delay ) * time . Second )
c . SetOption ( "online" , tdlib . NewOptionValueBoolean ( true ) )
time . Sleep ( 5 * time . Second )
inputMsgTxt := tdlib . NewInputMessageText ( tdlib . NewFormattedText ( "/pledge\n" , nil ) , true , true )
msgMutex . Lock ( )
sendMsg , _ := c . SendMessage ( updateMsg . Message . ChatID , 0 , false , false , nil , inputMsgTxt )
msgID64 = sendMsg . ID
msgText = string ( "/pledge" )
fmt . Println ( "send msgID64 (pledge) : " , msgID64 )
time . Sleep ( 1 * time . Second )
DeleteMsg ( c , ownUserID64 , fwdMsg )
time . Sleep ( 7 * time . Second )
// c.SetOption("online", tdlib.NewOptionValueBoolean(false))
break
}
}
}
}
2019-04-15 12:55:00 +02:00
}
func ListenCW ( c * tdlib . Client ) {
2019-05-03 10:00:30 +02:00
var msgDisplay , msgDelete bool
eventFilter := func ( msg * tdlib . TdMessage ) bool {
updateMsg := ( * msg ) . ( * tdlib . UpdateNewMessage )
chatID := updateMsg . Message . ChatID
senderUserID := updateMsg . Message . SenderUserID
if senderUserID == user_chtwrsbot && chatID == user_chtwrsbot {
return true
}
return false
}
2019-04-15 12:55:00 +02:00
2019-05-03 10:00:30 +02:00
receiver := c . AddEventReceiver ( & tdlib . UpdateNewMessage { } , eventFilter , 100 )
for newMsg := range receiver . Chan {
updateMsg := ( newMsg ) . ( * tdlib . UpdateNewMessage )
senderUserID := updateMsg . Message . SenderUserID
mType := updateMsg . Message . Content . GetMessageContentEnum ( )
if mType == "messageText" {
user , err := c . GetUser ( senderUserID )
if err != nil {
fmt . Println ( "ListenCW:" , err . Error ( ) )
continue
}
txt := updateMsg . Message . Content . ( * tdlib . MessageText ) . Text . Text
fmt . Println ( "============== CHAT WARS (" , user . Username , ") ================================================================" )
fmt . Println ( txt , "\n" )
fmt . Println ( "===============================================================================================================" )
fmt . Println ( "recv msgID64 : " , msgID64 )
if msgID64 != int64 ( 0 ) {
switch msgText {
case "/g_stock_res" :
vault . Res = string ( txt )
msgDisplay = false
msgDelete = true
case "/g_stock_alch" :
vault . Alch = string ( txt )
msgDisplay = false
msgDelete = true
case "/g_stock_misc" :
vault . Misc = string ( txt )
msgDisplay = false
msgDelete = true
case "/g_stock_rec" :
vault . Rec = string ( txt )
msgDisplay = false
msgDelete = true
case "/g_stock_parts" :
vault . Parts = string ( txt )
msgDisplay = false
msgDelete = true
case "/g_stock_other" :
vault . Other = string ( txt )
msgDisplay = false
msgDelete = true
case "/g_withdraw" :
time . Sleep ( 1 * time . Second )
_ = ForwardMsg ( c , updateMsg . Message . ID , updateMsg . Message . ChatID , msgUserID64 )
msgDisplay = false
msgDelete = false
default :
fmt . Println ( "No specific task for " , msgText )
msgDisplay = true
msgDelete = false
}
time . Sleep ( 1 * time . Second )
if msgDelete {
DeleteMsg ( c , user_chtwrsbot , msgID64 )
time . Sleep ( 1 * time . Second )
DeleteMsg ( c , user_chtwrsbot , updateMsg . Message . ID )
}
msgID64 = int64 ( 0 )
msgUserID64 = int64 ( 0 )
msgMutex . Unlock ( )
} else {
msgDisplay = true
}
if msgDisplay {
for _ , line := range strings . Split ( strings . TrimSuffix ( txt , "\n" ) , "\n" ) {
// fmt.Println("Testing line:", line)
match , _ := regexp . MatchString ( ".*Your result on the battlefield:.*" , line )
if match {
fmt . Println ( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! REPORT SPOTTED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" )
time . Sleep ( 1 * time . Second )
ForwardMsg ( c , updateMsg . Message . ID , updateMsg . Message . ChatID , int64 ( user_botnestbot ) )
time . Sleep ( 1 * time . Second )
ForwardMsg ( c , updateMsg . Message . ID , updateMsg . Message . ChatID , int64 ( user_chtwrscastlebot ) )
break
}
match , _ = regexp . MatchString ( ".*Leaderboard of fighters are updated: /top5 & /top6. ((Cheer up)|(Congratulations))!.*" , line )
if match {
fmt . Println ( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! FIGHT SPOTTED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" )
time . Sleep ( 1 * time . Second )
ForwardMsg ( c , updateMsg . Message . ID , updateMsg . Message . ChatID , int64 ( user_chtwrscastlebot ) )
break
}
match , _ = regexp . MatchString ( "Deposited [⚡📕📗📘📙📒'a-zA-Z0-9+ ]* \\([0-9]*\\) successfully" , line )
if match {
fmt . Println ( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! DEPOSIT SPOTTED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" )
time . Sleep ( 1 * time . Second )
ForwardMsg ( c , updateMsg . Message . ID , updateMsg . Message . ChatID , int64 ( chat_guild_deposit ) )
break
}
match , _ = regexp . MatchString ( "Received [⚡📕📗📘📙📒'a-zA-Z0-9+ ]* x [0-9]*" , line )
if match {
fmt . Println ( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! RECEPTION SPOTTED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" )
time . Sleep ( 1 * time . Second )
ForwardMsg ( c , updateMsg . Message . ID , updateMsg . Message . ChatID , int64 ( chat_guild_deposit ) )
break
}
}
}
}
}
2019-04-15 12:55:00 +02:00
}
func ListenDarkwing ( c * tdlib . Client ) {
2019-05-03 10:00:30 +02:00
eventFilter := func ( msg * tdlib . TdMessage ) bool {
updateMsg := ( * msg ) . ( * tdlib . UpdateNewMessage )
chatID := updateMsg . Message . ChatID
senderUserID := updateMsg . Message . SenderUserID
if senderUserID == user_botnestbot && chatID == chat_darkwing {
return true
}
return false
}
2019-04-15 12:55:00 +02:00
2019-05-03 10:00:30 +02:00
receiver := c . AddEventReceiver ( & tdlib . UpdateNewMessage { } , eventFilter , 100 )
for newMsg := range receiver . Chan {
updateMsg := ( newMsg ) . ( * tdlib . UpdateNewMessage )
senderUserID := updateMsg . Message . SenderUserID
mType := updateMsg . Message . Content . GetMessageContentEnum ( )
if mType == "messageText" {
user , err := c . GetUser ( senderUserID )
if err != nil {
fmt . Println ( "ListenDarkwing:" , err . Error ( ) )
continue
}
txt := updateMsg . Message . Content . ( * tdlib . MessageText ) . Text . Text
fmt . Println ( "============== DARKWING (" , user . Username , ") =================================================================" )
fmt . Println ( txt , "\n" )
fmt . Println ( "===============================================================================================================" )
for _ , line := range strings . Split ( strings . TrimSuffix ( txt , "\n" ) , "\n" ) {
match , _ := regexp . MatchString ( ".*Your result on the battlefield:.*" , line )
if match {
fmt . Println ( "!!!!!!!!!!!!!!!!! REPORT SPOTTED !!!!!!!!!!!!!!!!!" )
time . Sleep ( 1 * time . Second )
ForwardMsg ( c , updateMsg . Message . ID , updateMsg . Message . ChatID , int64 ( user_botnestbot ) )
time . Sleep ( 1 * time . Second )
ForwardMsg ( c , updateMsg . Message . ID , updateMsg . Message . ChatID , int64 ( user_chtwrscastlebot ) )
break
}
}
}
}
2019-04-15 12:55:00 +02:00
}
func ListenGuild ( c * tdlib . Client ) {
2019-05-03 10:00:30 +02:00
eventFilter := func ( msg * tdlib . TdMessage ) bool {
updateMsg := ( * msg ) . ( * tdlib . UpdateNewMessage )
chatID := updateMsg . Message . ChatID
// senderUserID := updateMsg.Message.SenderUserID
if chatID == chat_guild {
return true
}
return false
}
2019-04-15 12:55:00 +02:00
2019-05-03 10:00:30 +02:00
receiver := c . AddEventReceiver ( & tdlib . UpdateNewMessage { } , eventFilter , 100 )
for newMsg := range receiver . Chan {
updateMsg := ( newMsg ) . ( * tdlib . UpdateNewMessage )
senderUserID := updateMsg . Message . SenderUserID
mType := updateMsg . Message . Content . GetMessageContentEnum ( )
if mType == "messageText" {
user , err := c . GetUser ( senderUserID )
if err != nil {
fmt . Println ( "ListenGuild:" , err . Error ( ) )
continue
}
txt := updateMsg . Message . Content . ( * tdlib . MessageText ) . Text . Text
fmt . Println ( "============== GUILD (" , user . Username , ") =================================================================" )
fmt . Println ( txt , "\n" )
fmt . Println ( "===============================================================================================================" )
for _ , line := range strings . Split ( strings . TrimSuffix ( txt , "\n" ) , "\n" ) {
2019-12-14 07:52:28 +01:00
validID := regexp . MustCompile ( ` ^/g_withdraw ([a-z0-9]+) ([0-9]+)$ ` )
2019-12-20 11:24:31 +01:00
if validID . MatchString ( line ) && senderUserID != 121964035 {
2019-05-03 10:00:30 +02:00
fmt . Println ( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! GUILD WITHDRAWAL SPOTTED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" )
t := regexp . MustCompile ( ` /g_withdraw (?P<Code>[a-z0-9]+) (?P<Quantity>[0-9]+) ` )
if t . FindStringSubmatch ( line ) != nil {
size , _ = strconv . Atoi ( t . ReplaceAllString ( line , "${Quantity}" ) )
fmt . Printf ( "Withdrawing %s / %d\n" , t . ReplaceAllString ( line , "${Code}" ) , size )
m := ChatWarsWithdraw {
Item : t . ReplaceAllString ( line , "${Code}" ) ,
Quantity : int64 ( size ) ,
UserID64 : int64 ( senderUserID ) ,
Time : time . Now ( ) ,
}
b , _ := json . Marshal ( m )
md5Bytes := md5 . Sum ( b )
md5String := TgEncoding . EncodeToString ( md5Bytes [ : ] )
withdrawals [ md5String ] = m
msgText = fmt . Sprintf ( "To validate @%s withdrawal of %d x %s\nClick /withdraw_%s\n" , user . Username , size , items [ t . ReplaceAllString ( line , "${Code}" ) ] . Name , md5String )
inputMsgTxt := tdlib . NewInputMessageText ( tdlib . NewFormattedText ( msgText , nil ) , true , true )
c . SendMessage ( chat_guild , 0 , false , false , nil , inputMsgTxt )
msgText = ""
} else {
fmt . Printf ( "Can't match withdrawing request.\n" )
}
break
}
2019-12-20 11:24:31 +01:00
if validID . MatchString ( line ) && senderUserID == 121964035 {
t := regexp . MustCompile ( ` /g_withdraw (?P<Code>[a-z0-9]+) (?P<Quantity>[0-9]+) ` )
if t . FindStringSubmatch ( line ) != nil {
size , _ = strconv . Atoi ( t . ReplaceAllString ( line , "${Quantity}" ) )
fmt . Printf ( "Withdrawing %s / %d\n" , t . ReplaceAllString ( line , "${Code}" ) , size )
m := ChatWarsWithdraw {
Item : t . ReplaceAllString ( line , "${Code}" ) ,
Quantity : int64 ( size ) ,
UserID64 : int64 ( senderUserID ) ,
Time : time . Now ( ) ,
}
2019-12-20 11:28:09 +01:00
msgText = fmt . Sprintf ( "Your command, master.\n" )
2019-12-20 11:24:31 +01:00
inputMsgTxt := tdlib . NewInputMessageText ( tdlib . NewFormattedText ( msgText , nil ) , true , true )
c . SendMessage ( chat_guild , 0 , false , false , nil , inputMsgTxt )
msgText = fmt . Sprintf ( "/g_withdraw %s %d\n" , m . Item , m . Quantity )
2019-12-20 11:25:54 +01:00
inputMsgTxt = tdlib . NewInputMessageText ( tdlib . NewFormattedText ( msgText , nil ) , true , true )
2019-12-20 11:24:31 +01:00
msgMutex . Lock ( )
sendMsg , _ := c . SendMessage ( user_chtwrsbot , 0 , false , false , nil , inputMsgTxt )
msgID64 = sendMsg . ID
msgText = string ( "/g_withdraw" )
msgUserID64 = m . UserID64
fmt . Println ( "send msgID64 (g_withdraw) : " , msgID64 )
} else {
fmt . Printf ( "Can't match withdrawing request.\n" )
}
break
}
2019-05-03 10:00:30 +02:00
validID = regexp . MustCompile ( ` ^/withdraw_([ABCDEFGHIJKLMNOPQRSTUVWXYZ234567] { 26})$ ` )
if validID . MatchString ( line ) {
fmt . Println ( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! GUILD WITHDRAW CONF SPOTTED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" )
u := regexp . MustCompile ( ` ^/withdraw_(?P<Reference>[ABCDEFGHIJKLMNOPQRSTUVWXYZ234567] { 26})$ ` )
if u . FindStringSubmatch ( line ) != nil {
fmt . Printf ( "Withdrawal %s identified\n" , u . ReplaceAllString ( line , "${Reference}" ) )
ref := u . ReplaceAllString ( line , "${Reference}" )
if _ , ok := withdrawals [ ref ] ; ok {
fmt . Printf ( "Withdrawal %s found\n" , ref )
t := time . Now ( )
if t . Sub ( withdrawals [ ref ] . Time ) > 300 * time . Second {
msgText = fmt . Sprintf ( "Reference %s is expired.\n" , ref )
inputMsgTxt := tdlib . NewInputMessageText ( tdlib . NewFormattedText ( msgText , nil ) , true , true )
c . SendMessage ( chat_guild , 0 , false , false , nil , inputMsgTxt )
msgText = ""
} else {
if withdrawals [ ref ] . UserID64 != ownUserID64 && withdrawals [ ref ] . UserID64 == int64 ( senderUserID ) {
inputMsgTxt := tdlib . NewInputMessageText ( tdlib . NewFormattedText ( "You cannot validate your own withdrawal requests.\n" , nil ) , true , true )
c . SendMessage ( chat_guild , 0 , false , false , nil , inputMsgTxt )
msgText = ""
} else {
msgText = fmt . Sprintf ( "/g_withdraw %s %d\n" , withdrawals [ ref ] . Item , withdrawals [ ref ] . Quantity )
inputMsgTxt := tdlib . NewInputMessageText ( tdlib . NewFormattedText ( msgText , nil ) , true , true )
msgMutex . Lock ( )
sendMsg , _ := c . SendMessage ( user_chtwrsbot , 0 , false , false , nil , inputMsgTxt )
msgID64 = sendMsg . ID
msgText = string ( "/g_withdraw" )
msgUserID64 = withdrawals [ ref ] . UserID64
fmt . Println ( "send msgID64 (g_withdraw) : " , msgID64 )
delete ( withdrawals , ref )
}
}
} else {
msgText = fmt . Sprintf ( "Reference %s is not found.\n" , ref )
inputMsgTxt := tdlib . NewInputMessageText ( tdlib . NewFormattedText ( msgText , nil ) , true , true )
c . SendMessage ( chat_guild , 0 , false , false , nil , inputMsgTxt )
msgText = ""
}
} else {
msgText = fmt . Sprintf ( "Reference is malformed\n" )
inputMsgTxt := tdlib . NewInputMessageText ( tdlib . NewFormattedText ( msgText , nil ) , true , true )
c . SendMessage ( chat_guild , 0 , false , false , nil , inputMsgTxt )
msgText = ""
}
break
}
}
}
}
2019-04-15 12:55:00 +02:00
}
2019-05-03 10:00:30 +02:00
2019-04-15 12:55:00 +02:00
/ *
func ForwardOwnMsg ( c * tdlib . Client ) {
eventFilter := func ( msg * tdlib . TdMessage ) bool {
updateMsg := ( * msg ) . ( * tdlib . UpdateNewMessage )
chatID := updateMsg . Message . ChatID
senderUserID := updateMsg . Message . SenderUserID
if ( senderUserID == ownUserID32 && chatID != ownUserID64 ) {
return true
}
return false
}
2019-05-03 10:00:30 +02:00
2019-04-15 12:55:00 +02:00
receiver := c . AddEventReceiver ( & tdlib . UpdateNewMessage { } , eventFilter , 100 )
for newMsg := range receiver . Chan {
updateMsg := ( newMsg ) . ( * tdlib . UpdateNewMessage )
mType := updateMsg . Message . Content . GetMessageContentEnum ( )
if mType == "messageText" {
fwdMsg := ForwardMsg ( c , updateMsg . Message . ID , updateMsg . Message . ChatID , ownUserID64 )
time . Sleep ( 2 * time . Second )
DeleteMsg ( c , fwdMsg )
}
}
}
* /
2019-11-10 10:56:43 +01:00
func ListenAll ( c * tdlib . Client ) {
2019-05-03 10:00:30 +02:00
eventFilter := func ( msg * tdlib . TdMessage ) bool {
updateMsg := ( * msg ) . ( * tdlib . UpdateNewMessage )
chatID := updateMsg . Message . ChatID
// senderUserID := updateMsg.Message.SenderUserID
if chatID == user_chtwrsbot || chatID == user_botnestbot || chatID == user_chtwrscastlebot || chatID == chat_darkwing || chatID == chat_guild {
return false
}
return true
}
2019-04-15 12:55:00 +02:00
2019-05-03 10:00:30 +02:00
receiver := c . AddEventReceiver ( & tdlib . UpdateNewMessage { } , eventFilter , 100 )
for newMsg := range receiver . Chan {
updateMsg := ( newMsg ) . ( * tdlib . UpdateNewMessage )
senderUserID := updateMsg . Message . SenderUserID
mType := updateMsg . Message . Content . GetMessageContentEnum ( )
if mType == "messageText" {
username := "null"
if senderUserID != 0 {
user , err := c . GetUser ( senderUserID )
if err != nil {
fmt . Println ( "Listen:" , err . Error ( ) )
continue
} else {
username = user . Username
}
}
t := time . Now ( )
txt := updateMsg . Message . Content . ( * tdlib . MessageText ) . Text . Text
fmt . Printf ( "[%d-%02d-%02d %02d:%02d:%02d-00:00]" , t . Year ( ) , t . Month ( ) , t . Day ( ) , t . Hour ( ) , t . Minute ( ) , t . Second ( ) )
fmt . Println ( " === SENT (" , username , ") =====================================================================" )
fmt . Println ( txt , "\n" )
fmt . Println ( "************ DETAILS ************" )
fmt . Println ( "ID : " , updateMsg . Message . ID )
fmt . Println ( "SenderUserID : " , updateMsg . Message . SenderUserID )
fmt . Println ( "ChatID : " , updateMsg . Message . ChatID )
fmt . Println ( "SendingState : " , updateMsg . Message . SendingState )
fmt . Println ( "IsOutgoing : " , updateMsg . Message . IsOutgoing )
fmt . Println ( "CanBeEdited : " , updateMsg . Message . CanBeEdited )
fmt . Println ( "CanBeForwarded : " , updateMsg . Message . CanBeForwarded )
fmt . Println ( "IsChannelPost : " , updateMsg . Message . IsChannelPost )
fmt . Println ( "ContainsUnreadMention : " , updateMsg . Message . ContainsUnreadMention )
fmt . Println ( "ForwardInfo : " , updateMsg . Message . ForwardInfo )
fmt . Println ( "ReplyToMessageID : " , updateMsg . Message . ReplyToMessageID )
fmt . Println ( "ViaBotUserID : " , updateMsg . Message . ViaBotUserID )
fmt . Println ( "================================================================================================================" )
}
}
2019-04-15 12:55:00 +02:00
}
2019-05-03 10:00:30 +02:00
func ForwardMsg ( c * tdlib . Client , msgID int64 , fromChatID int64 , toChatID int64 ) int64 {
2019-04-15 12:55:00 +02:00
msgIDs := make ( [ ] int64 , 1 )
msgIDs [ 0 ] = msgID
msgs , _ := c . ForwardMessages ( toChatID , fromChatID , msgIDs , false , false , false )
if msgs != nil {
2019-05-03 10:00:30 +02:00
return msgs . Messages [ 0 ] . ID
2019-04-15 12:55:00 +02:00
} else {
2019-05-03 10:00:30 +02:00
return 0
2019-04-15 12:55:00 +02:00
}
}
func DeleteMsg ( c * tdlib . Client , chatID int64 , msgID int64 ) {
msgIDs := make ( [ ] int64 , 1 )
msgIDs [ 0 ] = msgID
c . DeleteMessages ( chatID , msgIDs , false )
fmt . Println ( "Deleting message " , msgID )
}
2019-05-03 10:00:30 +02:00
func OwnUserID ( c * tdlib . Client ) int32 {
2019-04-15 12:55:00 +02:00
user , _ := c . GetMe ( )
2019-05-03 10:00:30 +02:00
return user . ID
2019-04-15 12:55:00 +02:00
}