forked from woodruffw/yossarian-bot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
yossarian-bot.rb
103 lines (86 loc) · 2.86 KB
/
yossarian-bot.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# frozen_string_literal: true
# -*- coding: utf-8 -*-
# yossarian-bot.rb
# Author: William Woodruff
# ------------------------
# A call-and-response IRC bot for entertainment.
# ------------------------
# This code is licensed by William Woodruff under the MIT License.
# http://opensource.org/licenses/MIT
require "set"
require "cinch"
require "cinch/plugins/identify"
require "yaml"
Dir[File.dirname(__FILE__) + "/extend/**/*.rb"].each do |extension|
require extension
end
Dir[File.dirname(__FILE__) + "/plugins/**/*.rb"].each do |plugin|
require plugin
end
config_file = File.expand_path(File.join(File.dirname(__FILE__), "config.yml"))
version_file = File.expand_path(File.join(File.dirname(__FILE__), "version.yml"))
plugins_file = File.expand_path(File.join(File.dirname(__FILE__), "plugins.yml"))
server_threads = []
if File.file?(config_file) && File.file?(version_file) && File.file?(plugins_file)
config = YAML.load_file(config_file)
version = YAML.load_file(version_file)
plugins = YAML.load_file(plugins_file)["plugins"]
else
abort("Fatal: Missing one of: config.yml, version.yml, plugins.yml.")
end
config["servers"].each do |server_name, server_info|
server_threads << Thread.new do
Cinch::Bot.new do
@starttime = Time.now
@version = version
@admins = server_info["admins"] || []
@blacklist = server_info["blacklist"]&.to_set || Set.new
@all_plugins = plugins.map do |plugin|
Object.const_get(plugin)
end
# rubocop:disable Style/TrivialAccessors
def starttime
@starttime
end
def version
@version
end
def admins
@admins
end
def blacklist
@blacklist
end
def all_plugins
@all_plugins
end
# rubocop:enable Style/TrivialAccessors
configure do |conf|
conf.nick = server_info["nick"] || "yossarian-bot"
conf.realname = "yossarian-bot"
conf.user = "yossarian-bot"
conf.max_messages = 1
conf.server = server_name
conf.channels = server_info["channels"]
conf.port = server_info["port"] || 6667
conf.ssl.use = server_info["ssl"] || false
conf.plugins.prefix = Regexp.new(server_info["prefix"] || /^!/)
conf.plugins.plugins = @all_plugins.dup
conf.plugins.plugins << Cinch::Plugins::Identify
ENV.update(config["environment"] || {})
if server_info.key?("auth")
conf.plugins.options[Cinch::Plugins::Identify] = {
type: server_info["auth"]["type"].to_sym,
password: server_info["auth"]["password"],
}
end
if server_info.key?("disabled_plugins")
server_info["disabled_plugins"].each do |plugin|
conf.plugins.plugins.delete(Object.const_get(plugin))
end
end
end
end.start
end
end
server_threads.each(&:join)