This commit is contained in:
shoopea 2019-05-03 12:08:15 +08:00
parent fc52fc66f5
commit d984dc4f7f

18
main.go
View File

@ -1,10 +1,10 @@
package main package main
import ( import (
"encoding/json"
"fmt" "fmt"
"log" "log"
"time" "time"
"encoding/json"
"github.com/Arman92/go-tdlib" "github.com/Arman92/go-tdlib"
"github.com/streadway/amqp" "github.com/streadway/amqp"
@ -18,10 +18,10 @@ const (
) )
type ChatWarsMessage struct { type ChatWarsMessage struct {
MsgID64 int64 `json:"msg_id"`
UserID64 int64 `json:"user_id"` UserID64 int64 `json:"user_id"`
Direction MsgDirection `json:"direction"` Direction MsgDirection `json:"direction"`
MsgText string `json:"msg"` MsgText string `json:"msg"`
MsgID64 int64 `json:"msg_id"`
} }
const user_chtwrsbot = 408101137 const user_chtwrsbot = 408101137
@ -29,7 +29,6 @@ const user_chtwrsbot = 408101137
var ownUserID64 = int64(0) var ownUserID64 = int64(0)
var ownUserID32 = int32(0) var ownUserID32 = int32(0)
func main() { func main() {
// msgMutex = &sync.Mutex{} // msgMutex = &sync.Mutex{}
tdlib.SetLogVerbosityLevel(1) tdlib.SetLogVerbosityLevel(1)
@ -102,13 +101,13 @@ func ListenCW(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
if (chatID == user_chtwrsbot) { if chatID == user_chtwrsbot {
return true return true
} }
return false return false
} }
conn, err := amqp.Dial("amqp://shoopea:UmDd5g4WRa2MzqOHsG2T@localhost:5672/chatwars_shoopea") conn, err := amqp.Dial("amqp://shoopea:UmDd5g4WRa2MzqOHsG2T@localhost:5672/chatwars")
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -170,8 +169,6 @@ func ListenCW(c *tdlib.Client) {
Body: []byte(b), Body: []byte(b),
}) })
fmt.Printf("[%d-%02d-%02d %02d:%02d:%02d-00:00]", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second()) fmt.Printf("[%d-%02d-%02d %02d:%02d:%02d-00:00]", t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
fmt.Println(" === CHATWARS (", user.Username, ") =====================================================================") fmt.Println(" === CHATWARS (", user.Username, ") =====================================================================")
fmt.Println(txt, "\n") fmt.Println(txt, "\n")
@ -194,7 +191,7 @@ func ListenCW(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)
@ -212,8 +209,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
} }