test
This commit is contained in:
parent
5419909572
commit
2d9d2380a7
|
@ -1,6 +1,10 @@
|
||||||
ChirpNestBot
|
ChirpNestBot
|
||||||
- [ ] Eliminate cache map race conditions (all maps with read/write)
|
- [ ] Test HTML in message
|
||||||
- [ ] Export/import all messages
|
- [ ] 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
|
- [ ] Turn on/off queue consumption
|
||||||
- [ ] Client de-registration announce
|
- [ ] Client de-registration announce
|
||||||
- [ ] Items parsing/identification
|
- [ ] Items parsing/identification
|
||||||
|
@ -16,6 +20,7 @@ ChirpNestBot
|
||||||
- [ ] Experience graphs & forecast
|
- [ ] Experience graphs & forecast
|
||||||
- [ ] Impersonate
|
- [ ] Impersonate
|
||||||
- [x] Foray interception
|
- [x] Foray interception
|
||||||
|
- [x] Export/import all messages
|
||||||
Progression :
|
Progression :
|
||||||
- 0 -> 4 : Forest + Foray ;
|
- 0 -> 4 : Forest + Foray ;
|
||||||
- 5 -> 10 : Forest + Foray + Arena ;
|
- 5 -> 10 : Forest + Foray + Arena ;
|
43
bot.go
43
bot.go
|
@ -23,6 +23,7 @@ func BotHandlers(b *tb.Bot) {
|
||||||
})
|
})
|
||||||
|
|
||||||
b.Handle("/test", botTest)
|
b.Handle("/test", botTest)
|
||||||
|
b.Handle("/test_html", botTestHTML)
|
||||||
b.Handle("/msg_rescan", botMsgRescan)
|
b.Handle("/msg_rescan", botMsgRescan)
|
||||||
b.Handle("/msg_rescan_all", botMsgRescanAll)
|
b.Handle("/msg_rescan_all", botMsgRescanAll)
|
||||||
b.Handle("/msg_dump", botMsgDump)
|
b.Handle("/msg_dump", botMsgDump)
|
||||||
|
@ -109,6 +110,22 @@ func botHelp(m *tb.Message) {
|
||||||
return
|
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) {
|
func botTest(m *tb.Message) {
|
||||||
if !m.Private() {
|
if !m.Private() {
|
||||||
return
|
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
|
r := regexp.MustCompile("^(http|https)://[a-z0-9./]+.zip$") // https://dump.siteop.biz/20190609163137.backup.zip
|
||||||
if r.MatchString(m.Payload) {
|
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)
|
resp, err := http.Get(m.Payload)
|
||||||
logOnError(err, "botMsgLoad : Get")
|
logOnError(err, "botMsgLoad : Get")
|
||||||
|
@ -281,9 +291,26 @@ func botMsgLoad(m *tb.Message) {
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
buf.ReadFrom(resp.Body)
|
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")
|
logOnError(err, "botMsgLoad : UnzipMessages")
|
||||||
|
|
||||||
|
c = TGCommand{
|
||||||
|
Type: commandReplyMsg,
|
||||||
|
Text: "Messages injected.",
|
||||||
|
FromMsgID64: int64(m.ID),
|
||||||
|
FromChatID64: m.Chat.ID,
|
||||||
|
}
|
||||||
|
TGCmdQueue <- c
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
c := TGCommand{
|
c := TGCommand{
|
||||||
Type: commandReplyMsg,
|
Type: commandReplyMsg,
|
||||||
|
|
5
def.go
5
def.go
|
@ -44,6 +44,7 @@ type TGCommand struct {
|
||||||
ToUserID64 int64 `json:"to_user_id"`
|
ToUserID64 int64 `json:"to_user_id"`
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
Document tb.Document `json:"document"`
|
Document tb.Document `json:"document"`
|
||||||
|
ParseMode int64 `json:"parse_mode"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ChatWarsCastle struct {
|
type ChatWarsCastle struct {
|
||||||
|
@ -246,6 +247,10 @@ const (
|
||||||
commandRefreshMsg = 5
|
commandRefreshMsg = 5
|
||||||
commandSendDocument = 6
|
commandSendDocument = 6
|
||||||
|
|
||||||
|
cmdParseModePlain = 1
|
||||||
|
cmdParseModeMarkDown = 2
|
||||||
|
cmdParseModeHTML = 3
|
||||||
|
|
||||||
objTypeUser = 1
|
objTypeUser = 1
|
||||||
objTypeGuild = 2
|
objTypeGuild = 2
|
||||||
objTypeMessage = 3
|
objTypeMessage = 3
|
||||||
|
|
8
rules.go
8
rules.go
|
@ -9,7 +9,13 @@ func resetMsgParsingRules() {
|
||||||
failOnError(err, "resetMsgParsingRules : truncate table msg_rules")
|
failOnError(err, "resetMsgParsingRules : truncate table msg_rules")
|
||||||
|
|
||||||
_, err = db.Exec(`INSERT INTO msg_rules (prio, msg_type_id, descn, rule)
|
_, 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(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(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` +
|
`,(5000, ` + strconv.Itoa(objSubTypeMessageMiniWar) + `, "Mini War", "^⛳️Battle results:\\n` +
|
||||||
|
|
20
workers.go
20
workers.go
|
@ -184,7 +184,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||||
cwm.ObjID64 = objId
|
cwm.ObjID64 = objId
|
||||||
err = insertMsgAuctionAnnounce(cwm)
|
err = insertMsgAuctionAnnounce(cwm)
|
||||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : insertMsgAuctionAnnounce")
|
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{
|
p := JobPayloadMsgRefresh{
|
||||||
ObjID64: m.ObjID64,
|
ObjID64: m.ObjID64,
|
||||||
}
|
}
|
||||||
|
@ -248,19 +249,30 @@ func TGCmdWorker(id int, b *tb.Bot, cmds <-chan TGCommand) {
|
||||||
j, err := json.Marshal(c)
|
j, err := json.Marshal(c)
|
||||||
logOnError(err, "TGCmdWorker["+strconv.Itoa(id)+"] : Marshal(c)")
|
logOnError(err, "TGCmdWorker["+strconv.Itoa(id)+"] : Marshal(c)")
|
||||||
log.Printf("TGCmdWorker["+strconv.Itoa(id)+"] : new command.\n%s\n", string(j))
|
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 {
|
switch c.Type {
|
||||||
case commandSendMsg:
|
case commandSendMsg:
|
||||||
if c.ToChatID64 != 0 {
|
if c.ToChatID64 != 0 {
|
||||||
ch := tb.Chat{
|
ch := tb.Chat{
|
||||||
ID: c.ToChatID64,
|
ID: c.ToChatID64,
|
||||||
}
|
}
|
||||||
_, err := b.Send(&ch, c.Text)
|
_, err := b.Send(&ch, c.Text, opt)
|
||||||
logOnError(err, "TGCmdWorker["+strconv.Itoa(id)+"] : SendMsg Chat")
|
logOnError(err, "TGCmdWorker["+strconv.Itoa(id)+"] : SendMsg Chat")
|
||||||
} else if c.ToUserID64 != 0 {
|
} else if c.ToUserID64 != 0 {
|
||||||
u := tb.User{
|
u := tb.User{
|
||||||
ID: int(c.ToUserID64),
|
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")
|
logOnError(err, "TGCmdWorker["+strconv.Itoa(id)+"] : SendMsg User")
|
||||||
}
|
}
|
||||||
case commandReplyMsg:
|
case commandReplyMsg:
|
||||||
|
@ -271,7 +283,7 @@ func TGCmdWorker(id int, b *tb.Bot, cmds <-chan TGCommand) {
|
||||||
ID: int(c.FromMsgID64),
|
ID: int(c.FromMsgID64),
|
||||||
Chat: &ch,
|
Chat: &ch,
|
||||||
}
|
}
|
||||||
_, err := b.Reply(&m, c.Text)
|
_, err := b.Reply(&m, c.Text, opt)
|
||||||
logOnError(err, "TGCmdWorker["+strconv.Itoa(id)+"] : ReplyMsg")
|
logOnError(err, "TGCmdWorker["+strconv.Itoa(id)+"] : ReplyMsg")
|
||||||
case commandSendDocument:
|
case commandSendDocument:
|
||||||
if c.ToChatID64 != 0 {
|
if c.ToChatID64 != 0 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user