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},
})
if err != nil {
log.Fatal(err)
return
}
failOnError(err, "StartBot")
b.Handle("/hello", botHello)
b.Handle("/rescan_msg", botRescanMsg)
b.Handle(tb.OnPhoto, botPhoto)
b.Handle(tb.OnChannelPost, botChannelPost)
b.Handle(tb.OnQuery, botQuery)
@ -34,12 +32,14 @@ func StartBot() {
}
func botPhoto(m *tb.Message) {
fmt.Println("OnPhoto :", m.Text)
fmt.Println("botPhoto :", m.Text)
// photos only
}
func botHello(m *tb.Message) {
fmt.Println("botHello :", m.Text)
if !m.Private() {
fmt.Println("botHello : !m.Private()")
return
}
// fmt.Println("Hello payload :", m.Payload) // <PAYLOAD>
@ -48,18 +48,30 @@ func botHello(m *tb.Message) {
}
func botChannelPost(m *tb.Message) {
fmt.Println("OnChannelPost :", m.Text)
fmt.Println("botChannelPost :", m.Text)
PrintText(m)
// channel posts only
}
func botQuery(q *tb.Query) {
fmt.Println("Query ?")
fmt.Println("botQuery")
// incoming inline queries
}
func botText(m *tb.Message) {
fmt.Println("botText :", m.Text)
PrintText(m)
// all the text messages that weren't
// 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
objSubTypeMessageTributeAck = 315
objSubTypeMessageAuctionAnnounce = 316
objSubTypeMessageAuctionUpdReq = 317
objSubTypeMessageAcutionUpdAck = 318
objSubTypeMessageTime = 317
objSubTypeJobPillage = 601
objSubTypeJobTribute = 602

16
sql.go
View File

@ -155,6 +155,22 @@ func initDB() {
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci;`)
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 (
id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT
,prio SMALLINT NOT NULL