test
This commit is contained in:
parent
887226ccf9
commit
835afa709f
11
def.go
11
def.go
@ -66,6 +66,11 @@ type ChatWarsItem struct {
|
||||
Weight int `json:"weight"`
|
||||
}
|
||||
|
||||
type ChatWarsItems struct {
|
||||
ItemID64 int64 `json:"item_id"`
|
||||
Quantity int64 `json:"quantity"`
|
||||
}
|
||||
|
||||
type ChatWarsMessage struct {
|
||||
ObjID64 int64 `json:"obj_id"`
|
||||
UserID64 int64 `json:"user_id"`
|
||||
@ -76,6 +81,12 @@ type ChatWarsMessage struct {
|
||||
Text string `json:"text"`
|
||||
}
|
||||
|
||||
type ChatWarsMessageStock struct {
|
||||
Msg *ChatWarsMessage `json:"msg"`
|
||||
OwnerID64 int64 `json:"owner_id"`
|
||||
ItemList []ChatWarsItems `json:"item_list"`
|
||||
}
|
||||
|
||||
type ChatWarsMessageReportAck struct {
|
||||
ObjID64 int64 `json:"obj_id"`
|
||||
}
|
||||
|
2
main.go
2
main.go
@ -105,6 +105,8 @@ func main() {
|
||||
logOnError(err, "Caching guilds")
|
||||
err = loadObjUser()
|
||||
logOnError(err, "Caching user")
|
||||
err = loadObjItem()
|
||||
logOnError(err, "Caching user")
|
||||
|
||||
// Registering bot
|
||||
b, err := tb.NewBot(tb.Settings{
|
||||
|
10
msg.go
10
msg.go
@ -30,6 +30,16 @@ func parseSubTypeMessageReportAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWa
|
||||
return &cwm, nil
|
||||
}
|
||||
|
||||
func parseSubTypeMessageGStockAnyAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageStock, error) {
|
||||
cwm := ChatWarsMessageStock{}
|
||||
log.Printf("parseSubTypeMessageReport : GStock Any Ack identified\n")
|
||||
re := regex.MustCompile(`(\\n[0-9a-z]+ .* x [0-9]+)`)
|
||||
for s := range re.FindAllString(r.ReplaceAllString(m.Text, "${Stock}"), -1) {
|
||||
log.Printf("parseSubTypeMessageGStockAnyAck : %s\n", s)
|
||||
}
|
||||
return &cwm, nil
|
||||
}
|
||||
|
||||
func parseSubTypeMessageMeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageMeAck, error) {
|
||||
var i int64
|
||||
|
||||
|
133
workers.go
133
workers.go
@ -90,11 +90,43 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||
err = setObjSubTypeId(objId, msgParsingRules[i].MsgTypeID)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId")
|
||||
switch msgParsingRules[i].MsgTypeID {
|
||||
case objSubTypeMessageGRolesReq:
|
||||
case objSubTypeMessageGo:
|
||||
case objSubTypeMessageReportReq:
|
||||
case objSubTypeMessageGReportReq:
|
||||
case objSubTypeMessageHeroReq:
|
||||
case objSubTypeMessageMeReq:
|
||||
case objSubTypeMessageInventoryReq:
|
||||
case objSubTypeMessageTimeReq:
|
||||
case objSubTypeMessagePledge:
|
||||
case objSubTypeMessagePillageGo:
|
||||
case objSubTypeMessagePillageTimeout:
|
||||
case objSubTypeMessagePillageWin:
|
||||
case objSubTypeMessagePillageLoss:
|
||||
case objSubTypeMessageGoQuest:
|
||||
case objSubTypeMessageGoFastFight:
|
||||
case objSubTypeMessageGoArena:
|
||||
case objSubTypeMessageTop:
|
||||
case objSubTypeMessageMenu:
|
||||
case objSubTypeMessageBuyReq:
|
||||
case objSubTypeMessageSellReq:
|
||||
case objSubTypeMessageOrderbookReq:
|
||||
case objSubTypeMessageOrderbookAck:
|
||||
case objSubTypeMessageWithdrawReq:
|
||||
case objSubTypeMessageWithdrawCode:
|
||||
case objSubTypeMessageWithdrawRcv:
|
||||
case objSubTypeMessageDepositReq:
|
||||
case objSubTypeMessageDepositAck:
|
||||
case objSubTypeMessageStockReq:
|
||||
case objSubTypeMessageMiscReq:
|
||||
case objSubTypeMessageGStockAnyAck:
|
||||
cwm, err := parseSubTypeMessageGStockAnyAck(m, r)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageGStockAnyAck.")
|
||||
cwm.ObjID64 = objId
|
||||
case objSubTypeMessageReportAck:
|
||||
cwm, err := parseSubTypeMessageReportAck(m, r)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageReportAck.")
|
||||
cwm.ObjID64 = objId
|
||||
|
||||
case objSubTypeMessageMiniWar:
|
||||
cwm, err := parseSubTypeMessageMiniWar(m, r)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMiniWar.")
|
||||
@ -122,19 +154,6 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||
_, err = createJob(objSubTypeJobPillage, objJobPriority, m.UserID64, m.Date.Add(time.Duration(25+rand.Intn(35))*time.Second), b)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : createJob(JobPillage)")
|
||||
}
|
||||
case objSubTypeMessageGo:
|
||||
case objSubTypeMessageReportReq:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageReportReq)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(ReportReq)")
|
||||
case objSubTypeMessageGReportReq:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageGReportReq)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(GReportReq)")
|
||||
case objSubTypeMessageHeroReq:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageHeroReq)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(HeroReq)")
|
||||
case objSubTypeMessageMeReq:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageMeReq)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(MeReq)")
|
||||
case objSubTypeMessageMeAck:
|
||||
cwm, err := parseSubTypeMessageMeAck(m, r)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMeAck.")
|
||||
@ -142,105 +161,23 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||
clientMsgMeAck(cwm)
|
||||
_, err = addObjXP(cwm.UserID64, cwm.ExpNow, cwm.ExpLvl, cwm.Level, m.Date)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : addObjXP(MeAck)")
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageMeAck)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(MeAck)")
|
||||
case objSubTypeMessageGoQuestAck:
|
||||
cwm, err := parseSubTypeMessageGoQuestAck(m, r)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMeAck.")
|
||||
cwm.ObjID64 = objId
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageGoQuestAck)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(GoQuestAck)")
|
||||
case objSubTypeMessageInventoryReq:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageInventoryReq)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(InventoryReq)")
|
||||
case objSubTypeMessageTimeReq:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageTimeReq)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(TimeReq)")
|
||||
case objSubTypeMessagePledge:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessagePledge)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(Pledge)")
|
||||
case objSubTypeMessagePillageGo:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessagePillageGo)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(PillageGo)")
|
||||
case objSubTypeMessagePillageTimeout:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessagePillageTimeout)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(PillageTimeout)")
|
||||
case objSubTypeMessagePillageWin:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessagePillageWin)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(PillageWin)")
|
||||
case objSubTypeMessagePillageLoss:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessagePillageLoss)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(PillageLoss)")
|
||||
case objSubTypeMessageDuelFight:
|
||||
cwm, err := parseSubTypeMessageDuelFight(m, r)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageDuelFight.")
|
||||
cwm.ObjID64 = objId
|
||||
err = insertMsgDuelFight(cwm)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgAuctionAnnounce")
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageDuelFight)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(DuelFight)")
|
||||
case objSubTypeMessageGoQuest:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageGoQuest)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(GoQuest)")
|
||||
case objSubTypeMessageGoFastFight:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageGoFastFight)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(GoFastFight)")
|
||||
case objSubTypeMessageGoArena:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageGoArena)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(GoArena)")
|
||||
case objSubTypeMessageTop:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageTop)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(Top)")
|
||||
case objSubTypeMessageMenu:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageMenu)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(Menu)")
|
||||
case objSubTypeMessageBuyReq:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageBuyReq)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(BuyReq)")
|
||||
case objSubTypeMessageSellReq:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageSellReq)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(SellReq)")
|
||||
case objSubTypeMessageOrderbookReq:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageOrderbookReq)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(OrderbookReq)")
|
||||
case objSubTypeMessageOrderbookAck:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageSellReq)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(SellReq)")
|
||||
case objSubTypeMessageWithdrawReq:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageWithdrawReq)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(WithdrawReq)")
|
||||
case objSubTypeMessageWithdrawCode:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageWithdrawCode)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(WithdrawCode)")
|
||||
case objSubTypeMessageWithdrawRcv:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageWithdrawRcv)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(WithdrawRcv)")
|
||||
case objSubTypeMessageDepositReq:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageDepositReq)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(DepositReq)")
|
||||
case objSubTypeMessageDepositAck:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageDepositAck)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(DepositAck)")
|
||||
case objSubTypeMessageStockReq:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageStockReq)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(StockReq)")
|
||||
case objSubTypeMessageMiscReq:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageMiscReq)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(MiscReq)")
|
||||
case objSubTypeMessageUnionWar:
|
||||
_, err := parseSubTypeMessageUnionWar(m, r)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageUnionWar.")
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageUnionWar)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(UnionWar)")
|
||||
case objSubTypeMessageGRolesReq:
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageGRolesReq)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(GRolesReq)")
|
||||
case objSubTypeMessageGRolesAck:
|
||||
cwm, err := parseSubTypeMessageGRolesAck(m, r)
|
||||
cwm.Msg = m
|
||||
clientMsgGRolesAck(cwm)
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageGRolesAck)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(GRolesAck)")
|
||||
case objSubTypeMessageAuctionAnnounce:
|
||||
cwm := ChatWarsMessageAuctionAnnounce{
|
||||
ObjID64: objId,
|
||||
@ -258,13 +195,9 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||
cwm.End, _ = fromChatWarsDate(r.ReplaceAllString(m.Text, "${End}"))
|
||||
err = insertMsgAuctionAnnounce(&cwm)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgAuctionAnnounce")
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageAuctionAnnounce)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(AuctionAnnounce)")
|
||||
case objSubTypeMessageTimeAck:
|
||||
_, err := fromChatWarsDate(r.ReplaceAllString(m.Text, "${Day}") + " " + r.ReplaceAllString(m.Text, "${Month}") + " " + r.ReplaceAllString(m.Text, "${Year}") + " " + r.ReplaceAllString(m.Text, "${Hour}") + ":" + r.ReplaceAllString(m.Text, "${Minute}"))
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : fromChatWarsDate")
|
||||
err = setObjSubTypeId(objId, objSubTypeMessageTimeAck)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(objSubTypeMessageTimeAck)")
|
||||
default:
|
||||
log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Unknwon message type in rule %d : %d (%d)\n%s\n", msgParsingRules[i].ID, msgParsingRules[i].MsgTypeID, objId, m.Text)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user