Class: TickingAway::Bot
- Inherits:
-
Object
- Object
- TickingAway::Bot
- Defined in:
- lib/ticking_away/bot.rb
Constant Summary collapse
- TIMEAT_CMD =
'!timeat '.freeze
- TIMEPOPULARITY_CMD =
'!timepopularity '.freeze
- DEFAULT_TIME_API =
'http://worldtimeapi.org/api'.freeze
- EXCUSES =
[ 'Time is an illusion', 'What is time, really?', 'The linear progression of time is currently on hold' ].freeze
Instance Attribute Summary collapse
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
-
#time_api ⇒ Object
readonly
Returns the value of attribute time_api.
Instance Method Summary collapse
-
#chat(msg) ⇒ Object
Send a string to the Bot in the format of <user_name>: <message> or just <message> Only !timeat <tz_info> and !timepopularity <tz_info or prefix> commands will return a string response.
-
#initialize(storage: nil, time_api: nil) ⇒ Bot
constructor
Allow the caller to pass in the storage method via primitive DI.
-
#stat_check(msg) ⇒ Object
Return the statistic for the provided tz_info or prefix.
-
#time_check(msg) ⇒ Object
Check time for the timezone provided against the provided time api.
Constructor Details
#initialize(storage: nil, time_api: nil) ⇒ Bot
Allow the caller to pass in the storage method via primitive DI. Other storage methods must implement increment_stat(<tz_info>) and get_stat(<tz_info or prefix>)
17 18 19 20 |
# File 'lib/ticking_away/bot.rb', line 17 def initialize(storage: nil, time_api: nil) @storage = storage || TickingAway::JSONFileStorage.new @time_api = ENV['TIME_API'] || time_api || DEFAULT_TIME_API end |
Instance Attribute Details
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
12 13 14 |
# File 'lib/ticking_away/bot.rb', line 12 def storage @storage end |
#time_api ⇒ Object (readonly)
Returns the value of attribute time_api.
12 13 14 |
# File 'lib/ticking_away/bot.rb', line 12 def time_api @time_api end |
Instance Method Details
#chat(msg) ⇒ Object
Send a string to the Bot in the format of <user_name>: <message> or just <message> Only !timeat <tz_info> and !timepopularity <tz_info or prefix> commands will return a string response
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ticking_away/bot.rb', line 26 def chat(msg) = strip_username(msg) case .partition(' ')[0] when TIMEAT_CMD.strip time_check() when TIMEPOPULARITY_CMD.strip stat_check() end end |
#stat_check(msg) ⇒ Object
Return the statistic for the provided tz_info or prefix
48 49 50 |
# File 'lib/ticking_away/bot.rb', line 48 def stat_check(msg) storage.get_stat((msg, TIMEPOPULARITY_CMD.length)) end |
#time_check(msg) ⇒ Object
Check time for the timezone provided against the provided time api.
39 40 41 42 43 44 45 |
# File 'lib/ticking_away/bot.rb', line 39 def time_check(msg) tz_info = (msg, TIMEAT_CMD.length) puts "Event: Checking Time for timezone: #{tz_info}" (tz_info) end |