upd
This commit is contained in:
parent
488eada53b
commit
b55fbeac64
207
main.go
207
main.go
@ -1,39 +1,23 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/md5"
|
||||||
|
"encoding/base32"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"crypto/md5"
|
|
||||||
"encoding/base32"
|
|
||||||
"encoding/json"
|
|
||||||
"math/rand"
|
|
||||||
|
|
||||||
"github.com/Arman92/go-tdlib"
|
"github.com/Arman92/go-tdlib"
|
||||||
"github.com/streadway/amqp"
|
// "github.com/go-web/tokenizer"
|
||||||
// "github.com/go-web/tokenizer"
|
// "database/sql"
|
||||||
|
// _ "github.com/go-sql-driver/mysql"
|
||||||
// "database/sql"
|
|
||||||
// _ "github.com/go-sql-driver/mysql"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type MsgDirection int
|
|
||||||
|
|
||||||
const (
|
|
||||||
Incoming MsgDirection = 1
|
|
||||||
Outgoing MsgDirection = 2
|
|
||||||
)
|
|
||||||
|
|
||||||
type ChatWarsMessage struct {
|
|
||||||
UserID64 int64 `json:"user_id"`
|
|
||||||
Direction MsgDirection `json:"direction"`
|
|
||||||
MsgText string `json:"msg"`
|
|
||||||
MsgID64 int64 `json:"msg_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ChatWarsWithdraw struct {
|
type ChatWarsWithdraw struct {
|
||||||
Item string `json:"item"`
|
Item string `json:"item"`
|
||||||
Quantity int64 `json:"quantity"`
|
Quantity int64 `json:"quantity"`
|
||||||
@ -65,15 +49,13 @@ var hmacKey []byte
|
|||||||
var withdrawals = map[string]ChatWarsWithdraw{}
|
var withdrawals = map[string]ChatWarsWithdraw{}
|
||||||
var TgEncoding *base32.Encoding
|
var TgEncoding *base32.Encoding
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// msgMutex = &sync.Mutex{}
|
// msgMutex = &sync.Mutex{}
|
||||||
tdlib.SetLogVerbosityLevel(1)
|
tdlib.SetLogVerbosityLevel(1)
|
||||||
tdlib.SetFilePath("./errors.txt")
|
tdlib.SetFilePath("./errors.txt")
|
||||||
|
|
||||||
TgEncoding = base32.StdEncoding.WithPadding(base32.NoPadding)
|
TgEncoding = base32.StdEncoding.WithPadding(base32.NoPadding)
|
||||||
|
|
||||||
|
|
||||||
// Create new instance of client
|
// Create new instance of client
|
||||||
client := tdlib.NewClient(tdlib.Config{
|
client := tdlib.NewClient(tdlib.Config{
|
||||||
APIID: "187786",
|
APIID: "187786",
|
||||||
@ -131,7 +113,7 @@ func main() {
|
|||||||
go ListenCW(client)
|
go ListenCW(client)
|
||||||
go Listen(client)
|
go Listen(client)
|
||||||
go ListenGuild(client)
|
go ListenGuild(client)
|
||||||
// go ForwardOwnMsg(client)
|
// go ForwardOwnMsg(client)
|
||||||
|
|
||||||
fmt.Println("Started !")
|
fmt.Println("Started !")
|
||||||
|
|
||||||
@ -146,11 +128,11 @@ func PillageKnight(c *tdlib.Client) {
|
|||||||
updateMsg := (*msg).(*tdlib.UpdateNewMessage)
|
updateMsg := (*msg).(*tdlib.UpdateNewMessage)
|
||||||
chatID := updateMsg.Message.ChatID
|
chatID := updateMsg.Message.ChatID
|
||||||
senderUserID := updateMsg.Message.SenderUserID
|
senderUserID := updateMsg.Message.SenderUserID
|
||||||
// viaBotUserID := updateMsg.Message.ViaBotUserID
|
// viaBotUserID := updateMsg.Message.ViaBotUserID
|
||||||
// fmt.Println("UpdateNewMessage : chatID : ", chatID)
|
// fmt.Println("UpdateNewMessage : chatID : ", chatID)
|
||||||
// fmt.Println("UpdateNewMessage : senderUserID : ", senderUserID)
|
// fmt.Println("UpdateNewMessage : senderUserID : ", senderUserID)
|
||||||
// fmt.Println("UpdateNewMessage : viaBotUserID : ", viaBotUserID)
|
// fmt.Println("UpdateNewMessage : viaBotUserID : ", viaBotUserID)
|
||||||
if (senderUserID == user_chtwrsbot && chatID == user_chtwrsbot) {
|
if senderUserID == user_chtwrsbot && chatID == user_chtwrsbot {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@ -159,16 +141,16 @@ func PillageKnight(c *tdlib.Client) {
|
|||||||
receiver := c.AddEventReceiver(&tdlib.UpdateNewMessage{}, eventFilter, 100)
|
receiver := c.AddEventReceiver(&tdlib.UpdateNewMessage{}, eventFilter, 100)
|
||||||
for newMsg := range receiver.Chan {
|
for newMsg := range receiver.Chan {
|
||||||
updateMsg := (newMsg).(*tdlib.UpdateNewMessage)
|
updateMsg := (newMsg).(*tdlib.UpdateNewMessage)
|
||||||
// senderUserID := updateMsg.Message.SenderUserID
|
// senderUserID := updateMsg.Message.SenderUserID
|
||||||
mType := updateMsg.Message.Content.GetMessageContentEnum()
|
mType := updateMsg.Message.Content.GetMessageContentEnum()
|
||||||
if mType == "messageText" {
|
if mType == "messageText" {
|
||||||
/*
|
/*
|
||||||
user, err := c.GetUser(senderUserID)
|
user, err := c.GetUser(senderUserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Pillage:", err.Error())
|
fmt.Println("Pillage:", err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
txt := updateMsg.Message.Content.(*tdlib.MessageText).Text.Text
|
txt := updateMsg.Message.Content.(*tdlib.MessageText).Text.Text
|
||||||
|
|
||||||
for _, line := range strings.Split(strings.TrimSuffix(txt, "\n"), "\n") {
|
for _, line := range strings.Split(strings.TrimSuffix(txt, "\n"), "\n") {
|
||||||
@ -178,7 +160,7 @@ func PillageKnight(c *tdlib.Client) {
|
|||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
fwdMsg := ForwardMsg(c, updateMsg.Message.ID, updateMsg.Message.ChatID, ownUserID64)
|
fwdMsg := ForwardMsg(c, updateMsg.Message.ID, updateMsg.Message.ChatID, ownUserID64)
|
||||||
delay := rand.Intn(20)
|
delay := rand.Intn(20)
|
||||||
fmt.Println("Delaying reply by", delay + 5, "seconds")
|
fmt.Println("Delaying reply by", delay+5, "seconds")
|
||||||
time.Sleep(time.Duration(delay) * time.Second)
|
time.Sleep(time.Duration(delay) * time.Second)
|
||||||
c.SetOption("online", tdlib.NewOptionValueBoolean(true))
|
c.SetOption("online", tdlib.NewOptionValueBoolean(true))
|
||||||
time.Sleep(5 * time.Second)
|
time.Sleep(5 * time.Second)
|
||||||
@ -203,7 +185,7 @@ func PillageKnight(c *tdlib.Client) {
|
|||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
DeleteMsg(c, ownUserID64, fwdMsg)
|
DeleteMsg(c, ownUserID64, fwdMsg)
|
||||||
time.Sleep(7 * time.Second)
|
time.Sleep(7 * time.Second)
|
||||||
// c.SetOption("online", tdlib.NewOptionValueBoolean(false))
|
// c.SetOption("online", tdlib.NewOptionValueBoolean(false))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
match, _ = regexp.MatchString(".*/pledge.*", line)
|
match, _ = regexp.MatchString(".*/pledge.*", line)
|
||||||
@ -227,7 +209,7 @@ func PillageKnight(c *tdlib.Client) {
|
|||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
DeleteMsg(c, ownUserID64, fwdMsg)
|
DeleteMsg(c, ownUserID64, fwdMsg)
|
||||||
time.Sleep(7 * time.Second)
|
time.Sleep(7 * time.Second)
|
||||||
// c.SetOption("online", tdlib.NewOptionValueBoolean(false))
|
// c.SetOption("online", tdlib.NewOptionValueBoolean(false))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -241,27 +223,12 @@ func ListenCW(c *tdlib.Client) {
|
|||||||
updateMsg := (*msg).(*tdlib.UpdateNewMessage)
|
updateMsg := (*msg).(*tdlib.UpdateNewMessage)
|
||||||
chatID := updateMsg.Message.ChatID
|
chatID := updateMsg.Message.ChatID
|
||||||
senderUserID := updateMsg.Message.SenderUserID
|
senderUserID := updateMsg.Message.SenderUserID
|
||||||
if (senderUserID == user_chtwrsbot && chatID == user_chtwrsbot) {
|
if senderUserID == user_chtwrsbot && chatID == user_chtwrsbot {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, _ := amqp.Dial("amqp://shoopea:UmDd5g4WRa2MzqOHsG2T@localhost:5672/chatwars")
|
|
||||||
defer conn.Close()
|
|
||||||
|
|
||||||
ch, _ := conn.Channel()
|
|
||||||
defer ch.Close()
|
|
||||||
|
|
||||||
q, _ := ch.QueueDeclare(
|
|
||||||
"msg", // name
|
|
||||||
false, // durable
|
|
||||||
false, // delete when unused
|
|
||||||
false, // exclusive
|
|
||||||
false, // no-wait
|
|
||||||
nil, // arguments
|
|
||||||
)
|
|
||||||
|
|
||||||
receiver := c.AddEventReceiver(&tdlib.UpdateNewMessage{}, eventFilter, 100)
|
receiver := c.AddEventReceiver(&tdlib.UpdateNewMessage{}, eventFilter, 100)
|
||||||
for newMsg := range receiver.Chan {
|
for newMsg := range receiver.Chan {
|
||||||
updateMsg := (newMsg).(*tdlib.UpdateNewMessage)
|
updateMsg := (newMsg).(*tdlib.UpdateNewMessage)
|
||||||
@ -278,36 +245,42 @@ func ListenCW(c *tdlib.Client) {
|
|||||||
fmt.Println(txt, "\n")
|
fmt.Println(txt, "\n")
|
||||||
fmt.Println("===============================================================================================================")
|
fmt.Println("===============================================================================================================")
|
||||||
|
|
||||||
m := ChatWarsMessage{
|
|
||||||
UserID64 : ownUserID64,
|
|
||||||
MsgText : string(txt),
|
|
||||||
Direction : Incoming,
|
|
||||||
MsgID64 : updateMsg.Message.ID,
|
|
||||||
}
|
|
||||||
|
|
||||||
b, err := json.Marshal(m)
|
|
||||||
|
|
||||||
_ = ch.Publish(
|
|
||||||
"", // exchange
|
|
||||||
q.Name, // routing key
|
|
||||||
false, // mandatory
|
|
||||||
false, // immediate
|
|
||||||
amqp.Publishing{
|
|
||||||
ContentType: "application/json",
|
|
||||||
Body: []byte(b),
|
|
||||||
})
|
|
||||||
|
|
||||||
fmt.Println("recv msgID64 : ", msgID64)
|
fmt.Println("recv msgID64 : ", msgID64)
|
||||||
if msgID64 != int64(0) {
|
if msgID64 != int64(0) {
|
||||||
switch msgText {
|
switch msgText {
|
||||||
case "/g_stock_res": vault.Res = string(txt) ; msgDisplay = false; msgDelete = true
|
case "/g_stock_res":
|
||||||
case "/g_stock_alch": vault.Alch = string(txt) ; msgDisplay = false; msgDelete = true
|
vault.Res = string(txt)
|
||||||
case "/g_stock_misc": vault.Misc = string(txt) ; msgDisplay = false; msgDelete = true
|
msgDisplay = false
|
||||||
case "/g_stock_rec": vault.Rec = string(txt) ; msgDisplay = false; msgDelete = true
|
msgDelete = true
|
||||||
case "/g_stock_parts": vault.Parts = string(txt) ; msgDisplay = false; msgDelete = true
|
case "/g_stock_alch":
|
||||||
case "/g_stock_other": vault.Other = string(txt) ; msgDisplay = false; msgDelete = true
|
vault.Alch = string(txt)
|
||||||
case "/g_withdraw": time.Sleep(1 * time.Second) ; _ = ForwardMsg(c, updateMsg.Message.ID, updateMsg.Message.ChatID, msgUserID64) ; msgDisplay = false; msgDelete = false
|
msgDisplay = false
|
||||||
default: fmt.Println("No specific task for ", msgText) ; msgDisplay = true; msgDelete = 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)
|
time.Sleep(1 * time.Second)
|
||||||
if msgDelete {
|
if msgDelete {
|
||||||
@ -324,7 +297,7 @@ func ListenCW(c *tdlib.Client) {
|
|||||||
|
|
||||||
if msgDisplay {
|
if msgDisplay {
|
||||||
for _, line := range strings.Split(strings.TrimSuffix(txt, "\n"), "\n") {
|
for _, line := range strings.Split(strings.TrimSuffix(txt, "\n"), "\n") {
|
||||||
// fmt.Println("Testing line:", line)
|
// fmt.Println("Testing line:", line)
|
||||||
match, _ := regexp.MatchString(".*Your result on the battlefield:.*", line)
|
match, _ := regexp.MatchString(".*Your result on the battlefield:.*", line)
|
||||||
if match {
|
if match {
|
||||||
fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! REPORT SPOTTED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
fmt.Println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! REPORT SPOTTED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
||||||
@ -366,7 +339,7 @@ func ListenDarkwing(c *tdlib.Client) {
|
|||||||
updateMsg := (*msg).(*tdlib.UpdateNewMessage)
|
updateMsg := (*msg).(*tdlib.UpdateNewMessage)
|
||||||
chatID := updateMsg.Message.ChatID
|
chatID := updateMsg.Message.ChatID
|
||||||
senderUserID := updateMsg.Message.SenderUserID
|
senderUserID := updateMsg.Message.SenderUserID
|
||||||
if (senderUserID == user_botnestbot && chatID == chat_darkwing) {
|
if senderUserID == user_botnestbot && chatID == chat_darkwing {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@ -407,8 +380,8 @@ func ListenGuild(c *tdlib.Client) {
|
|||||||
eventFilter := func(msg *tdlib.TdMessage) bool {
|
eventFilter := func(msg *tdlib.TdMessage) bool {
|
||||||
updateMsg := (*msg).(*tdlib.UpdateNewMessage)
|
updateMsg := (*msg).(*tdlib.UpdateNewMessage)
|
||||||
chatID := updateMsg.Message.ChatID
|
chatID := updateMsg.Message.ChatID
|
||||||
// senderUserID := updateMsg.Message.SenderUserID
|
// senderUserID := updateMsg.Message.SenderUserID
|
||||||
if (chatID == chat_guild) {
|
if chatID == chat_guild {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@ -487,15 +460,15 @@ func ListenGuild(c *tdlib.Client) {
|
|||||||
vault.ResSize = 0
|
vault.ResSize = 0
|
||||||
vault.ResCount = 0
|
vault.ResCount = 0
|
||||||
for _, item := range strings.Split(strings.TrimSuffix(vault.Res, "\n"), "\n") {
|
for _, item := range strings.Split(strings.TrimSuffix(vault.Res, "\n"), "\n") {
|
||||||
// fmt.Printf("%s : %#v\n", item, r.FindStringSubmatch(item))
|
// fmt.Printf("%s : %#v\n", item, r.FindStringSubmatch(item))
|
||||||
// fmt.Printf("%s : %#v\n", item, r.SubexpNames())
|
// fmt.Printf("%s : %#v\n", item, r.SubexpNames())
|
||||||
if r.FindStringSubmatch(item) != nil {
|
if r.FindStringSubmatch(item) != nil {
|
||||||
if _, ok := items[r.ReplaceAllString(item, "${Code}")]; ok {
|
if _, ok := items[r.ReplaceAllString(item, "${Code}")]; ok {
|
||||||
if items[r.ReplaceAllString(item, "${Code}")].Weight == -1 {
|
if items[r.ReplaceAllString(item, "${Code}")].Weight == -1 {
|
||||||
fmt.Printf("=====================> Unknown size for item : %s (%s)\n", r.ReplaceAllString(item, "${Code}"), r.ReplaceAllString(item, "${Name}"))
|
fmt.Printf("=====================> Unknown size for item : %s (%s)\n", r.ReplaceAllString(item, "${Code}"), r.ReplaceAllString(item, "${Name}"))
|
||||||
} else {
|
} else {
|
||||||
size, _ = strconv.Atoi(r.ReplaceAllString(item, "${Quantity}"))
|
size, _ = strconv.Atoi(r.ReplaceAllString(item, "${Quantity}"))
|
||||||
vault.ResSize = vault.ResSize + items[r.ReplaceAllString(item, "${Code}")].Weight * int32(size)
|
vault.ResSize = vault.ResSize + items[r.ReplaceAllString(item, "${Code}")].Weight*int32(size)
|
||||||
vault.ResCount = vault.ResCount + int32(size)
|
vault.ResCount = vault.ResCount + int32(size)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -513,15 +486,15 @@ func ListenGuild(c *tdlib.Client) {
|
|||||||
vault.AlchSize = 0
|
vault.AlchSize = 0
|
||||||
vault.AlchCount = 0
|
vault.AlchCount = 0
|
||||||
for _, item := range strings.Split(strings.TrimSuffix(vault.Alch, "\n"), "\n") {
|
for _, item := range strings.Split(strings.TrimSuffix(vault.Alch, "\n"), "\n") {
|
||||||
// fmt.Printf("%s : %#v\n", item, r.FindStringSubmatch(item))
|
// fmt.Printf("%s : %#v\n", item, r.FindStringSubmatch(item))
|
||||||
// fmt.Printf("%s : %#v\n", item, r.SubexpNames())
|
// fmt.Printf("%s : %#v\n", item, r.SubexpNames())
|
||||||
if r.FindStringSubmatch(item) != nil {
|
if r.FindStringSubmatch(item) != nil {
|
||||||
if _, ok := items[r.ReplaceAllString(item, "${Code}")]; ok {
|
if _, ok := items[r.ReplaceAllString(item, "${Code}")]; ok {
|
||||||
if items[r.ReplaceAllString(item, "${Code}")].Weight == -1 {
|
if items[r.ReplaceAllString(item, "${Code}")].Weight == -1 {
|
||||||
fmt.Printf("=====================> Unknown size for item : %s (%s)\n", r.ReplaceAllString(item, "${Code}"), r.ReplaceAllString(item, "${Name}"))
|
fmt.Printf("=====================> Unknown size for item : %s (%s)\n", r.ReplaceAllString(item, "${Code}"), r.ReplaceAllString(item, "${Name}"))
|
||||||
} else {
|
} else {
|
||||||
size, _ = strconv.Atoi(r.ReplaceAllString(item, "${Quantity}"))
|
size, _ = strconv.Atoi(r.ReplaceAllString(item, "${Quantity}"))
|
||||||
vault.AlchSize = vault.AlchSize + items[r.ReplaceAllString(item, "${Code}")].Weight * int32(size)
|
vault.AlchSize = vault.AlchSize + items[r.ReplaceAllString(item, "${Code}")].Weight*int32(size)
|
||||||
vault.AlchCount = vault.AlchCount + int32(size)
|
vault.AlchCount = vault.AlchCount + int32(size)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -539,15 +512,15 @@ func ListenGuild(c *tdlib.Client) {
|
|||||||
vault.MiscSize = 0
|
vault.MiscSize = 0
|
||||||
vault.MiscCount = 0
|
vault.MiscCount = 0
|
||||||
for _, item := range strings.Split(strings.TrimSuffix(vault.Misc, "\n"), "\n") {
|
for _, item := range strings.Split(strings.TrimSuffix(vault.Misc, "\n"), "\n") {
|
||||||
// fmt.Printf("%s : %#v\n", item, r.FindStringSubmatch(item))
|
// fmt.Printf("%s : %#v\n", item, r.FindStringSubmatch(item))
|
||||||
// fmt.Printf("%s : %#v\n", item, r.SubexpNames())
|
// fmt.Printf("%s : %#v\n", item, r.SubexpNames())
|
||||||
if r.FindStringSubmatch(item) != nil {
|
if r.FindStringSubmatch(item) != nil {
|
||||||
if _, ok := items[r.ReplaceAllString(item, "${Code}")]; ok {
|
if _, ok := items[r.ReplaceAllString(item, "${Code}")]; ok {
|
||||||
if items[r.ReplaceAllString(item, "${Code}")].Weight == -1 {
|
if items[r.ReplaceAllString(item, "${Code}")].Weight == -1 {
|
||||||
fmt.Printf("=====================> Unknown size for item : %s (%s)\n", r.ReplaceAllString(item, "${Code}"), r.ReplaceAllString(item, "${Name}"))
|
fmt.Printf("=====================> Unknown size for item : %s (%s)\n", r.ReplaceAllString(item, "${Code}"), r.ReplaceAllString(item, "${Name}"))
|
||||||
} else {
|
} else {
|
||||||
size, _ = strconv.Atoi(r.ReplaceAllString(item, "${Quantity}"))
|
size, _ = strconv.Atoi(r.ReplaceAllString(item, "${Quantity}"))
|
||||||
vault.MiscSize = vault.MiscSize + items[r.ReplaceAllString(item, "${Code}")].Weight * int32(size)
|
vault.MiscSize = vault.MiscSize + items[r.ReplaceAllString(item, "${Code}")].Weight*int32(size)
|
||||||
vault.MiscCount = vault.MiscCount + int32(size)
|
vault.MiscCount = vault.MiscCount + int32(size)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -565,15 +538,15 @@ func ListenGuild(c *tdlib.Client) {
|
|||||||
vault.RecSize = 0
|
vault.RecSize = 0
|
||||||
vault.RecCount = 0
|
vault.RecCount = 0
|
||||||
for _, item := range strings.Split(strings.TrimSuffix(vault.Rec, "\n"), "\n") {
|
for _, item := range strings.Split(strings.TrimSuffix(vault.Rec, "\n"), "\n") {
|
||||||
// fmt.Printf("%s : %#v\n", item, r.FindStringSubmatch(item))
|
// fmt.Printf("%s : %#v\n", item, r.FindStringSubmatch(item))
|
||||||
// fmt.Printf("%s : %#v\n", item, r.SubexpNames())
|
// fmt.Printf("%s : %#v\n", item, r.SubexpNames())
|
||||||
if r.FindStringSubmatch(item) != nil {
|
if r.FindStringSubmatch(item) != nil {
|
||||||
if _, ok := items[r.ReplaceAllString(item, "${Code}")]; ok {
|
if _, ok := items[r.ReplaceAllString(item, "${Code}")]; ok {
|
||||||
if items[r.ReplaceAllString(item, "${Code}")].Weight == -1 {
|
if items[r.ReplaceAllString(item, "${Code}")].Weight == -1 {
|
||||||
fmt.Printf("=====================> Unknown size for item : %s (%s)\n", r.ReplaceAllString(item, "${Code}"), r.ReplaceAllString(item, "${Name}"))
|
fmt.Printf("=====================> Unknown size for item : %s (%s)\n", r.ReplaceAllString(item, "${Code}"), r.ReplaceAllString(item, "${Name}"))
|
||||||
} else {
|
} else {
|
||||||
size, _ = strconv.Atoi(r.ReplaceAllString(item, "${Quantity}"))
|
size, _ = strconv.Atoi(r.ReplaceAllString(item, "${Quantity}"))
|
||||||
vault.RecSize = vault.RecSize + items[r.ReplaceAllString(item, "${Code}")].Weight * int32(size)
|
vault.RecSize = vault.RecSize + items[r.ReplaceAllString(item, "${Code}")].Weight*int32(size)
|
||||||
vault.RecCount = vault.RecCount + int32(size)
|
vault.RecCount = vault.RecCount + int32(size)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -591,15 +564,15 @@ func ListenGuild(c *tdlib.Client) {
|
|||||||
vault.PartsSize = 0
|
vault.PartsSize = 0
|
||||||
vault.PartsCount = 0
|
vault.PartsCount = 0
|
||||||
for _, item := range strings.Split(strings.TrimSuffix(vault.Parts, "\n"), "\n") {
|
for _, item := range strings.Split(strings.TrimSuffix(vault.Parts, "\n"), "\n") {
|
||||||
// fmt.Printf("%s : %#v\n", item, r.FindStringSubmatch(item))
|
// fmt.Printf("%s : %#v\n", item, r.FindStringSubmatch(item))
|
||||||
// fmt.Printf("%s : %#v\n", item, r.SubexpNames())
|
// fmt.Printf("%s : %#v\n", item, r.SubexpNames())
|
||||||
if r.FindStringSubmatch(item) != nil {
|
if r.FindStringSubmatch(item) != nil {
|
||||||
if _, ok := items[r.ReplaceAllString(item, "${Code}")]; ok {
|
if _, ok := items[r.ReplaceAllString(item, "${Code}")]; ok {
|
||||||
if items[r.ReplaceAllString(item, "${Code}")].Weight == -1 {
|
if items[r.ReplaceAllString(item, "${Code}")].Weight == -1 {
|
||||||
fmt.Printf("=====================> Unknown size for item : %s (%s)\n", r.ReplaceAllString(item, "${Code}"), r.ReplaceAllString(item, "${Name}"))
|
fmt.Printf("=====================> Unknown size for item : %s (%s)\n", r.ReplaceAllString(item, "${Code}"), r.ReplaceAllString(item, "${Name}"))
|
||||||
} else {
|
} else {
|
||||||
size, _ = strconv.Atoi(r.ReplaceAllString(item, "${Quantity}"))
|
size, _ = strconv.Atoi(r.ReplaceAllString(item, "${Quantity}"))
|
||||||
vault.PartsSize = vault.PartsSize + items[r.ReplaceAllString(item, "${Code}")].Weight * int32(size)
|
vault.PartsSize = vault.PartsSize + items[r.ReplaceAllString(item, "${Code}")].Weight*int32(size)
|
||||||
vault.PartsCount = vault.PartsCount + int32(size)
|
vault.PartsCount = vault.PartsCount + int32(size)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -617,15 +590,15 @@ func ListenGuild(c *tdlib.Client) {
|
|||||||
vault.OtherSize = 0
|
vault.OtherSize = 0
|
||||||
vault.OtherCount = 0
|
vault.OtherCount = 0
|
||||||
for _, item := range strings.Split(strings.TrimSuffix(vault.Other, "\n"), "\n") {
|
for _, item := range strings.Split(strings.TrimSuffix(vault.Other, "\n"), "\n") {
|
||||||
// fmt.Printf("%s : %#v\n", item, r.FindStringSubmatch(item))
|
// fmt.Printf("%s : %#v\n", item, r.FindStringSubmatch(item))
|
||||||
// fmt.Printf("%s : %#v\n", item, r.SubexpNames())
|
// fmt.Printf("%s : %#v\n", item, r.SubexpNames())
|
||||||
if r.FindStringSubmatch(item) != nil {
|
if r.FindStringSubmatch(item) != nil {
|
||||||
if _, ok := items[r.ReplaceAllString(item, "${Code}")]; ok {
|
if _, ok := items[r.ReplaceAllString(item, "${Code}")]; ok {
|
||||||
if items[r.ReplaceAllString(item, "${Code}")].Weight == -1 {
|
if items[r.ReplaceAllString(item, "${Code}")].Weight == -1 {
|
||||||
fmt.Printf("=====================> Unknown size for item : %s (%s)\n", r.ReplaceAllString(item, "${Code}"), r.ReplaceAllString(item, "${Name}"))
|
fmt.Printf("=====================> Unknown size for item : %s (%s)\n", r.ReplaceAllString(item, "${Code}"), r.ReplaceAllString(item, "${Name}"))
|
||||||
} else {
|
} else {
|
||||||
size, _ = strconv.Atoi(r.ReplaceAllString(item, "${Quantity}"))
|
size, _ = strconv.Atoi(r.ReplaceAllString(item, "${Quantity}"))
|
||||||
vault.OtherSize = vault.OtherSize + items[r.ReplaceAllString(item, "${Code}")].Weight * int32(size)
|
vault.OtherSize = vault.OtherSize + items[r.ReplaceAllString(item, "${Code}")].Weight*int32(size)
|
||||||
vault.OtherCount = vault.OtherCount + int32(size)
|
vault.OtherCount = vault.OtherCount + int32(size)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -635,7 +608,7 @@ func ListenGuild(c *tdlib.Client) {
|
|||||||
for k, v := range items {
|
for k, v := range items {
|
||||||
if strings.Compare(v.Name, s.ReplaceAllString(itemName, "${BaseName}")) == 0 {
|
if strings.Compare(v.Name, s.ReplaceAllString(itemName, "${BaseName}")) == 0 {
|
||||||
size, _ = strconv.Atoi(r.ReplaceAllString(item, "${Quantity}"))
|
size, _ = strconv.Atoi(r.ReplaceAllString(item, "${Quantity}"))
|
||||||
vault.OtherSize = vault.OtherSize + items[k].Weight * int32(size)
|
vault.OtherSize = vault.OtherSize + items[k].Weight*int32(size)
|
||||||
vault.OtherCount = vault.OtherCount + int32(size)
|
vault.OtherCount = vault.OtherCount + int32(size)
|
||||||
fmt.Printf("=====================> Found in map : %s (%d)\n", items[k].Name, size)
|
fmt.Printf("=====================> Found in map : %s (%d)\n", items[k].Name, size)
|
||||||
}
|
}
|
||||||
@ -650,7 +623,7 @@ func ListenGuild(c *tdlib.Client) {
|
|||||||
}
|
}
|
||||||
fmt.Printf("=====================> Size for vault.Other : %d\n", vault.OtherSize)
|
fmt.Printf("=====================> Size for vault.Other : %d\n", vault.OtherSize)
|
||||||
|
|
||||||
msgText = fmt.Sprintf("Current stock [%d/38000] :\n - Resources : %d (%d)\n - Alchemist : %d (%d)\n - Misc stuff : %d (%d)\n - Recipes : %d (%d)\n - Parts : %d (%d)\n - Other : %d (%d)\n", vault.ResSize + vault.AlchSize + vault.MiscSize + vault.RecSize + vault.PartsSize + vault.OtherSize, vault.ResSize, vault.ResCount, vault.AlchSize, vault.AlchCount, vault.MiscSize, vault.MiscCount, vault.RecSize, vault.RecCount, vault.PartsSize, vault.PartsCount, vault.OtherSize, vault.OtherCount)
|
msgText = fmt.Sprintf("Current stock [%d/38000] :\n - Resources : %d (%d)\n - Alchemist : %d (%d)\n - Misc stuff : %d (%d)\n - Recipes : %d (%d)\n - Parts : %d (%d)\n - Other : %d (%d)\n", vault.ResSize+vault.AlchSize+vault.MiscSize+vault.RecSize+vault.PartsSize+vault.OtherSize, vault.ResSize, vault.ResCount, vault.AlchSize, vault.AlchCount, vault.MiscSize, vault.MiscCount, vault.RecSize, vault.RecCount, vault.PartsSize, vault.PartsCount, vault.OtherSize, vault.OtherCount)
|
||||||
inputMsgTxt = tdlib.NewInputMessageText(tdlib.NewFormattedText(msgText, nil), true, true)
|
inputMsgTxt = tdlib.NewInputMessageText(tdlib.NewFormattedText(msgText, nil), true, true)
|
||||||
sendMsg, _ = c.SendMessage(chat_guild, 0, false, false, nil, inputMsgTxt)
|
sendMsg, _ = c.SendMessage(chat_guild, 0, false, false, nil, inputMsgTxt)
|
||||||
msgText = ""
|
msgText = ""
|
||||||
@ -667,10 +640,10 @@ func ListenGuild(c *tdlib.Client) {
|
|||||||
size, _ = strconv.Atoi(t.ReplaceAllString(line, "${Quantity}"))
|
size, _ = strconv.Atoi(t.ReplaceAllString(line, "${Quantity}"))
|
||||||
fmt.Printf("Withdrawing %s / %d\n", t.ReplaceAllString(line, "${Code}"), size)
|
fmt.Printf("Withdrawing %s / %d\n", t.ReplaceAllString(line, "${Code}"), size)
|
||||||
m := ChatWarsWithdraw{
|
m := ChatWarsWithdraw{
|
||||||
Item : t.ReplaceAllString(line, "${Code}"),
|
Item: t.ReplaceAllString(line, "${Code}"),
|
||||||
Quantity : int64(size),
|
Quantity: int64(size),
|
||||||
UserID64 : int64(senderUserID),
|
UserID64: int64(senderUserID),
|
||||||
Time : time.Now(),
|
Time: time.Now(),
|
||||||
}
|
}
|
||||||
|
|
||||||
b, _ := json.Marshal(m)
|
b, _ := json.Marshal(m)
|
||||||
@ -679,7 +652,7 @@ func ListenGuild(c *tdlib.Client) {
|
|||||||
|
|
||||||
md5String := TgEncoding.EncodeToString(md5Bytes[:])
|
md5String := TgEncoding.EncodeToString(md5Bytes[:])
|
||||||
|
|
||||||
withdrawals[md5String] = m;
|
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)
|
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)
|
inputMsgTxt := tdlib.NewInputMessageText(tdlib.NewFormattedText(msgText, nil), true, true)
|
||||||
@ -703,7 +676,7 @@ func ListenGuild(c *tdlib.Client) {
|
|||||||
if _, ok := withdrawals[ref]; ok {
|
if _, ok := withdrawals[ref]; ok {
|
||||||
fmt.Printf("Withdrawal %s found\n", ref)
|
fmt.Printf("Withdrawal %s found\n", ref)
|
||||||
t := time.Now()
|
t := time.Now()
|
||||||
if t.Sub(withdrawals[ref].Time) > 300 * time.Second {
|
if t.Sub(withdrawals[ref].Time) > 300*time.Second {
|
||||||
msgText = fmt.Sprintf("Reference %s is expired.\n", ref)
|
msgText = fmt.Sprintf("Reference %s is expired.\n", ref)
|
||||||
inputMsgTxt := tdlib.NewInputMessageText(tdlib.NewFormattedText(msgText, nil), true, true)
|
inputMsgTxt := tdlib.NewInputMessageText(tdlib.NewFormattedText(msgText, nil), true, true)
|
||||||
c.SendMessage(chat_guild, 0, false, false, nil, inputMsgTxt)
|
c.SendMessage(chat_guild, 0, false, false, nil, inputMsgTxt)
|
||||||
@ -744,6 +717,7 @@ func ListenGuild(c *tdlib.Client) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
func ForwardOwnMsg(c *tdlib.Client) {
|
func ForwardOwnMsg(c *tdlib.Client) {
|
||||||
eventFilter := func(msg *tdlib.TdMessage) bool {
|
eventFilter := func(msg *tdlib.TdMessage) bool {
|
||||||
@ -772,8 +746,8 @@ func Listen(c *tdlib.Client) {
|
|||||||
eventFilter := func(msg *tdlib.TdMessage) bool {
|
eventFilter := func(msg *tdlib.TdMessage) bool {
|
||||||
updateMsg := (*msg).(*tdlib.UpdateNewMessage)
|
updateMsg := (*msg).(*tdlib.UpdateNewMessage)
|
||||||
chatID := updateMsg.Message.ChatID
|
chatID := updateMsg.Message.ChatID
|
||||||
// senderUserID := updateMsg.Message.SenderUserID
|
// senderUserID := updateMsg.Message.SenderUserID
|
||||||
if (chatID == user_chtwrsbot || chatID == user_botnestbot || chatID == user_chtwrscastlebot || chatID == chat_darkwing || chatID == chat_guild) {
|
if chatID == user_chtwrsbot || chatID == user_botnestbot || chatID == user_chtwrscastlebot || chatID == chat_darkwing || chatID == chat_guild {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@ -818,7 +792,7 @@ func Listen(c *tdlib.Client) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ForwardMsg(c *tdlib.Client, msgID int64, fromChatID int64, toChatID int64) (int64) {
|
func ForwardMsg(c *tdlib.Client, msgID int64, fromChatID int64, toChatID int64) int64 {
|
||||||
msgIDs := make([]int64, 1)
|
msgIDs := make([]int64, 1)
|
||||||
msgIDs[0] = msgID
|
msgIDs[0] = msgID
|
||||||
msgs, _ := c.ForwardMessages(toChatID, fromChatID, msgIDs, false, false, false)
|
msgs, _ := c.ForwardMessages(toChatID, fromChatID, msgIDs, false, false, false)
|
||||||
@ -836,8 +810,7 @@ func DeleteMsg(c *tdlib.Client, chatID int64, msgID int64) {
|
|||||||
fmt.Println("Deleting message ", msgID)
|
fmt.Println("Deleting message ", msgID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func OwnUserID(c *tdlib.Client) (int32) {
|
func OwnUserID(c *tdlib.Client) int32 {
|
||||||
user, _ := c.GetMe()
|
user, _ := c.GetMe()
|
||||||
return user.ID;
|
return user.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user