This commit is contained in:
shoopea 2019-06-02 17:30:04 +08:00
parent 887226ccf9
commit 835afa709f
4 changed files with 56 additions and 100 deletions

11
def.go
View File

@ -66,6 +66,11 @@ type ChatWarsItem struct {
Weight int `json:"weight"` Weight int `json:"weight"`
} }
type ChatWarsItems struct {
ItemID64 int64 `json:"item_id"`
Quantity int64 `json:"quantity"`
}
type ChatWarsMessage struct { type ChatWarsMessage struct {
ObjID64 int64 `json:"obj_id"` ObjID64 int64 `json:"obj_id"`
UserID64 int64 `json:"user_id"` UserID64 int64 `json:"user_id"`
@ -76,6 +81,12 @@ type ChatWarsMessage struct {
Text string `json:"text"` Text string `json:"text"`
} }
type ChatWarsMessageStock struct {
Msg *ChatWarsMessage `json:"msg"`
OwnerID64 int64 `json:"owner_id"`
ItemList []ChatWarsItems `json:"item_list"`
}
type ChatWarsMessageReportAck struct { type ChatWarsMessageReportAck struct {
ObjID64 int64 `json:"obj_id"` ObjID64 int64 `json:"obj_id"`
} }

View File

@ -105,6 +105,8 @@ func main() {
logOnError(err, "Caching guilds") logOnError(err, "Caching guilds")
err = loadObjUser() err = loadObjUser()
logOnError(err, "Caching user") logOnError(err, "Caching user")
err = loadObjItem()
logOnError(err, "Caching user")
// Registering bot // Registering bot
b, err := tb.NewBot(tb.Settings{ b, err := tb.NewBot(tb.Settings{

10
msg.go
View File

@ -30,6 +30,16 @@ func parseSubTypeMessageReportAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWa
return &cwm, nil 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) { func parseSubTypeMessageMeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageMeAck, error) {
var i int64 var i int64

View File

@ -90,11 +90,43 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
err = setObjSubTypeId(objId, msgParsingRules[i].MsgTypeID) err = setObjSubTypeId(objId, msgParsingRules[i].MsgTypeID)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId")
switch msgParsingRules[i].MsgTypeID { 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: case objSubTypeMessageReportAck:
cwm, err := parseSubTypeMessageReportAck(m, r) cwm, err := parseSubTypeMessageReportAck(m, r)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageReportAck.") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageReportAck.")
cwm.ObjID64 = objId cwm.ObjID64 = objId
case objSubTypeMessageMiniWar: case objSubTypeMessageMiniWar:
cwm, err := parseSubTypeMessageMiniWar(m, r) cwm, err := parseSubTypeMessageMiniWar(m, r)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMiniWar.") 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) _, 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)") 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: case objSubTypeMessageMeAck:
cwm, err := parseSubTypeMessageMeAck(m, r) cwm, err := parseSubTypeMessageMeAck(m, r)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMeAck.") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMeAck.")
@ -142,105 +161,23 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
clientMsgMeAck(cwm) clientMsgMeAck(cwm)
_, err = addObjXP(cwm.UserID64, cwm.ExpNow, cwm.ExpLvl, cwm.Level, m.Date) _, err = addObjXP(cwm.UserID64, cwm.ExpNow, cwm.ExpLvl, cwm.Level, m.Date)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : addObjXP(MeAck)") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : addObjXP(MeAck)")
err = setObjSubTypeId(objId, objSubTypeMessageMeAck)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(MeAck)")
case objSubTypeMessageGoQuestAck: case objSubTypeMessageGoQuestAck:
cwm, err := parseSubTypeMessageGoQuestAck(m, r) cwm, err := parseSubTypeMessageGoQuestAck(m, r)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMeAck.") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageMeAck.")
cwm.ObjID64 = objId 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: case objSubTypeMessageDuelFight:
cwm, err := parseSubTypeMessageDuelFight(m, r) cwm, err := parseSubTypeMessageDuelFight(m, r)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageDuelFight.") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageDuelFight.")
cwm.ObjID64 = objId cwm.ObjID64 = objId
err = insertMsgDuelFight(cwm) err = insertMsgDuelFight(cwm)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgAuctionAnnounce") 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: case objSubTypeMessageUnionWar:
_, err := parseSubTypeMessageUnionWar(m, r) _, err := parseSubTypeMessageUnionWar(m, r)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing objSubTypeMessageUnionWar.") 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: case objSubTypeMessageGRolesAck:
cwm, err := parseSubTypeMessageGRolesAck(m, r) cwm, err := parseSubTypeMessageGRolesAck(m, r)
cwm.Msg = m cwm.Msg = m
clientMsgGRolesAck(cwm) clientMsgGRolesAck(cwm)
err = setObjSubTypeId(objId, objSubTypeMessageGRolesAck)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(GRolesAck)")
case objSubTypeMessageAuctionAnnounce: case objSubTypeMessageAuctionAnnounce:
cwm := ChatWarsMessageAuctionAnnounce{ cwm := ChatWarsMessageAuctionAnnounce{
ObjID64: objId, ObjID64: objId,
@ -258,13 +195,9 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
cwm.End, _ = fromChatWarsDate(r.ReplaceAllString(m.Text, "${End}")) cwm.End, _ = fromChatWarsDate(r.ReplaceAllString(m.Text, "${End}"))
err = insertMsgAuctionAnnounce(&cwm) err = insertMsgAuctionAnnounce(&cwm)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgAuctionAnnounce") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgAuctionAnnounce")
err = setObjSubTypeId(objId, objSubTypeMessageAuctionAnnounce)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(AuctionAnnounce)")
case objSubTypeMessageTimeAck: 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}")) _, 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") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : fromChatWarsDate")
err = setObjSubTypeId(objId, objSubTypeMessageTimeAck)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId(objSubTypeMessageTimeAck)")
default: 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) 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)
} }