-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.rb
60 lines (49 loc) · 1.38 KB
/
app.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
48
49
50
51
52
53
54
55
56
57
58
59
60
# frozen_string_literal: true
require "sentry_raven_without_integrations"
require "optparse"
require "./app/tflbot"
module RufusRavenSupport
def on_error(job, err)
Raven.capture_exception(err, extra: { "job": job })
super
end
end
# We have to monkey patch the rufus scheduler to support sentry because there's
# no direct way to override the default exception handler.
module Rufus
class Scheduler
prepend RufusRavenSupport
end
end
def parse_opts!
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: app.rb [options]"
opts.on("-cCONFIG_PATH", "--config=CONFIG_PATH", "Specify a config file") do |v|
options[:config] = v
end
end.parse!
options
end
def run
cmd_opts = parse_opts!
bot = Bot::LondonBot.new(
config_path: cmd_opts[:config] || Bot::LondonBot::DEFAULT_CONFIG_PATH,
)
begin
bot.run!
rescue SignalException
# Best effort attempt at sending a close-frame to discord. API calls might
# not be confirmed without a close frame, resulting in unexpected behaviour.
# See discussion on https://github.com/meew0/discordrb/pull/251#issuecomment-254053322
# for more details.
bot.stop!
$stdout.puts "So long and thanks for all the fish."
exit! true
# rubocop:disable Lint/RescueException
rescue Exception => e
Raven.capture_exception(e)
end
# rubocop:enable Lint/RescueException
end
run