Skip to main content

View Time

This command retrieves the time and weather of your city and displays it in a nice looking embed with a different image/color depending on time.

note

As you have to hardcode your time/weather/name currently this is more useful as a personal thing rather than something useful for a server.

Triggerā€‹

Type: Command
Trigger: time

Usageā€‹

  • -time - retrieves the time and weather of your city and displays it as an embed.

Configurationā€‹

  • $assets
    Colors and images to use for different times of the day. Should be quite self explanatory but each value in the dictionary corresponds to a time of day and contains an image and color decimal, which will be used for the embed.

  • šŸ“Œ $timezone
    Timezone database name (Area/City).

    tip

    You can use this tool to find your timezone database name (selected the Area/City option).

  • šŸ“Œ $name
    Name to use for the embed.

  • šŸ“Œ $location
    Your city name (used for retrieving the weather).

Codeā€‹

{{/*
Gets the time and weather of your city, and shows it in an embed with a different image / color depending on time.
See <https://yagpdb-cc.github.io/utilities/view-time> for more information.

Author: jo3-l <https://github.com/jo3-l>
*/}}

{{/* Configurable values */}}
{{ $assets := sdict
"morning" (sdict
"image" "https://www.bnrconvention.com/wp-content/uploads/2017/04/coffee-icon-1.png"
"color" 9498256
)
"afternoon" (sdict
"image" "https://www.bnrconvention.com/wp-content/uploads/2017/04/coffee-icon-1.png"
"color" 16747520
)
"evening" (sdict
"image" "https://cdn4.iconfinder.com/data/icons/outdoors-3/460/night-512.png"
"color" 8087790
)
"night" (sdict
"image" "https://cdn4.iconfinder.com/data/icons/outdoors-3/460/night-512.png"
"color" 1062054
)
}}
{{ $timezone := "America/Vancouver" }}
{{ $name := "Joe" }}
{{ $location := "Vancouver" }}
{{/* End of configurable values */}}

{{ $marker := "night" }}
{{ $output := exec "weather" $location }}
{{ $output = reReplace `\x60+` $output "" }}
{{ $res := split $output "\n" }}
{{ $weather := slice (index $res 3) 15 }}
{{ $temp := reReplace `\.\.` (reReplace ` \(.+$` (slice (index $res 4) 15) "") " - " }}

{{ $now := currentTime.In (newDate 0 0 0 0 0 0 $timezone).Location }}
{{ $hr := $now.Hour }}
{{ if and (ge $hr 5) (lt $hr 12) }} {{ $marker = "morning" }}
{{ else if and (ge $hr 12) (lt $hr 17) }} {{ $marker = "afternoon" }}
{{ else if and (ge $hr 17) (lt $hr 21) }} {{ $marker = "evening" }}
{{ end }}

{{ $asset := $assets.Get $marker }}
{{ $time := $now.Format "3:04:05 PM" }}
{{ $date := $now.Format "Monday, January 2, 2006" }}
{{ $embed := cembed
"title" (printf "Good %s, %s" $marker $name)
"color" $asset.color
"thumbnail" (sdict "url" $asset.image)
"description" (printf "āÆ **Time:** %s\nāÆ **Date:** %s\nāÆ **Weather:** %s (%s)" $time $date $weather $temp)
}}
{{ sendMessage nil $embed }}

Authorā€‹

This custom command was written by @jo3-l.