2023-05-20 03:45:54 -04:00
|
|
|
#frozen_string_literal: true
|
|
|
|
|
|
|
|
module DiscourseAi::AiBot::Commands
|
|
|
|
class TimeCommand < Command
|
|
|
|
class << self
|
|
|
|
def name
|
|
|
|
"time"
|
|
|
|
end
|
|
|
|
|
|
|
|
def desc
|
2023-06-21 03:10:30 -04:00
|
|
|
"Will generate the time in a timezone"
|
2023-05-20 03:45:54 -04:00
|
|
|
end
|
2023-06-19 18:45:31 -04:00
|
|
|
|
|
|
|
def parameters
|
|
|
|
[
|
|
|
|
Parameter.new(
|
|
|
|
name: "timezone",
|
2023-06-21 03:10:30 -04:00
|
|
|
description: "ALWAYS supply a Ruby compatible timezone",
|
2023-06-19 18:45:31 -04:00
|
|
|
type: "string",
|
|
|
|
required: true,
|
|
|
|
),
|
|
|
|
]
|
|
|
|
end
|
2023-05-20 03:45:54 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def result_name
|
|
|
|
"time"
|
|
|
|
end
|
|
|
|
|
|
|
|
def description_args
|
|
|
|
{ timezone: @last_timezone, time: @last_time }
|
|
|
|
end
|
|
|
|
|
2023-06-19 18:45:31 -04:00
|
|
|
def process(args)
|
|
|
|
timezone = JSON.parse(args)["timezone"]
|
|
|
|
|
2023-05-20 03:45:54 -04:00
|
|
|
time =
|
|
|
|
begin
|
|
|
|
Time.now.in_time_zone(timezone)
|
|
|
|
rescue StandardError
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
time = Time.now if !time
|
|
|
|
|
|
|
|
@last_timezone = timezone
|
|
|
|
@last_time = time.to_s
|
|
|
|
|
2023-06-21 03:10:30 -04:00
|
|
|
{ args: args, time: time.to_s }
|
2023-05-20 03:45:54 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|