chirpnest/client.go

76 lines
1.8 KiB
Go
Raw Normal View History

2019-05-30 06:12:01 +02:00
package main
import (
"strings"
)
func clientSendCWMsg(userID64 int64, s string) {
c := TGCommand{
Type: commandSendMsg,
Text: s,
FromUserID64: userID64,
ToChatID64: userID64ChtWrsBot,
}
MQTGCmdQueue <- c
}
2019-06-11 05:37:06 +02:00
func clientRefreshCWMsg(userID64 int64, chatID64 int64, msgID64 int64) {
2019-06-11 04:19:27 +02:00
c := TGCommand{
Type: commandRefreshMsg,
2019-06-11 05:37:06 +02:00
FromUserID64: userID64,
2019-06-11 04:19:27 +02:00
FromChatID64: chatID64,
FromMsgID64: msgID64,
}
MQTGCmdQueue <- c
}
2019-05-30 07:55:53 +02:00
func clientMsgMeAck(m *ChatWarsMessageMeAck) {
2019-05-30 08:08:39 +02:00
if _, ok := clientsQueue[m.Msg.UserID64]; ok {
2019-06-03 10:45:39 +02:00
if v, ok := clientsCW.Load(m.Msg.UserID64); ok {
2019-06-03 10:43:22 +02:00
c := v.(*ChatWarsClient)
2019-05-30 12:57:41 +02:00
if c.LastUpdate.Before(m.Msg.Date) {
2019-05-30 07:49:11 +02:00
c.GuildID64 = m.GuildID64
c.State = m.State
2019-05-30 08:08:39 +02:00
c.LastUpdate = m.Msg.Date
2019-05-31 05:15:19 +02:00
if getObjGuildID(``) != m.GuildID64 && strings.Compare(c.Role, ``) == 0 {
2019-05-30 08:08:39 +02:00
clientSendCWMsg(m.Msg.UserID64, "/g_roles")
2019-05-30 06:12:01 +02:00
}
}
} else {
c := ChatWarsClient{
2019-05-30 12:57:00 +02:00
UserID64: m.UserID64,
TelegramID64: m.Msg.UserID64,
GuildID64: m.GuildID64,
State: m.State,
LastUpdate: m.Msg.Date,
2019-05-30 06:12:01 +02:00
}
2019-06-03 10:46:27 +02:00
clientsCW.Store(m.Msg.UserID64, &c)
2019-05-31 05:15:19 +02:00
if getObjGuildID(``) != m.GuildID64 {
2019-05-30 08:08:39 +02:00
clientSendCWMsg(m.Msg.UserID64, "/g_roles")
2019-05-30 06:12:01 +02:00
}
}
}
}
2019-05-30 12:57:00 +02:00
func clientMsgGRolesAck(m *ChatWarsMessageGRolesAck) {
if _, ok := clientsQueue[m.Msg.UserID64]; ok {
2019-06-03 10:43:22 +02:00
if v, ok := clientsCW.Load(m.Msg.UserID64); ok {
c := v.(*ChatWarsClient)
2019-05-30 12:57:00 +02:00
if c.LastUpdate.Before(m.Msg.Date) {
if m.CommanderID64 == c.UserID64 {
c.Role = `commander`
} else if m.BartenderID64 == c.UserID64 {
c.Role = `bartender`
} else if m.SquireID64 == c.UserID64 {
c.Role = `squire`
} else if m.TreasurerID64 == c.UserID64 {
c.Role = `treasurer`
} else {
2019-05-30 12:58:01 +02:00
c.Role = `none`
2019-05-30 12:57:00 +02:00
}
c.LastUpdate = m.Msg.Date
}
}
}
}