-
Notifications
You must be signed in to change notification settings - Fork 5
/
chatbot.rb
54 lines (44 loc) · 1.49 KB
/
chatbot.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
require 'rubygems'
require 'cinch'
require 'cinch/plugins/identify'
require 'yaml'
begin
$settings = YAML.load(File.read("bot.yml"))
rescue
puts "create bot.yml and populate it with values. See the readme file!"
end
# This method is taken from rails core
# (didn't want to load the entire lib for one method)
# http://api.rubyonrails.org/classes/ActiveSupport/Inflector.html#method-i-constantize
def constantize(camel_cased_word)
names = camel_cased_word.split('::')
names.shift if names.empty? || names.first.empty?
constant = Object
names.each do |name|
constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
end
constant
end
$help_messages = []
$settings["settings"]["plugins"].each do |plugin|
require "./plugins/#{plugin}"
end
@irc = Cinch::Bot.new do
configure do |c|
c.server = "irc.freenode.org"
c.nick = $settings["settings"]["nick"]
c.channels = [$settings["settings"]["channel"]]
c.plugins.plugins = $settings["settings"]["cinch_plugins"]||[] +
$settings["settings"]["plugins"].map {|plugin| constantize(plugin.split("_").map {|word| word.capitalize}.join(""))}||[]
c.plugins.options[Cinch::Plugins::Identify] = {
:username => $settings['settings']['nick'],
:password => $settings['settings']['nickserv_pass'],
:type => :nickserv
}
end
on :message, /^!help/ do |m|
$help_messages.each{|message| m.user.send message }
end
end
Process.daemon(true)
@irc.start