Can now accept location
This commit is contained in:
@@ -18,6 +18,8 @@ type QueryResult struct {
|
||||
Query *query.QueryObject
|
||||
|
||||
isConsumed bool
|
||||
dataType string
|
||||
tableData [][]query.TableCell
|
||||
}
|
||||
|
||||
func writeShortRoute(lang *string, sb *strings.Builder, b *BusStop) {
|
||||
@@ -38,11 +40,13 @@ func writeShortRoute(lang *string, sb *strings.Builder, b *BusStop) {
|
||||
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) {
|
||||
func (this *QueryResult) Message() (string, error) {
|
||||
|
||||
this.dataType = "PlainText"
|
||||
|
||||
if this.Error != nil {
|
||||
return "", this.Error
|
||||
@@ -67,29 +71,40 @@ func (this QueryResult) Message() (string, error) {
|
||||
loc := q.Message.Location
|
||||
if loc != nil {
|
||||
|
||||
// Print nearest bus stops
|
||||
this.dataType = "Table"
|
||||
sb.WriteString("K巴 100m")
|
||||
|
||||
table := [][]query.TableCell{}
|
||||
|
||||
for _, entry := range *q.Results {
|
||||
busStop := any(entry).(*BusStop)
|
||||
|
||||
utils.WriteMDv2Text(&sb, fmt.Sprintf("%.2fm", busStop.Dist(loc.Lat(), loc.Lon())))
|
||||
sb.WriteString(" ")
|
||||
sb.WriteString(" [")
|
||||
utils.WriteMDv2Text(&sb, busStop.RouteId)
|
||||
sb_i := strings.Builder{}
|
||||
sb_i.WriteString(fmt.Sprintf("%.2fm", busStop.Dist(loc.Lat(), loc.Lon())))
|
||||
sb_i.WriteString(" ")
|
||||
utils.WriteMDv2Text(&sb_i, busStop.RouteId)
|
||||
d := busStop.Direction
|
||||
if d == "O" {
|
||||
sb.WriteString("↑")
|
||||
sb_i.WriteString("↑")
|
||||
} else if d == "I" {
|
||||
sb.WriteString("↓")
|
||||
sb_i.WriteString("↓")
|
||||
} else {
|
||||
sb.WriteString("\\?")
|
||||
sb_i.WriteString("\\?")
|
||||
}
|
||||
utils.WriteMDv2Text(&sb, (*busStop.Name)[this.Lang])
|
||||
utils.WriteMDv2Text(&sb, busStop.RouteId)
|
||||
utils.WriteMDv2Text(&sb, (*busStop.Name)[this.Lang])
|
||||
sb.WriteString(")")
|
||||
sb.WriteString("\n")
|
||||
sb_i.WriteString(" ")
|
||||
utils.WriteMDv2Text(&sb_i, (*busStop.Name)[this.Lang])
|
||||
|
||||
row := []query.TableCell{
|
||||
query.TableCell{
|
||||
Name: sb_i.String(),
|
||||
Value: fmt.Sprintf("%s %s", busStop.RouteId, (*busStop.Name)[this.Lang]),
|
||||
},
|
||||
}
|
||||
|
||||
table = append(table, row)
|
||||
}
|
||||
|
||||
this.tableData = table
|
||||
} else {
|
||||
sort.Sort(query.ByKey(*q.Results))
|
||||
for _, entry := range *q.Results {
|
||||
|
||||
Reference in New Issue
Block a user