penguin/golifehk

@golifehk bot in Telegram

datasources/kmb/QueryResult.go

raw · 1538 bytes

package kmb

import (
    "fmt"
    "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 )
                    if route.Direction == "O" {
                        sb.WriteString( "↑" )
                    } else if route.Direction == "I" {
                        sb.WriteString( "↓" )
                    }
                    if route.ServiceType != "1" {
                        utils.WriteMDv2Text( &sb, utils.ToPower( route.ServiceType ) )
                    }
                    sb.WriteString( " " )
                }
                sb.WriteString( "\n" )
            }
        }
        fmt.Print( this.Query.Key )
    } else {
    }

    return sb.String(), nil
}