-
Notifications
You must be signed in to change notification settings - Fork 0
/
minion.rb
69 lines (57 loc) · 1.88 KB
/
minion.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
61
62
63
64
65
66
67
68
69
require 'rubygems'
require 'cinch'
require 'cinch/plugins/identify'
require 'yaml'
require 'mechanize'
def random_name
agent = Mechanize.new
page = agent.get('http://www.rinkworks.com/namegen/')
form = page.forms[1]
form.c = "<<s|ss>|<VC|vC|B|BVs|Vs>><v|V|v|<v(l|n|r)|vc>>(th)"
res = form.submit
names = res.body.scan(/\<td\>(\w+)\<\/td\>/)
names[rand(names.length)].first
end
begin
nick = random_name
$settings = YAML.load(File.read("minion.yml"))
$settings["settings"]["channel"] = [ARGV.first]
$settings["settings"]["nick"] = nick
end
$master = $settings["settings"]["master"]
# 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 = []
if $settings["settings"]["abilities"]
$settings["settings"]["abilities"].each do |plugin|
require "./abilities/#{plugin}"
end
end
$irc = Cinch::Bot.new do
configure do |c|
c.server = "irc.freenode.com"
c.nick = $settings["settings"]["nick"]
c.channels = $settings["settings"]["channel"]
c.plugins.plugins = $settings["settings"]["plugins"].map {|plugin| constantize(plugin.split("_").map {|word| word.capitalize}.join(""))} if $settings["settings"]["plugins"]
end
on :message, /^!unsummon( #{$settings["settings"]["nick"]})?$/ do |m|
if m.user == User($master)
$irc.quit
system("exit")
end
end
on :message, /^!whois #{$settings['settings']['nick']}\s*/ do |m|
m.reply "#{m.user.nick}: I am #{$settings['settings']['bot_master']}'s minion."
end
end
$irc.start