penguin/golifehk

@golifehk bot in Telegram

datasources/kmb/QueryResult.go

raw ยท 1099 bytes

package kmb

import (
    "strings"

    query "github.com/tgckpg/golifehk/query"
    utils "github.com/tgckpg/golifehk/utils"
)

type QueryResult struct {
    Lang string
    Error error
    Query *query.QueryObject
}

func ( this *QueryResult ) Message() ( string, error ) {

    if this.Error != nil {
        return "", this.Error
    }

    sb := strings.Builder{}

    if 0 < len( *this.Query.Results ) {
        // Print Stop Name, the print the list of routes
        if this.Query.Key == "" {
            for _, item := range *this.Query.Results {
                var b *BusStop
                b = any( item ).( *BusStop )

                if b.Routes == nil {
                    continue
                }

                utils.WriteMDv2Text( &sb, (*b.Name)[ this.Lang ] )
                sb.WriteString( "\n  " )
                for _, route := range *b.Routes {
                    utils.WriteMDv2Text( &sb, route.RouteId )
                    sb.WriteString( " " )
                }
                sb.WriteString( "\n" )
            }
        }
    }

    return sb.String(), nil
}