This commit is contained in:
shoopea 2019-05-10 10:26:37 +08:00
parent 4dff5544e1
commit 142e051241
3 changed files with 37 additions and 7 deletions

26
bot.go
View File

@ -19,12 +19,10 @@ func StartBot() {
Poller: &tb.LongPoller{Timeout: 10 * time.Second}, Poller: &tb.LongPoller{Timeout: 10 * time.Second},
}) })
if err != nil { failOnError(err, "StartBot")
log.Fatal(err)
return
}
b.Handle("/hello", botHello) b.Handle("/hello", botHello)
b.Handle("/rescan_msg", botRescanMsg)
b.Handle(tb.OnPhoto, botPhoto) b.Handle(tb.OnPhoto, botPhoto)
b.Handle(tb.OnChannelPost, botChannelPost) b.Handle(tb.OnChannelPost, botChannelPost)
b.Handle(tb.OnQuery, botQuery) b.Handle(tb.OnQuery, botQuery)
@ -34,12 +32,14 @@ func StartBot() {
} }
func botPhoto(m *tb.Message) { func botPhoto(m *tb.Message) {
fmt.Println("OnPhoto :", m.Text) fmt.Println("botPhoto :", m.Text)
// photos only // photos only
} }
func botHello(m *tb.Message) { func botHello(m *tb.Message) {
fmt.Println("botHello :", m.Text)
if !m.Private() { if !m.Private() {
fmt.Println("botHello : !m.Private()")
return return
} }
// fmt.Println("Hello payload :", m.Payload) // <PAYLOAD> // fmt.Println("Hello payload :", m.Payload) // <PAYLOAD>
@ -48,18 +48,30 @@ func botHello(m *tb.Message) {
} }
func botChannelPost(m *tb.Message) { func botChannelPost(m *tb.Message) {
fmt.Println("OnChannelPost :", m.Text) fmt.Println("botChannelPost :", m.Text)
PrintText(m) PrintText(m)
// channel posts only // channel posts only
} }
func botQuery(q *tb.Query) { func botQuery(q *tb.Query) {
fmt.Println("Query ?") fmt.Println("botQuery")
// incoming inline queries // incoming inline queries
} }
func botText(m *tb.Message) { func botText(m *tb.Message) {
fmt.Println("botText :", m.Text)
PrintText(m) PrintText(m)
// all the text messages that weren't // all the text messages that weren't
// captured by existing handlers // captured by existing handlers
} }
func botRescanMsg(m *tb.Message) {
fmt.Println("botRescanMsg :", m.Text)
if !m.Private() {
fmt.Println("botRescanMsg : !m.Private()")
return
}
// fmt.Println("Hello payload :", m.Payload) // <PAYLOAD>
PrintText(m)
b.Send(m.Sender, "rescan")
}

2
def.go
View File

@ -61,6 +61,8 @@ const (
objSubTypeMessagePillageAck = 314 objSubTypeMessagePillageAck = 314
objSubTypeMessageTributeAck = 315 objSubTypeMessageTributeAck = 315
objSubTypeMessageAuctionAnnounce = 316 objSubTypeMessageAuctionAnnounce = 316
objSubTypeMessageAuctionUpdReq = 317
objSubTypeMessageAcutionUpdAck = 318
objSubTypeMessageTime = 317 objSubTypeMessageTime = 317
objSubTypeJobPillage = 601 objSubTypeJobPillage = 601
objSubTypeJobTribute = 602 objSubTypeJobTribute = 602

16
sql.go
View File

@ -155,6 +155,22 @@ func initDB() {
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`) ) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_msg_auction_announce") failOnError(err, "initDB : create table obj_msg_auction_announce")
_, err = db.Exec(`CREATE TABLE obj_msg_auction_upd_req (
obj_id BIGINT UNSIGNED NOT NULL
,lot_id BIGINT UNSIGNED NOT NULL
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_msg_auction_upd_req")
_, err = db.Exec(`CREATE TABLE obj_msg_auction_upd_ack (
obj_id BIGINT UNSIGNED NOT NULL
,seller VARCHAR(32)
,buyer VARCHAR(32)
,item VARCHAR(80)
,FOREIGN KEY (obj_id) REFERENCES obj(id) ON DELETE CASCADE
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
failOnError(err, "initDB : create table obj_msg_auction_upd_req")
_, err = db.Exec(`CREATE TABLE msg_rules ( _, err = db.Exec(`CREATE TABLE msg_rules (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT
,prio SMALLINT NOT NULL ,prio SMALLINT NOT NULL