test
This commit is contained in:
parent
da1d3ca910
commit
bade7a4f78
29
bot.go
29
bot.go
@ -21,6 +21,7 @@ func BotHandlers(b *tb.Bot) {
|
||||
b.Handle("/test", botTest)
|
||||
b.Handle("/msg_rescan", botMsgRescan)
|
||||
b.Handle("/msg_rescan_all", botMsgRescanAll)
|
||||
b.Handle("/msg_dump", botMsgDump)
|
||||
|
||||
b.Handle(tb.OnPhoto, botPhoto)
|
||||
b.Handle(tb.OnChannelPost, botChannelPost)
|
||||
@ -168,3 +169,31 @@ func botMsgRescanAll(m *tb.Message) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func botMsgDump(m *tb.Message) {
|
||||
var res string
|
||||
r := regexp.MustCompile("^[0-9]+$")
|
||||
if r.MatchString(m.Payload) {
|
||||
objId, _ := strconv.ParseInt(m.Payload, 10, 64)
|
||||
objSubTypeId, err := getObjSubTypeId(objId)
|
||||
if err != nil {
|
||||
res = `This is not a message reference`
|
||||
} else {
|
||||
cwm, err := getMsg(objId)
|
||||
b, _ := json.Marshal(cwm)
|
||||
res = string(b)
|
||||
}
|
||||
} else {
|
||||
res = `/msg_dump <msg_id>`
|
||||
}
|
||||
|
||||
c := TGCommand{
|
||||
Type: commandReplyMsg,
|
||||
Text: res,
|
||||
FromMsgID64: int64(m.ID),
|
||||
FromChatID64: m.Chat.ID,
|
||||
}
|
||||
TGCmdQueue <- c
|
||||
|
||||
return
|
||||
}
|
||||
|
5
def.go
5
def.go
@ -40,6 +40,10 @@ type ChatWarsMessage struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
type ChatWarsMessageReport struct {
|
||||
ObjID64 int64 `json:"obj_id"`
|
||||
}
|
||||
|
||||
type ChatWarsMessageAuctionAnnounce struct {
|
||||
ObjID64 int64 `json:"obj_id"`
|
||||
LotID int32 `json:"lot_id"`
|
||||
@ -97,6 +101,7 @@ type Job struct {
|
||||
}
|
||||
|
||||
type JobPayloadPillage struct {
|
||||
Date time.Time `json:"date"`
|
||||
}
|
||||
|
||||
type JobPayloadTribute struct {
|
||||
|
19
msg.go
19
msg.go
@ -7,6 +7,25 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func parseSubTypeMessageReport(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageReport, error) {
|
||||
cwm := ChatWarsMessageReport{}
|
||||
log.Printf("SQLIdentifyMsgWorker[" + strconv.Itoa(id) + "] : War report identified\n")
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Castle : %s\n", r.ReplaceAllString(m.Text, "${Castle}"))
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Guild : %s\n", r.ReplaceAllString(m.Text, "${Guild}"))
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : User : %s\n", r.ReplaceAllString(m.Text, "${User}"))
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Attack : %s\n", r.ReplaceAllString(m.Text, "${Attack}"))
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : AttackMod : %s\n", r.ReplaceAllString(m.Text, "${AttackMod}"))
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Defense : %s\n", r.ReplaceAllString(m.Text, "${Defense}"))
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Level : %s\n", r.ReplaceAllString(m.Text, "${Level}"))
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Exp : %s\n", r.ReplaceAllString(m.Text, "${Exp}"))
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Gold : %s\n", r.ReplaceAllString(m.Text, "${Gold}"))
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Stock : %s\n", r.ReplaceAllString(m.Text, "${Stock}"))
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Stamina : %s\n", r.ReplaceAllString(m.Text, "${Stamina}"))
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Crit : %s\n", r.ReplaceAllString(m.Text, "${Crit}"))
|
||||
|
||||
return &cwm, err
|
||||
}
|
||||
|
||||
func parseSubTypeMessageMiniWar(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageMiniWar, error) {
|
||||
t, err := time.Parse("02/01/06 15:04", r.ReplaceAllString(m.Text, "${Time}"))
|
||||
logOnError(err, "parseSubTypeMessageMiniWar : parsing time : "+r.ReplaceAllString(m.Text, "${Time}"))
|
||||
|
29
workers.go
29
workers.go
@ -89,27 +89,15 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||
r := msgParsingRules[i].re
|
||||
switch msgParsingRules[i].MsgTypeID {
|
||||
case objSubTypeMessageReport:
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : War report identified (%d)\n", objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Castle : %s (%d)\n", r.ReplaceAllString(m.Text, "${Castle}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Guild : %s (%d)\n", r.ReplaceAllString(m.Text, "${Guild}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : User : %s (%d)\n", r.ReplaceAllString(m.Text, "${User}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Attack : %s (%d)\n", r.ReplaceAllString(m.Text, "${Attack}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : AttackMod : %s (%d)\n", r.ReplaceAllString(m.Text, "${AttackMod}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Defense : %s (%d)\n", r.ReplaceAllString(m.Text, "${Defense}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Level : %s (%d)\n", r.ReplaceAllString(m.Text, "${Level}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Exp : %s (%d)\n", r.ReplaceAllString(m.Text, "${Exp}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Gold : %s (%d)\n", r.ReplaceAllString(m.Text, "${Gold}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Stock : %s (%d)\n", r.ReplaceAllString(m.Text, "${Stock}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Stamina : %s (%d)\n", r.ReplaceAllString(m.Text, "${Stamina}"), objId)
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Crit : %s (%d)\n", r.ReplaceAllString(m.Text, "${Crit}"), objId)
|
||||
cwm, err := parseSubTypeMessageReport(m, r)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageReport.")
|
||||
cwm.ObjID64 = objId
|
||||
case objSubTypeMessageMiniWar:
|
||||
|
||||
cwm, err := parseSubTypeMessageMiniWar(m, r)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMiniWar.")
|
||||
cwm.ObjID64 = objId
|
||||
err = insertMsgMiniWar(cwm)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgMiniWar")
|
||||
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageMiniWar)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(MiniWar)")
|
||||
case objSubTypeMessagePillageInc:
|
||||
@ -120,7 +108,10 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgMiniWar")
|
||||
err = setObjSubTypeId(objId, objSubTypeMessagePillageInc)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(PillageInc)")
|
||||
p := JobPayloadPillage{}
|
||||
if m.Date.Add(3 * time.Minute).After(time.Now()) {
|
||||
p := JobPayloadPillage{
|
||||
Date: m.Date,
|
||||
}
|
||||
b, _ := json.Marshal(&p)
|
||||
err = createJob(objSubTypeJobPillage, objJobPriority, m.UserID64, time.Now().Add(time.Duration(25+rand.Intn(35))*time.Second), b)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : createJob(JobPillage)")
|
||||
@ -130,7 +121,11 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||
ToUserID64: m.UserID64,
|
||||
}
|
||||
TGCmdQueue <- s
|
||||
}
|
||||
case objSubTypeMessageGo:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageGo)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(Go)")
|
||||
|
||||
case objSubTypeMessageAuctionAnnounce:
|
||||
cwm := ChatWarsMessageAuctionAnnounce{
|
||||
ObjID64: objId,
|
||||
@ -178,6 +173,8 @@ func SQLJobWorker(id int) {
|
||||
jobRescan(j)
|
||||
case objSubTypeJobSetJobDone:
|
||||
jobSetDone(j)
|
||||
case objSubTypeJobPillage:
|
||||
jobPillage(j)
|
||||
default:
|
||||
log.Printf("SQLJobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user