This commit is contained in:
shoopea 2019-10-11 12:00:25 +08:00
parent d849a5620d
commit 898846727a
2 changed files with 88 additions and 14 deletions

65
bot.go
View File

@ -46,13 +46,13 @@ func BotHandlers(b *tb.Bot) {
b.Handle("/clients", botGetClients)
b.Handle("/vault", botVaultHelp)
b.Handle("/vault_all", botVault)
b.Handle("/vault_res", botVault)
b.Handle("/vault_alch", botVault)
b.Handle("/vault_misc", botVault)
b.Handle("/vault_rec", botVault)
b.Handle("/vault_part", botVault)
b.Handle("/vault_other", botVault)
b.Handle("/vault_all", botVaultAll)
b.Handle("/vault_res", botVaultRes)
b.Handle("/vault_alch", botVaultAlch)
b.Handle("/vault_misc", botVaultMisc)
b.Handle("/vault_rec", botVaultRec)
b.Handle("/vault_part", botVaultPart)
b.Handle("/vault_other", botVaultOther)
b.Handle(tb.OnPhoto, botPhoto)
b.Handle(tb.OnChannelPost, botChannelPost)
@ -676,14 +676,51 @@ func botVaultHelp(m *tb.Message) {
TGCmdQueue <- c
}
func botVault(m *tb.Message) {
b, _ := json.Marshal(m)
log.Printf("botVault (msg) :\n%s\n", string(b))
for _, e := range m.Entities {
if e.Type == tb.EntityMention {
log.Printf("botVault (user) : %s\n", m.Text[e.Offset:e.Offset+e.Length])
func botVaultAll(m *tb.Message) {
l := []int64{objSubTypeItemResource, objSubTypeItemAlch, objSubTypeItemMisc, objSubTypeItemRecipe, objSubTypeItemPart, objSubTypeItemOther}
botVault(m, l)
}
func botVaultRes(m *tb.Message) {
l := []int64{objSubTypeItemResource}
botVault(m, l)
}
func botVaultAlch(m *tb.Message) {
l := []int64{objSubTypeItemAlch}
botVault(m, l)
}
func botVaultMisc(m *tb.Message) {
l := []int64{objSubTypeItemMisc}
botVault(m, l)
}
func botVaultRec(m *tb.Message) {
l := []int64{objSubTypeItemRecipe}
botVault(m, l)
}
func botVaultPart(m *tb.Message) {
l := []int64{objSubTypeItemPart}
botVault(m, l)
}
func botVaultOther(m *tb.Message) {
l := []int64{objSubTypeItemOther}
botVault(m, l)
}
func botVault(m *tb.Message, l []int64) {
/*
b, _ := json.Marshal(m)
log.Printf("botVault (msg) :\n%s\n", string(b))
for _, e := range m.Entities {
if e.Type == tb.EntityMention {
log.Printf("botVault (user) : %s\n", m.Text[e.Offset:e.Offset+e.Length])
}
}
}
*/
if !m.Private() {
return
}

37
sql.go
View File

@ -581,6 +581,43 @@ func initDB() {
failOnError(err, "initDB : populate table code_obj_sub_type")
log.Println("initDB : code_obj_sub_type populated ...")
_, err = db.Exec(`CREATE VIEW obj_msg_vault_v AS
SELECT x.sender_user_id user_id
,x.item_id
,(SELECT COALESCE(SUM(omix.quantity), 0)
FROM obj ox
,obj_msg omx
,obj_msg_item omix
WHERE ox.obj_sub_type_id = ` + strconv.Itoa(objSubTypeMessageGDepositAck) + `
AND omx.sender_user_id = x.sender_user_id
AND omx.obj_id = ox.id
AND omix.obj_id = ox.id
AND omix.item_id = x.item_id) deposit
,(SELECT coalesce(sum(omix.quantity), 0)
FROM obj ox
,obj_msg omx
,obj_msg_item omix
WHERE ox.obj_sub_type_id = ` + strconv.Itoa(objSubTypeMessageWithdrawRcv) + `
AND omx.sender_user_id = x.sender_user_id
AND omx.obj_id = ox.id
AND omix.obj_id = ox.id
AND omix.item_id = x.item_id) withdraw
FROM (SELECT DISTINCT
om.sender_user_id
,om.chat_id
,omi.item_id
FROM obj o
,obj_msg om
,obj_msg_item omi
WHERE o.id = om.obj_id
AND o.obj_type_id = ` + strconv.Itoa(objTypeMessage) + `
AND o.obj_sub_type_id in (` + strconv.Itoa(objSubTypeMessageWithdrawRcv) + `, ` + strconv.Itoa(objSubTypeMessageGDepositAck) + `)
AND omi.obj_id = o.id) x
ORDER BY x.sender_user_id ASC
,x.item_id ASC;`)
failOnError(err, "initDB : create view obj_msg_vault_v")
log.Println("initDB : obj_msg_vault_v created ...")
log.Println("initDB : Database set up")
}