chirpnest/rules.go
2019-05-27 12:04:10 +08:00

125 lines
15 KiB
Go
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"strconv"
)
func resetMsgParsingRules() {
_, err := db.Exec(`TRUNCATE TABLE msg_rules;`)
failOnError(err, "resetMsgParsingRules : truncate table msg_rules")
_, err = db.Exec(`INSERT INTO msg_rules (prio, msg_type_id, descn, rule)
VALUES (5000, ` + strconv.Itoa(objSubTypeMessageReportAck) + `, "Player war report", "^(?P<Castle>[🐉🦅🐺🦈🦌🥔🌑])(\\[(?P<Guild>[A-Z0-9]{1,3})\\]){0,1}(?P<User>([A-Za-z0-9 ]*)) ⚔:(?P<Attack>[0-9]+)(?P<AttackMod>\\((-|\\+)[0-9]+\\)){0,1} 🛡:(?P<Defense>[0-9]+) Lvl: (?P<Level>[0-9]+)\\nYour result on the battlefield:\\n(🔥Exp: (?P<Exp>[0-9]+)\\n){0,1}(💰Gold: (?P<Gold>\\-{0,1}[0-9]+)\\n){0,1}(📦Stock: (?P<Stock>\\-{0,1}[0-9]+)){0,1}(\\n(?P<Stamina>(🔋Stamina restored))){0,1}(\\n(?P<Crit>(⚡Critical strike))){0,1}$")
,(5000, ` + strconv.Itoa(objSubTypeMessageAuctionAnnounce) + `, "Auction annouce", "^Lot #(?P<Lot>[0-9]+) : (?P<Item>.*)\\n(Quality: (?P<Quality>.*)\\n){0,1}(Condition: (?P<Cond>.*)\\n){0,1}Seller: (?P<Seller>.*)\\nCurrent price: (?P<Price>[0-9]+) pouch\\(es\\)\\nBuyer: (?P<Buyer>.*)\\nEnd At: (?P<End>.*)\\nStatus: (?P<Status>.*)(\\n)*(?s:.*)")
,(5000, ` + strconv.Itoa(objSubTypeMessageTimeAck) + `, "Time", "^In Chat Wars world now\\n(?P<Time>.*)\\n(?P<Hour>[0-9]{2}):(?P<Minute>[0-9]{2})\\n(?P<Day>[0-9]{2}) (?P<Month>.+) (?P<Year>[0-9]{4})\\n(?s:.*)$")` +
`,(5000, ` + strconv.Itoa(objSubTypeMessageMiniWar) + `, "Mini War", "^⛳Battle results:\\n` +
`(?P<Gardian1>🔱){0,1}.*(?P<Loot1>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)):(?P<Result1>[^\\x{1F4B0}\\x{1F4E6}]*)((?P<Gold1>(\\-|\\+)[0-9]+)\\x{1F4B0}){0,1}[ ]*((?P<Stock1>(\\-|\\+)[0-9]+)\\x{1F4E6}){0,1}\\n` +
`(?P<Gardian2>🔱){0,1}.*(?P<Loot2>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)):(?P<Result2>[^\\x{1F4B0}\\x{1F4E6}]*)((?P<Gold2>(\\-|\\+)[0-9]+)\\x{1F4B0}){0,1}[ ]*((?P<Stock2>(\\-|\\+)[0-9]+)\\x{1F4E6}){0,1}\\n` +
`(?P<Gardian3>🔱){0,1}.*(?P<Loot3>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)):(?P<Result3>[^\\x{1F4B0}\\x{1F4E6}]*)((?P<Gold3>(\\-|\\+)[0-9]+)\\x{1F4B0}){0,1}[ ]*((?P<Stock3>(\\-|\\+)[0-9]+)\\x{1F4E6}){0,1}\\n` +
`(?P<Gardian4>🔱){0,1}.*(?P<Loot4>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)):(?P<Result4>[^\\x{1F4B0}\\x{1F4E6}]*)((?P<Gold4>(\\-|\\+)[0-9]+)\\x{1F4B0}){0,1}[ ]*((?P<Stock4>(\\-|\\+)[0-9]+)\\x{1F4E6}){0,1}\\n` +
`(?P<Gardian5>🔱){0,1}.*(?P<Loot5>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)):(?P<Result5>[^\\x{1F4B0}\\x{1F4E6}]*)((?P<Gold5>(\\-|\\+)[0-9]+)\\x{1F4B0}){0,1}[ ]*((?P<Stock5>(\\-|\\+)[0-9]+)\\x{1F4E6}){0,1}\\n` +
`(?P<Gardian6>🔱){0,1}.*(?P<Loot6>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)):(?P<Result6>[^\\x{1F4B0}\\x{1F4E6}]*)((?P<Gold6>(\\-|\\+)[0-9]+)\\x{1F4B0}){0,1}[ ]*((?P<Stock6>(\\-|\\+)[0-9]+)\\x{1F4E6}){0,1}\\n` +
`(?P<Gardian7>🔱){0,1}.*(?P<Loot7>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)):(?P<Result7>[^\\x{1F4B0}\\x{1F4E6}]*)((?P<Gold7>(\\-|\\+)[0-9]+)\\x{1F4B0}){0,1}[ ]*((?P<Stock7>(\\-|\\+)[0-9]+)\\x{1F4E6}){0,1}\\n` +
`\\n🏆Scores:\\n` +
`.*(?P<Score1>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)): (?P<Points1>\\+([0-9]+|NaN))\\n` +
`.*(?P<Score2>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)): (?P<Points2>\\+([0-9]+|NaN))\\n` +
`.*(?P<Score3>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)): (?P<Points3>\\+([0-9]+|NaN))\\n` +
`.*(?P<Score4>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)): (?P<Points4>\\+([0-9]+|NaN))\\n` +
`.*(?P<Score5>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)): (?P<Points5>\\+([0-9]+|NaN))\\n` +
`.*(?P<Score6>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)): (?P<Points6>\\+([0-9]+|NaN))\\n` +
`.*(?P<Score7>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)): (?P<Points7>\\+([0-9]+|NaN))\\n` +
`(?s:.*)` +
`Battle (?P<Time>[0-9]{2}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2})$")
,(5000, ` + strconv.Itoa(objSubTypeMessagePillageInc) + `, "Pillage Inc", "^You were strolling around on your horse when you noticed (\\[(?P<Guild>[A-Z0-9]{1,3})\\]){0,1}(?P<Attacker>.*) of .{1}(?P<Castle>(Moonlight|Wolfpack|Deerhorn|Dragonscale|Sharkteeth|Potato|Highnest)) Castle trying to pillage a local village. To stop him click /go$")
,(5000, ` + strconv.Itoa(objSubTypeMessageGo) + `, "Go", "^/go$")
,(5000, ` + strconv.Itoa(objSubTypeMessagePillageGo) + `,"Pillage Go", "^You lift up your sword and charge at the violator.$")
,(5000, ` + strconv.Itoa(objSubTypeMessagePillageWin) + `,"Pillage Win", "^You successfully defeated (\\[(?P<Guild>[A-Z0-9]{1,3})\\]){0,1}(?P<Attacker>.*). As he was crawling away, you picked up some of the gold he left behind. Received (?P<Gold>[0-9]+) gold and (?P<Exp>[0-9]+) exp.$")
,(5000, ` + strconv.Itoa(objSubTypeMessagePillageTimeout) + `,"Pillage Timeout", "^You\\'ve failed to protect the villagers. No more rewards for you.$")
,(5000, ` + strconv.Itoa(objSubTypeMessagePillageLoss) + `,"Pillage Loss", "^You let (\\[(?P<Guild>[A-Z0-9]{1,3})\\]){0,1}(?P<Attacker>.*) go and he pillaged the village. We hope you feel terrible.$")
,(5000, ` + strconv.Itoa(objSubTypeMessageDuelFight) + `, "Duel Fight result #2", "(?P<Life1>(\\-){0,1}[0-9]+).*(?P<Castle1>[🐉🦅🐺🦈🦌🥔🌑])(\\[(?P<Guild1>[A-Z0-9]{1,3})\\]){0,1}(?P<Duelist1>.*)\\n` +
`VS\\n` +
`(?P<Life2>(\\-){0,1}[0-9]+).*(?P<Castle2>[🐉🦅🐺🦈🦌🥔🌑])(\\[(?P<Guild2>[A-Z0-9]{1,3})\\]){0,1}(?P<Duelist2>.*)\\n` +
`(?s:.*)\\n` +
`(\\[(?P<WinGuild>[A-Z0-9]{1,3})\\]){0,1}(?P<WinDuelist>.*) from .*(?P<WinCastle>[🐉🦅🐺🦈🦌🥔🌑]).* Castle stands victorious over (\\[(?P<LossGuild>[A-Z0-9]{1,3})\\]){0,1}(?P<LossDuelist>.*) from .*(?P<LossCastle>[🐉🦅🐺🦈🦌🥔🌑]).* Castle, with blood slowly dripping from his (?P<Weapon>.*).\\n` +
`You received: (?P<Exp>[0-9]+) exp.\\n` +
`(?s:.*)$")
,(5000, ` + strconv.Itoa(objSubTypeMessageDuelFight) + `, "Duel Fight result #1", "(?P<Life1>(\\-){0,1}[0-9]+).*(?P<Castle1>[🐉🦅🐺🦈🦌🥔🌑])(\\[(?P<Guild1>[A-Z0-9]{1,3})\\]){0,1}(?P<Duelist1>.*)\\n` +
`VS\\n` +
`(?P<Life2>(\\-){0,1}[0-9]+).*(?P<Castle2>[🐉🦅🐺🦈🦌🥔🌑])(\\[(?P<Guild2>[A-Z0-9]{1,3})\\]){0,1}(?P<Duelist2>.*)\\n` +
`(?s:.*)\\n` +
`(\\[(?P<WinGuild>[A-Z0-9]{1,3})\\]){0,1}(?P<WinDuelist>.*) from .*(?P<WinCastle>[🐉🦅🐺🦈🦌🥔🌑]).* Castle was stronger than (\\[(?P<LossGuild>[A-Z0-9]{1,3})\\]){0,1}(?P<LossDuelist>.*) from .*(?P<LossCastle>[🐉🦅🐺🦈🦌🥔🌑]).* Castle.\\n` +
`You received: (?P<Exp>[0-9]+) exp.\\n` +
`(?s:.*)$")
,(5000, ` + strconv.Itoa(objSubTypeMessageReportReq) + `, "Report request", "^/report$")
,(5000, ` + strconv.Itoa(objSubTypeMessageGReportReq) + `, "Guild report request", "^/g_report$")
,(5000, ` + strconv.Itoa(objSubTypeMessageHeroReq) + `, "Hero request", "^/hero$")
,(5000, ` + strconv.Itoa(objSubTypeMessageMeReq) + `, "Me request", "^🏅Me$")
,(5000, ` + strconv.Itoa(objSubTypeMessageInventoryReq) + `, "Inventory request", "^/inv$")
,(5000, ` + strconv.Itoa(objSubTypeMessageTimeReq) + `, "Time request", "^/time$")
,(5000, ` + strconv.Itoa(objSubTypeMessagePledge) + `, "Pledge", "^/pledge$")
,(5000, ` + strconv.Itoa(objSubTypeMessageBuyReq) + `, "Buy request", "^/wtb_(?P<Item>[0-9]+)(_(?P<Quantity>[0-9]+)){0,1}$")
,(5000, ` + strconv.Itoa(objSubTypeMessageSellReq) + `, "Sell request", "^/wts_(?P<Item>[0-9]+)(_(?P<Quantity>[0-9]+)(_(?P<Price>[0-9]+)){0,1}){0,1}$")
,(5000, ` + strconv.Itoa(objSubTypeMessageOrderbookReq) + `, "Orderbook request", "^/t_(?P<Item>[0-9]+)$")
,(5000, ` + strconv.Itoa(objSubTypeMessageOrderbookAck) + `, "Orderbook request", "^$")
,(5000, ` + strconv.Itoa(objSubTypeMessageWithdrawReq) + `, "Withdraw Req", "^/g_withdraw( )+(?P<Item1>[a-z0-9]+)( )+(?P<Quantity1>[0-9]+)` +
`(( )+(?P<Item2>[a-z0-9]+)( )+(?P<Quantity2>[0-9]+)){0,1}` +
`(( )+(?P<Item3>[a-z0-9]+)( )+(?P<Quantity3>[0-9]+)){0,1}` +
`(( )+(?P<Item4>[a-z0-9]+)( )+(?P<Quantity4>[0-9]+)){0,1}` +
`(( )+(?P<Item5>[a-z0-9]+)( )+(?P<Quantity5>[0-9]+)){0,1}` +
`(( )+(?P<Item6>[a-z0-9]+)( )+(?P<Quantity6>[0-9]+)){0,1}` +
`(( )+(?P<Item7>[a-z0-9]+)( )+(?P<Quantity7>[0-9]+)){0,1}` +
`(( )+(?P<Item8>[a-z0-9]+)( )+(?P<Quantity8>[0-9]+)){0,1}$")
,(5000, ` + strconv.Itoa(objSubTypeMessageWithdrawCode) + `, "Withdraw Code #1", "^Withdrawing (?P<Item1>.*) x (?P<Quantity1>.*). Recipient shall send to bot:\\n` +
`/g_receive [a-z0-9]+$")
,(5000, ` + strconv.Itoa(objSubTypeMessageWithdrawCode) + `, "Withdraw Code #2", "^Withdrawing:\\n` +
`(?P<Item1>.*) x (?P<Quantity1>.*)\\n` +
`((?P<Item2>.*) x (?P<Quantity2>.*)\\n){0,1}` +
`((?P<Item3>.*) x (?P<Quantity3>.*)\\n){0,1}` +
`((?P<Item4>.*) x (?P<Quantity4>.*)\\n){0,1}` +
`((?P<Item5>.*) x (?P<Quantity5>.*)\\n){0,1}` +
`((?P<Item6>.*) x (?P<Quantity6>.*)\\n){0,1}` +
`((?P<Item7>.*) x (?P<Quantity7>.*)\\n){0,1}` +
`((?P<Item8>.*) x (?P<Quantity8>.*)\\n){0,1}` +
`Recipient shall send to bot:\\n` +
`/g_receive [a-z0-9]+$")
,(5000, ` + strconv.Itoa(objSubTypeMessageWithdrawRcv) + `, "Withdraw Received #1", "^Received (?P<Item1>.*) x (?P<Quantity1>.*)$")
,(5000, ` + strconv.Itoa(objSubTypeMessageWithdrawRcv) + `, "Withdraw Received #2", "^Received:` +
`(\\n(?P<Item1>.*) x (?P<Quantity1>.*))` +
`(\\n(?P<Item2>.*) x (?P<Quantity2>.*)){0,1}` +
`(\\n(?P<Item3>.*) x (?P<Quantity3>.*)){0,1}` +
`(\\n(?P<Item4>.*) x (?P<Quantity4>.*)){0,1}` +
`(\\n(?P<Item5>.*) x (?P<Quantity5>.*)){0,1}` +
`(\\n(?P<Item6>.*) x (?P<Quantity6>.*)){0,1}` +
`(\\n(?P<Item7>.*) x (?P<Quantity7>.*)){0,1}` +
`(\\n(?P<Item8>.*) x (?P<Quantity8>.*)){0,1}$")
,(5000, ` + strconv.Itoa(objSubTypeMessageDepositReq) + `, "Deposit Req", "^/g_deposit (?P<Item>[a-z0-9]+) (?P<Quantity>[0-9]+)$")
,(5000, ` + strconv.Itoa(objSubTypeMessageDepositAck) + `, "Deposit Ack #2", "^Deposited successfully: (?P<Item>.*) \\((?P<Quantity>[0-9]+)\\)$")
,(5000, ` + strconv.Itoa(objSubTypeMessageDepositAck) + `, "Deposit Ack #1", "^Deposited (?P<Item>.*) \\((?P<Quantity>[0-9]+)\\) successfully$")
,(5000, ` + strconv.Itoa(objSubTypeMessageStockReq) + `, "Stock Req", "^/stock$")
,(5000, ` + strconv.Itoa(objSubTypeMessageMiscReq) + `, "Misc Req", "^/misc$")` + /*
,(5000, ` + strconv.Itoa(objSubTypeMessageUnionWar) + `, "Union war report", "^(🏠Trade union news:\\n){0,1}` +
`(((?P<Union>[A-Z][a-z]+ [A-Z][a-z]+) was (?P<StatusUnion>(easily defended|defended successfully|breached.|easily breached.|closely breached.))( Attackers have pillaged union for (?P<Loot>[0-9]+) stock){0,1}:\\n` +
`(🎖Attack leaders: (?P<AtkUnionCastle1>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkUnionUser1>[^,]+)(,(?P<AtkUnionCastle2>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkUnionUser2>[^,]+)){0,1}(,(?P<AtkUnionCastle3>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkUnionUser3>[^,]+)){0,1}(,(?P<AtkUnionCastle4>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkUnionUser4>[^,]+)){0,1}){0,1}(\\n){0,1}` +
`(🎖Defense leaders: (?P<DefUnionCastle1>[🐉🦅🐺🦈🦌🥔🌑])(?P<DefUnionUser1>[^,]+)(,(?P<DefUnionCastle2>[🐉🦅🐺🦈🦌🥔🌑])(?P<DefUnionUser2>[^,]+)){0,1}(,(?P<DefUnionCastle3>[🐉🦅🐺🦈🦌🥔🌑])(?P<DefUnionUser3>[^,]+)){0,1}(,(?P<DefUnionCastle4>[🐉🦅🐺🦈🦌🥔🌑])(?P<DefUnionUser4>[^,]+)){0,1}){0,1}(\\n){0,1})(\\n)*)*` +
`(🎪State of exclusive rights:\\n){0,1}` +
`((?P<Fair>[A-Z][a-z]+ [A-Z][a-z]+) (?P<StatusFair>(was protected|belongs to)( (?P<Attacker>[A-Z][a-z]+ [A-Z][a-z]+):)\\n` +
`(🎖Attack leaders: (?P<AtkFairCastle1>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkFairUser1>[^,]+)(,(?P<AtkFairCastle2>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkFairUser2>[^,]+)){0,1}(,(?P<AtkFairCastle3>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkFairUser3>[^,]+)){0,1}(,(?P<AtkFairCastle4>[🐉🦅🐺🦈🦌🥔🌑])(?P<AtkFairUser4>[^,]+)){0,1}){0,1}(\\n){0,1}` +
`(🎖Defense leaders: (?P<DefFairCastle1>[🐉🦅🐺🦈🦌🥔🌑])(?P<DefFairUser1>[^,]+)(,(?P<DefFairCastle2>[🐉🦅🐺🦈🦌🥔🌑])(?P<DefFairUser2>[^,]+)){0,1}(,(?P<DefFairCastle3>[🐉🦅🐺🦈🦌🥔🌑])(?P<DefFairUser3>[^,]+)){0,1}(,(?P<DefFairCastle4>[🐉🦅🐺🦈🦌🥔🌑])(?P<DefFairUser4>[^,]+)){0,1}){0,1}(\\n){0,1})(\\n)*)*` +
`$")*/`
,(5000, ` + strconv.Itoa(objSubTypeMessageUnionWar) + `, "Union war report", "^(🏠Trade union news:\\n){0,1}` +
`((([A-Z][a-z]+ [A-Z][a-z]+) was ((easily defended|defended successfully|breached.|easily breached.|closely breached.))( Attackers have pillaged union for ([0-9]+) stock){0,1}:\\n` +
`(🎖Attack leaders: ([🐉🦅🐺🦈🦌🥔🌑])([^,]+)(,([🐉🦅🐺🦈🦌🥔🌑])([^,]+)){0,1}(,([🐉🦅🐺🦈🦌🥔🌑])([^,]+)){0,1}(,([🐉🦅🐺🦈🦌🥔🌑])([^,]+)){0,1}){0,1}(\\n){0,1}` +
`(🎖Defense leaders: ([🐉🦅🐺🦈🦌🥔🌑])([^,]+)(,([🐉🦅🐺🦈🦌🥔🌑])([^,]+)){0,1}(,([🐉🦅🐺🦈🦌🥔🌑])([^,]+)){0,1}(,([🐉🦅🐺🦈🦌🥔🌑])([^,]+)){0,1}){0,1}(\\n){0,1})(\\n)*)*` +
`(🎪State of exclusive rights:\\n){0,1}` +
`(([A-Z][a-z]+ [A-Z][a-z]+) ((was protected|belongs to)( ([A-Z][a-z]+ [A-Z][a-z]+):)\\n` +
`(🎖Attack leaders: ([🐉🦅🐺🦈🦌🥔🌑])([^,]+)(,([🐉🦅🐺🦈🦌🥔🌑])([^,]+)){0,1}(,([🐉🦅🐺🦈🦌🥔🌑])([^,]+)){0,1}(,([🐉🦅🐺🦈🦌🥔🌑])([^,]+)){0,1}){0,1}(\\n){0,1}` +
`(🎖Defense leaders: ([🐉🦅🐺🦈🦌🥔🌑])([^,]+)(,([🐉🦅🐺🦈🦌🥔🌑])([^,]+)){0,1}(,([🐉🦅🐺🦈🦌🥔🌑])([^,]+)){0,1}(,([🐉🦅🐺🦈🦌🥔🌑])([^,]+)){0,1}){0,1}(\\n){0,1})(\\n)*)*` +
`$")
,(5000, ` + strconv.Itoa(objSubTypeMessageUnionWar) + `, "Union war rep with both", "^(🏠Trade union news:\n)(?P<Union>(?s:.*))(🎪State of exclusive rights:\n)(?P<Fair>(?s:.*))$")
,(4900, ` + strconv.Itoa(objSubTypeMessageUnionWar) + `, "Union war rep only union", "^(🏠Trade union news:\n)(?P<Union>(?s:.*))(🎪State of exclusive rights:\n){0}(?P<Fair>(?s:.*))$")
,(4900, ` + strconv.Itoa(objSubTypeMessageUnionWar) + `, "Union war rep only fair", "^(🏠Trade union news:\n){0}(?P<Union>(?s:.*))(🎪State of exclusive rights:\n)(?P<Fair>(?s:.*))$")
,(5000, ` + strconv.Itoa(objSubTypeMessageTimeout) + `, "Generic timeout", "^Too late. Action is not available.$")
;`)
failOnError(err, "resetMsgParsingRules : populate table msg_rules")
}