This commit is contained in:
shoopea 2019-05-27 18:03:18 +08:00
parent 5cfe70af6f
commit f45a790ef7
3 changed files with 26 additions and 1 deletions

8
def.go
View File

@ -21,6 +21,14 @@ type MQClient struct {
Queue amqp.Queue
}
type ChatWarsClient struct {
UserID64 int64 `json:"user_id"`
GuildID64 int64 `json:"guild_id"`
Role string `json:"role"`
State string `json:"state"`
BusyUntil time.Time `json:"busy_until"`
}
type TGCommand struct {
Type int64 `json:"type"`
FromChatID64 int64 `json:"from_chat_id"`

View File

@ -52,6 +52,7 @@ var (
msgParsingRules map[int]MessageParsingRule
clientsKeepAlive map[int64]*MQKeepAlive
clientsQueue map[int64]*MQClient
clientsCW map[int64]*ChatWarsClient
)
func PrintText(m *tb.Message) {
@ -125,6 +126,7 @@ func main() {
MQTGCmdQueue = make(chan TGCommand, MQTGCmdQueueSize)
clientsQueue = make(map[int64]*MQClient)
clientsKeepAlive = make(map[int64]*MQKeepAlive)
clientsProfile = make(map[int64]*ChatWarsClient)
for w := 1; w <= MQGetMsgWorkers; w++ {
go MQGetMsgWorker(w, MQCWMsgQueue)

View File

@ -385,7 +385,7 @@ func MQKeepAliveWorker() {
logOnError(err, "MQKeepAliveWorker : Can't unmarshal.\n"+string(d.Body))
if err == nil {
if x.Date.Add(time.Minute).Before(time.Now()) {
// outdate keep-alive
// outdated keep-alive
} else if _, ok := clientsKeepAlive[x.UserID64]; ok {
clientsKeepAlive[x.UserID64].Date = x.Date
} else {
@ -419,6 +419,21 @@ func MQKeepAliveWorker() {
}
TGCmdQueue <- c
c = TGCommand{
Type: commandSendMsg,
FromUserID64: x.UserID64,
ToChatID64: userID64ChtWrsBot,
Text: `🏅Me`,
}
MQTGCmdQueue <- c
c = TGCommand{
Type: commandSendMsg,
FromUserID64: x.UserID64,
ToChatID64: userID64ChtWrsBot,
Text: `/hero`,
}
MQTGCmdQueue <- c
}
}
}