2024-01-04 08:44:07 -05:00
|
|
|
#frozen_string_literal: true
|
|
|
|
|
|
|
|
module DiscourseAi
|
|
|
|
module AiBot
|
|
|
|
module Tools
|
|
|
|
class Time < Tool
|
|
|
|
def self.signature
|
|
|
|
{
|
|
|
|
name: name,
|
|
|
|
description: "Will generate the time in a timezone",
|
|
|
|
parameters: [
|
|
|
|
{
|
|
|
|
name: "timezone",
|
|
|
|
description: "ALWAYS supply a Ruby compatible timezone",
|
|
|
|
type: "string",
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.name
|
|
|
|
"time"
|
|
|
|
end
|
|
|
|
|
|
|
|
def timezone
|
|
|
|
parameters[:timezone].to_s
|
|
|
|
end
|
|
|
|
|
2024-05-07 07:55:46 -04:00
|
|
|
def invoke
|
2024-01-04 08:44:07 -05:00
|
|
|
time =
|
|
|
|
begin
|
|
|
|
::Time.now.in_time_zone(timezone)
|
|
|
|
rescue StandardError
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
time = ::Time.now if !time
|
|
|
|
|
|
|
|
@last_time = time.to_s
|
|
|
|
|
|
|
|
{ args: { timezone: timezone }, time: time.to_s }
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def description_args
|
|
|
|
{ timezone: timezone, time: @last_time }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|