Early telegram integrations
This commit is contained in:
@@ -37,7 +37,11 @@ func ( result QueryResult ) Message() string {
|
||||
sb.WriteString( "\n" )
|
||||
for _, bus := range buses.Buses {
|
||||
sb.WriteString( " * " )
|
||||
sb.WriteString( bus.ETAText )
|
||||
if bus.ETAText == "" {
|
||||
sb.WriteString( bus.ETDText )
|
||||
} else {
|
||||
sb.WriteString( bus.ETAText )
|
||||
}
|
||||
sb.WriteString( "\n" )
|
||||
}
|
||||
|
||||
|
@@ -10,6 +10,7 @@ import (
|
||||
type queryObj struct {
|
||||
Route string
|
||||
BusStops *[]BusStop
|
||||
Search string
|
||||
}
|
||||
|
||||
type qTerm struct {
|
||||
@@ -25,6 +26,11 @@ func Query( lang string, message string ) *QueryResult {
|
||||
}
|
||||
|
||||
if qo.Route != "" {
|
||||
|
||||
if len( *qo.BusStops ) == 0 {
|
||||
return &QueryResult{ Error: errors.New( "Result not found" ) }
|
||||
}
|
||||
|
||||
schedules, err := getSchedule( lang, qo.Route )
|
||||
if err != nil {
|
||||
return &QueryResult{ Error: err }
|
||||
@@ -54,9 +60,9 @@ func Query( lang string, message string ) *QueryResult {
|
||||
|
||||
func test( entry BusStop, val string ) bool {
|
||||
switch true {
|
||||
case strings.Contains( (*entry.Name)["zh"], val ):
|
||||
case strings.Contains( strings.ToUpper( (*entry.Name)["zh"] ), val ):
|
||||
fallthrough
|
||||
case strings.Contains( (*entry.Name)["en"], val ):
|
||||
case strings.Contains( strings.ToUpper( (*entry.Name)["en"] ), val ):
|
||||
return true
|
||||
}
|
||||
return false
|
||||
@@ -109,21 +115,24 @@ func parse( line string ) ( *queryObj, error ) {
|
||||
|
||||
// If route found, filter out all other route
|
||||
// then search within that route
|
||||
if route != "" && 0 < len( searches ) {
|
||||
matches_in := []BusStop{}
|
||||
for _, entry := range matches {
|
||||
if entry.RouteId != route {
|
||||
continue
|
||||
}
|
||||
if route != "" {
|
||||
if 0 < len( searches ) {
|
||||
matches_in := []BusStop{}
|
||||
for _, entry := range matches {
|
||||
if entry.RouteId != route {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, val := range searches {
|
||||
if test( entry, val ) {
|
||||
matches_in = append( matches_in, entry )
|
||||
break
|
||||
for _, val := range searches {
|
||||
if test( entry, val ) {
|
||||
matches_in = append( matches_in, entry )
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
matches = matches_in
|
||||
} else {
|
||||
}
|
||||
matches = matches_in
|
||||
}
|
||||
|
||||
return &queryObj{ Route: route, BusStops: &matches }, err
|
||||
|
Reference in New Issue
Block a user