Can now accept location

This commit is contained in:
2026-03-08 15:38:28 +08:00
parent 912f9fd0ad
commit 33a7c04e09
12 changed files with 286 additions and 148 deletions

View File

@@ -17,6 +17,8 @@ type QueryResult struct {
Query *query.QueryObject
isConsumed bool
dataType string
tableData [][]query.TableCell
}
func writeRouteHead(sb *strings.Builder, r *RouteStop) {
@@ -50,12 +52,14 @@ func writeShortRoute(lang *string, sb *strings.Builder, r *RouteStop) {
sb.WriteString("\n")
}
func (this QueryResult) DataType() string { return "MarkdownV2" }
func (this QueryResult) Consumed() bool { return this.isConsumed }
func (this QueryResult) GetTableData() [][]map[string]string { return nil }
func (this QueryResult) DataType() string { return this.dataType }
func (this QueryResult) Consumed() bool { return this.isConsumed }
func (this QueryResult) GetTableData() [][]query.TableCell { return this.tableData }
func (this *QueryResult) Message() (string, error) {
this.dataType = "PlainText"
if this.Error != nil {
return "", this.Error
}
@@ -66,27 +70,61 @@ func (this *QueryResult) Message() (string, error) {
// Print Stop Names, then print the list of routes
if this.Query.Key == "" {
busStops := map[string]*BusStop{}
for _, item := range *this.Query.Results {
var r *RouteStop
r = any(item).(*RouteStop)
loc := this.Query.Message.Location
if loc != nil {
sb.WriteString("九巴 100m")
this.dataType = "Table"
b := r.BusStop
if b.Routes == nil {
continue
table := [][]query.TableCell{}
for _, item := range *this.Query.Results {
b := any(item).(*BusStop)
row := []query.TableCell{}
cell := query.TableCell{
Name: fmt.Sprintf("%.2fm %s", b.Dist(loc.Lat(), loc.Lon()), (*b.Name)[this.Lang]),
Value: fmt.Sprintf("%s", b.BusStopId),
}
row = append(row, cell)
for _, r := range *b.Routes {
sb_i := strings.Builder{}
writeRouteHead(&sb_i, r)
cell := query.TableCell{
Name: sb_i.String(),
Value: fmt.Sprintf("%s %s", r.RouteId, (*b.Name)[this.Lang]),
}
row = append(row, cell)
}
table = append(table, row)
}
this.tableData = table
} else {
busStops := map[string]*BusStop{}
for _, item := range *this.Query.Results {
var r *RouteStop
r = any(item).(*RouteStop)
b := r.BusStop
if b.Routes == nil {
continue
}
busStops[b.BusStopId] = b
}
busStops[b.BusStopId] = b
}
for _, b := range busStops {
utils.WriteMDv2Text(&sb, (*b.Name)[this.Lang])
sb.WriteString("\n ")
for _, route := range *b.Routes {
writeRouteHead(&sb, route)
sb.WriteString(" ")
for _, b := range busStops {
utils.WriteMDv2Text(&sb, (*b.Name)[this.Lang])
sb.WriteString("\n ")
for _, route := range *b.Routes {
writeRouteHead(&sb, route)
sb.WriteString(" ")
}
sb.WriteString("\n")
}
sb.WriteString("\n")
}
// We got a route key