test
This commit is contained in:
parent
f919abfd3f
commit
bfac2a94a2
19
bot.go
19
bot.go
@ -83,13 +83,7 @@ func botTest(m *tb.Message) {
|
||||
return
|
||||
}
|
||||
if _, ok := clientsKeepAlive[m.Chat.ID]; ok {
|
||||
c := TGCommand{
|
||||
Type: commandSendMsg,
|
||||
Text: "🏅Me",
|
||||
FromUserID64: m.Chat.ID,
|
||||
ToChatID64: userID64ChtWrsBot,
|
||||
}
|
||||
MQTGCmdQueue <- c
|
||||
clientSendCWMsg(m.Chat.ID, "🏅Me")
|
||||
|
||||
c = TGCommand{
|
||||
Type: commandReplyMsg,
|
||||
@ -282,15 +276,12 @@ func botTimer(m *tb.Message) {
|
||||
}
|
||||
TGCmdQueue <- c
|
||||
} else {
|
||||
c := TGCommand{
|
||||
Type: commandSendMsg,
|
||||
Text: r.ReplaceAllString(m.Payload, "${Msg}"),
|
||||
FromUserID64: m.Chat.ID,
|
||||
ToChatID64: userID64ChtWrsBot,
|
||||
p := JobPayloadMsgClient{
|
||||
Msg: r.ReplaceAllString(m.Payload, "${Msg}"),
|
||||
}
|
||||
b, _ := json.Marshal(c)
|
||||
b, _ := json.Marshal(p)
|
||||
t := time.Now().Add(d)
|
||||
objID64, err := createJob(objSubTypeJobMsgClient, objJobPriority, int64(m.Sender.ID), t, b)
|
||||
objID64, err := createJob(objSubTypeJobMsgClient, objJobPriority, int64(m.Chat.ID), t, b)
|
||||
logOnError(err, "botTimer : createJob")
|
||||
if err != nil {
|
||||
c := TGCommand{
|
||||
|
42
client.go
Normal file
42
client.go
Normal file
@ -0,0 +1,42 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func clientSendCWMsg(userID64 int64, s string) {
|
||||
c := TGCommand{
|
||||
Type: commandSendMsg,
|
||||
Text: s,
|
||||
FromUserID64: userID64,
|
||||
ToChatID64: userID64ChtWrsBot,
|
||||
}
|
||||
MQTGCmdQueue <- c
|
||||
}
|
||||
|
||||
func clientMsgMe(userID64 int64, guildID64 int64, state string, timestamp time.Time) {
|
||||
if _, ok := clientsQueue[userID64]; ok {
|
||||
if c, ok := clientsCW[userID64]; ok {
|
||||
if c.LastUpdate.Before(timestamp) {
|
||||
c.GuildID64 = guildID64
|
||||
c.State = state
|
||||
c.LastUpdate = timestamp
|
||||
if strings.Compare(cacheObjGuild[guildID64].Name, ``) != 0 && strings.Compare(c.Role, ``) == 0 {
|
||||
clientSendCWMsg(userID64, "/g_roles")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
c := ChatWarsClient{
|
||||
GuildID64: guildID64,
|
||||
State: state,
|
||||
LastUpdate: timestamp,
|
||||
}
|
||||
clientsCW[userID64] = &c
|
||||
if strings.Compare(cacheObjGuild[guildID64].Name, ``) != 0 {
|
||||
clientSendCWMsg(userID64, "/g_roles")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
7
def.go
7
def.go
@ -27,6 +27,7 @@ type ChatWarsClient struct {
|
||||
Role string `json:"role"`
|
||||
State string `json:"state"`
|
||||
BusyUntil time.Time `json:"busy_until"`
|
||||
LastUpdate time.Time `json:"last_update"`
|
||||
}
|
||||
|
||||
type TGCommand struct {
|
||||
@ -135,6 +136,8 @@ type MessageParsingRule struct {
|
||||
Description string
|
||||
Rule string
|
||||
MsgTypeID int32
|
||||
ChatID64 int64
|
||||
SenderUserID64 int64
|
||||
re *regexp.Regexp
|
||||
}
|
||||
|
||||
@ -180,6 +183,10 @@ type JobPayloadSetDone struct {
|
||||
Text string `json:"test"`
|
||||
}
|
||||
|
||||
type JobPayloadMsgClient struct {
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
const (
|
||||
userID64ChtWrsBot = 408101137
|
||||
|
||||
|
23
job.go
23
job.go
@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
@ -263,7 +262,6 @@ func jobPillage(j Job) {
|
||||
ToUserID64: j.UserID64,
|
||||
}
|
||||
TGCmdQueue <- s
|
||||
log.Printf("More than one outcome for pillage #%d\n", r.ObjID64)
|
||||
} else if len(ids) == 1 { // we've got a match, job is done whether we prevented the pillage or not
|
||||
m, err := getMsg(ids[0])
|
||||
logOnError(err, "jobPillage : getMsg(objSubTypeMessagePillageGo, objSubTypeMessagePillageTimeout)")
|
||||
@ -279,7 +277,6 @@ func jobPillage(j Job) {
|
||||
ToUserID64: j.UserID64,
|
||||
}
|
||||
TGCmdQueue <- s
|
||||
log.Printf("jobPillage : objSubTypeMessagePillageGo\n", r.ObjID64)
|
||||
} else if msgTypeID64 == objSubTypeMessagePillageWin {
|
||||
s := TGCommand{
|
||||
Type: commandSendMsg,
|
||||
@ -287,7 +284,6 @@ func jobPillage(j Job) {
|
||||
ToUserID64: j.UserID64,
|
||||
}
|
||||
TGCmdQueue <- s
|
||||
log.Printf("jobPillage : objSubTypeMessagePillageWin\n", r.ObjID64)
|
||||
} else if msgTypeID64 == objSubTypeMessagePillageLoss {
|
||||
s := TGCommand{
|
||||
Type: commandSendMsg,
|
||||
@ -295,7 +291,6 @@ func jobPillage(j Job) {
|
||||
ToUserID64: j.UserID64,
|
||||
}
|
||||
TGCmdQueue <- s
|
||||
log.Printf("jobPillage : objSubTypeMessagePillageLoss\n", r.ObjID64)
|
||||
} else if msgTypeID64 == objSubTypeMessagePillageTimeout {
|
||||
s := TGCommand{
|
||||
Type: commandSendMsg,
|
||||
@ -303,7 +298,6 @@ func jobPillage(j Job) {
|
||||
ToUserID64: j.UserID64,
|
||||
}
|
||||
TGCmdQueue <- s
|
||||
log.Printf("jobPillage : objSubTypeMessagePillageTimeout\n", r.ObjID64)
|
||||
} else {
|
||||
s := TGCommand{
|
||||
Type: commandSendMsg,
|
||||
@ -311,7 +305,6 @@ func jobPillage(j Job) {
|
||||
ToUserID64: j.UserID64,
|
||||
}
|
||||
TGCmdQueue <- s
|
||||
log.Printf("jobPillage : We don't know what happened\n", r.ObjID64)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -347,13 +340,7 @@ func jobPillage(j Job) {
|
||||
err = rescheduleJob(j.ID64, j.Status+1, time.Now().Add(30*time.Second))
|
||||
logOnError(err, "jobPillage : rescheduleJob(objSubTypeMessageGo)")
|
||||
} else { //no /go in the last 30 sec so we go ahead, send one and reschedule to check again in 25sec
|
||||
c := TGCommand{
|
||||
Type: commandSendMsg,
|
||||
Text: "/go",
|
||||
FromUserID64: j.UserID64,
|
||||
ToChatID64: userID64ChtWrsBot,
|
||||
}
|
||||
MQTGCmdQueue <- c
|
||||
clientSendCWMsg(j.UserID64, "/go")
|
||||
err = rescheduleJob(j.ID64, j.Status+1, time.Now().Add(30*time.Second))
|
||||
logOnError(err, "jobPillage : rescheduleJob")
|
||||
|
||||
@ -363,14 +350,16 @@ func jobPillage(j Job) {
|
||||
}
|
||||
|
||||
func jobMsgClient(j Job) {
|
||||
var c TGCommand
|
||||
var p JobPayloadMsgClient
|
||||
err := setJobStart(j.ID64)
|
||||
logOnError(err, "jobMsgClient : setJobStart")
|
||||
|
||||
err = json.Unmarshal(j.Payload, &c)
|
||||
err = json.Unmarshal(j.Payload, &p)
|
||||
logOnError(err, "jobMsgClient : Unmarshal payload")
|
||||
|
||||
MQTGCmdQueue <- c
|
||||
if err != nil {
|
||||
clientSendCWMsg(j.UserID64, p.Msg)
|
||||
}
|
||||
|
||||
err = setJobDone(j.ID64)
|
||||
logOnError(err, "joMsgClient : setJobDone")
|
||||
|
Loading…
Reference in New Issue
Block a user