-
Notifications
You must be signed in to change notification settings - Fork 0
/
scratchbot.rb
47 lines (38 loc) · 1.04 KB
/
scratchbot.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
require 'slack-ruby-bot'
require 'google_drive'
require './forecast.rb'
require 'dotenv/load'
SlackRubyBot::Client.logger.level = Logger::WARN
class ScratchBot < SlackRubyBot::Bot
help do
title 'Scratch'
desc 'shares current field forecast'
command 'forecast' do
long_desc 'shows, in Millions, the field commit in PCF Annual Contract Value for the current quarter'
end
end
command 'hi' do |client, data, match|
client.say(text: 'meow', channel: data.channel)
end
command 'forecast' do |client, data, match|
f = ForecastService.new.to_s
client.say(text: f, channel: data.channel)
end
command 'top' do |client, data, match|
f = ForecastService.new
client.say(text: f.top, channel: data.channel)
end
end
class ForecastService
def initialize
@session ||= GoogleDrive::Session.from_config("config.json")
@payload ||= @session.spreadsheet_by_url(ENV['FORECAST_URL'])
@forecast ||= Forecast.new(@payload)
end
def top
@forecast.top_twenty
end
def to_s
@forecast.to_s
end
end