This commit is contained in:
shoopea 2019-06-10 17:05:59 +08:00
parent 5419909572
commit 2d9d2380a7
5 changed files with 70 additions and 15 deletions

View File

@ -1,6 +1,10 @@
ChirpNestBot
- [ ] Eliminate cache map race conditions (all maps with read/write)
- [ ] Export/import all messages
- [ ] Test HTML in message
- [ ] Update auction from broadcast
- [ ] Update old auctions with client
- [ ] Convert config to json
- [ ] Eliminate cache map race conditions (all maps with read/write) and use redis ?
- [ ] Transform import/export to jobs
- [ ] Turn on/off queue consumption
- [ ] Client de-registration announce
- [ ] Items parsing/identification
@ -16,6 +20,7 @@ ChirpNestBot
- [ ] Experience graphs & forecast
- [ ] Impersonate
- [x] Foray interception
- [x] Export/import all messages
Progression :
- 0 -> 4 : Forest + Foray ;
- 5 -> 10 : Forest + Foray + Arena ;

43
bot.go
View File

@ -23,6 +23,7 @@ func BotHandlers(b *tb.Bot) {
})
b.Handle("/test", botTest)
b.Handle("/test_html", botTestHTML)
b.Handle("/msg_rescan", botMsgRescan)
b.Handle("/msg_rescan_all", botMsgRescanAll)
b.Handle("/msg_dump", botMsgDump)
@ -109,6 +110,22 @@ func botHelp(m *tb.Message) {
return
}
func botTestHTML(m *tb.Message) {
if !m.Private() {
return
}
c := TGCommand{
Type: commandReplyMsg,
Text: "<a href='https://t.me/share/url?url=/tu_def jgm2v8'>Defend</a>",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
ParseMode: cmdParseModeHTML,
}
TGCmdQueue <- c
return
}
func botTest(m *tb.Message) {
if !m.Private() {
return
@ -267,13 +284,6 @@ func botMsgLoad(m *tb.Message) {
}
r := regexp.MustCompile("^(http|https)://[a-z0-9./]+.zip$") // https://dump.siteop.biz/20190609163137.backup.zip
if r.MatchString(m.Payload) {
c := TGCommand{
Type: commandReplyMsg,
Text: "Got file",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
resp, err := http.Get(m.Payload)
logOnError(err, "botMsgLoad : Get")
@ -281,9 +291,26 @@ func botMsgLoad(m *tb.Message) {
buf := new(bytes.Buffer)
buf.ReadFrom(resp.Body)
err = UnzipMessages(buf.Bytes())
c := TGCommand{
Type: commandReplyMsg,
Text: "File downloaded.",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
err := UnzipMessages(buf.Bytes())
logOnError(err, "botMsgLoad : UnzipMessages")
c = TGCommand{
Type: commandReplyMsg,
Text: "Messages injected.",
FromMsgID64: int64(m.ID),
FromChatID64: m.Chat.ID,
}
TGCmdQueue <- c
} else {
c := TGCommand{
Type: commandReplyMsg,

5
def.go
View File

@ -44,6 +44,7 @@ type TGCommand struct {
ToUserID64 int64 `json:"to_user_id"`
Text string `json:"text"`
Document tb.Document `json:"document"`
ParseMode int64 `json:"parse_mode"`
}
type ChatWarsCastle struct {
@ -246,6 +247,10 @@ const (
commandRefreshMsg = 5
commandSendDocument = 6
cmdParseModePlain = 1
cmdParseModeMarkDown = 2
cmdParseModeHTML = 3
objTypeUser = 1
objTypeGuild = 2
objTypeMessage = 3

View File

@ -9,7 +9,13 @@ func resetMsgParsingRules() {
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}$")
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]+)\\n` +
`Your result on the battlefield:\\n` +
`(🔥Exp: (?P<Exp>[0-9]+)){0,1}(\\n)*` +
`(💰Gold: (?P<Gold>\\-{0,1}[0-9]+)){0,1}(\\n)*` +
`(📦Stock: (?P<Stock>\\-{0,1}[0-9]+)){0,1}(\\n)*` +
`(❤Hp: (?P<HP>\\-[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<SellerCastle>[🐉🦅🐺🦈🦌🥔🌑])( ){0,1}(\\[(?P<SellerGuild>[A-Z0-9]{1,3})\\]){0,1}(?P<SellerUser>.*){0,1}\\nCurrent price: (?P<Price>[0-9]+) pouch\\(es\\)\\nBuyer: (None|(?P<BuyerCastle>[🐉🦅🐺🦈🦌🥔🌑])( ){0,1}(\\[(?P<BuyerGuild>[A-Z0-9]{1,3})\\]){0,1}(?P<BuyerUser>.*){0,1})\\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` +

View File

@ -184,7 +184,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
cwm.ObjID64 = objId
err = insertMsgAuctionAnnounce(cwm)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgAuctionAnnounce")
if cwm.End.Add(15 * time.Second).After(time.Now()) {
if cwm.End.Add(15*time.Second).After(time.Now()) ||
(cwm.End.Before(time.Now()) && strings.Compare(cwm.Status, `#active`) == 0) {
p := JobPayloadMsgRefresh{
ObjID64: m.ObjID64,
}
@ -248,19 +249,30 @@ func TGCmdWorker(id int, b *tb.Bot, cmds <-chan TGCommand) {
j, err := json.Marshal(c)
logOnError(err, "TGCmdWorker["+strconv.Itoa(id)+"] : Marshal(c)")
log.Printf("TGCmdWorker["+strconv.Itoa(id)+"] : new command.\n%s\n", string(j))
opt := SendOptions{}
switch c.ParseMode {
case cmdParseModePlain:
opt.ParseMode = tb.ModeDefault
case cmdParseModeMarkDown:
opt.ParseMode = tb.ModeMarkdown
case cmdParseModeHTML:
opt.ParseMode = tb.ModeHTML
default:
opt.ParseMode = tb.ModeDefault
}
switch c.Type {
case commandSendMsg:
if c.ToChatID64 != 0 {
ch := tb.Chat{
ID: c.ToChatID64,
}
_, err := b.Send(&ch, c.Text)
_, err := b.Send(&ch, c.Text, opt)
logOnError(err, "TGCmdWorker["+strconv.Itoa(id)+"] : SendMsg Chat")
} else if c.ToUserID64 != 0 {
u := tb.User{
ID: int(c.ToUserID64),
}
_, err := b.Send(&u, c.Text)
_, err := b.Send(&u, c.Text, opt)
logOnError(err, "TGCmdWorker["+strconv.Itoa(id)+"] : SendMsg User")
}
case commandReplyMsg:
@ -271,7 +283,7 @@ func TGCmdWorker(id int, b *tb.Bot, cmds <-chan TGCommand) {
ID: int(c.FromMsgID64),
Chat: &ch,
}
_, err := b.Reply(&m, c.Text)
_, err := b.Reply(&m, c.Text, opt)
logOnError(err, "TGCmdWorker["+strconv.Itoa(id)+"] : ReplyMsg")
case commandSendDocument:
if c.ToChatID64 != 0 {