This repository has been archived by the owner on Jun 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.ru
76 lines (61 loc) · 1.53 KB
/
config.ru
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
require 'bundler'
Bundler.require :default, (ENV['RACK_ENV'] || 'production').to_sym
module Caskbot
class << self
extend Memoist
attr_accessor :bot
def github
stack = Faraday::RackBuilder.new do |builder|
builder.use Faraday::HttpCache
builder.use Octokit::Response::RaiseError
builder.adapter Faraday.default_adapter
end
Octokit.middleware = stack
Octokit::Client.new access_token: ENV['GITHUB_TOKEN']
end
def config
c = Hashie::Mash.new
ENV.each { |k,v| c[k.downcase] = v }
return c
end
def mainchan
Caskbot.bot.channel_list.find ENV['IRC_CHANNELS'].split.first
end
def root
__dir__
end
def template(file)
Tilt.new(root + '/templates/' + file + '.hbs')
end
def shorten(url)
begin
GitIo.shorten url
rescue
url
end
end
def gisten(filename, contents, opts = {})
opts[:filename] ||= filename
opts[:public] ||= false
opts[:anonymous] ||= true
Caskbot.shorten Gist.gist(contents, opts)['html_url']
end
memoize :config, :gisten, :github, :root, :shorten, :template
end
module Plugins
def self.to_a
self.constants.map { |c| self.const_get c }
end
end
module Hookins
def self.to_a
self.constants.map { |c| self.const_get c }
end
end
end
Dir['./hookins/*.rb'].each { |p| require p }
Dir['./plugins/*.rb'].each { |p| require p }
require './bot'
require './web'
Thread.new { Caskbot.bot.start }
run Caskbot::Web