Refactoring codes for more tg message types
This commit is contained in:
@@ -14,7 +14,10 @@ type QueryResult struct {
|
||||
Schedules *map[*BusStop]*BusStopBuses
|
||||
Lang string
|
||||
Error error
|
||||
Source *query.QueryMessage
|
||||
Query *query.QueryObject
|
||||
|
||||
isConsumed bool
|
||||
}
|
||||
|
||||
func writeShortRoute(lang *string, sb *strings.Builder, b *BusStop) {
|
||||
@@ -35,6 +38,10 @@ 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) Message() (string, error) {
|
||||
|
||||
if this.Error != nil {
|
||||
@@ -56,12 +63,41 @@ func (this QueryResult) Message() (string, error) {
|
||||
}
|
||||
|
||||
if q.Key == "" {
|
||||
sort.Sort(query.ByKey(*q.Results))
|
||||
for _, entry := range *q.Results {
|
||||
busStop := any(entry).(*BusStop)
|
||||
utils.WriteMDv2Text(&sb, busStop.RouteId)
|
||||
sb.WriteString(" ")
|
||||
writeShortRoute(&this.Lang, &sb, busStop)
|
||||
|
||||
loc := q.Message.Location
|
||||
if loc != nil {
|
||||
|
||||
// Print nearest bus stops
|
||||
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)
|
||||
d := busStop.Direction
|
||||
if d == "O" {
|
||||
sb.WriteString("↑")
|
||||
} else if d == "I" {
|
||||
sb.WriteString("↓")
|
||||
} else {
|
||||
sb.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")
|
||||
}
|
||||
|
||||
} else {
|
||||
sort.Sort(query.ByKey(*q.Results))
|
||||
for _, entry := range *q.Results {
|
||||
busStop := any(entry).(*BusStop)
|
||||
utils.WriteMDv2Text(&sb, busStop.RouteId)
|
||||
sb.WriteString(" ")
|
||||
writeShortRoute(&this.Lang, &sb, busStop)
|
||||
}
|
||||
}
|
||||
} else if 1 == len(*q.SearchTerms) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user