Refactoring codes for more tg message types

This commit is contained in:
2026-03-07 22:16:14 +08:00
parent a396a381b5
commit 912f9fd0ad
26 changed files with 771 additions and 472 deletions

View File

@@ -12,7 +12,8 @@ type CChar struct {
JyutPing *CJyutPing
DukJam *[]*DukJam
_JiDukJam *[]*CJyutPing
query.Searchable
query.Words
query.NoGeoLocation
}
type DukJam struct {
@@ -25,7 +26,8 @@ type CJyutPing struct {
SearchKey string // Searchable key
TungJamZi *[]*CChar
tSorted bool
query.Searchable
query.Words
query.NoGeoLocation
}
func (this *CJyutPing) Test(val string) bool {

View File

@@ -13,6 +13,9 @@ type QueryResult struct {
Lang string
Error error
Query *query.QueryObject
ResultType string
isConsumed bool
}
func writeCCharInfo(sb *strings.Builder, cc *CChar) {
@@ -37,14 +40,20 @@ func writeCCharInfo(sb *strings.Builder, cc *CChar) {
}
}
func (this QueryResult) DataType() string { return this.ResultType }
func (this QueryResult) Consumed() bool { return this.isConsumed }
func (this QueryResult) GetTableData() [][]map[string]string { return nil }
func (this QueryResult) Message() (string, error) {
this.ResultType = "PlainText"
if this.Error != nil {
return "", this.Error
}
if this.Query == nil {
panic("Query is nil")
return "", nil
}
sb := strings.Builder{}

View File

@@ -1,13 +1,16 @@
package cjlookup
import (
"fmt"
"strings"
"github.com/tgckpg/golifehk/query"
)
func Query(lang string, message string) query.IQueryResult {
func Query(q query.QueryMessage) query.IQueryResult {
lang := q.Lang
message := q.Text
var qResults *query.QueryObject
var err error
var searchables *[]query.ISearchable
@@ -17,9 +20,12 @@ func Query(lang string, message string) query.IQueryResult {
// Only look up jyut ping
if !strings.HasPrefix(messageU, "JP ") {
err = fmt.Errorf("Invalid query")
qr.ResultType = "IGNORE"
goto qrReturn
}
qr.isConsumed = true
if err != nil {
qr.Error = err
goto qrReturn
@@ -28,7 +34,7 @@ func Query(lang string, message string) query.IQueryResult {
messageU = messageU[3:]
searchables, err = getSearchables()
qResults, err = query.Parse(messageU, searchables)
qResults, err = query.MatchKeys(messageU, searchables)
qr.Query = qResults