This repository has been archived by the owner on Aug 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
bot.rb
165 lines (144 loc) · 4.62 KB
/
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# Chewbotcca IRC Bot
# Require Gems needed to run programs and plugins
require './requiregems.rb'
# Load config from file
begin
CONFIG = YAML.load_file('config.yaml')
rescue StandardError
puts 'Config file not found, this is fatal, running setup.'
`ruby setup.rb`
exit
end
# Require each plugin
Dir["#{File.dirname(__FILE__)}/plugins/*.rb"].each { |file| require file }
# Set up uptime.
STARTTIME = Time.now
# Pre-Config
botnick = if CONFIG['nickname'] == '' || CONFIG['nickname'].nil?
puts 'The bot doesn\'t have a nickname! Please set one'
exit
else
CONFIG['nickname'].to_s
end
botserver = if CONFIG['server'] == '' || CONFIG['server'].nil?
puts 'You did not configure a server for the bot to connect to. Please set one!'
exit
else
CONFIG['server'].to_s
end
botport = if CONFIG['port'].nil?
'6667'
else
CONFIG['port']
end
botuser = if CONFIG['username'].nil? || CONFIG['username'] == ''
CONFIG['nickname']
else
CONFIG['username']
end
commits = `git rev-list master | wc -l`.to_i
commit = if commits.zero?
''
else
" | Version: #{commits}"
end
botrealname = if CONFIG['realname'].nil? || CONFIG['realname'] == ''
"Chewbotcca IRC Bot - https://git.io/ChewbotccaIRC#{commit}"
else
"#{CONFIG['realname']} - https://git.io/ChewbotccaIRC#{commit}"
end
botssl = if CONFIG['ssl'].nil? || CONFIG['ssl'] == '' || CONFIG['ssl'] == 'false' || CONFIG['ssl'] == false
nil
else
'true'
end
botserverpass = if CONFIG['serverpass'].nil? || CONFIG['serverpass'] == ''
nil
else
CONFIG['serverpass']
end
if CONFIG['prefix'].nil? || CONFIG['prefix'] == ''
CONFIG['prefix'] = '!'
File.open('config.yaml', 'w') { |f| f.write CONFIG.to_yaml }
end
botprefix = if CONFIG['prefixstart'].nil? || CONFIG['prefixstart'] == '' || CONFIG['prefixstart'] == 'true' || CONFIG['prefixstart'] == true
/^#{Regexp.quote(CONFIG['prefix'])}/
else
/#{Regexp.quote(CONFIG['prefix'])}/
end
# Configure the Bot
bot = Cinch::Bot.new do
configure do |c|
# Bot Settings, Taken from pre-config
c.nick = botnick
c.server = botserver
c.channels = [CONFIG['channels']]
c.port = botport
c.user = botuser
c.realname = botrealname
c.messages_per_second = 5
c.ssl.use = botssl
c.password = botserverpass
c.plugins.prefix = botprefix
plugincount = Dir.glob(File.join('plugins', '**', '*.rb')).select { |file| File.file?(file) }.count
pluginlist = Array.new(plugincount)
x = 0
Dir["#{File.dirname(__FILE__)}/plugins/*.rb"].each do |wow|
bob = File.readlines(wow) { |line| line.split.map(&:to_s).join }
command = bob[0][6..bob[0].length]
command.delete!("\n")
command = Object.const_get(command)
pluginlist[x] = command
x += 1
end
# Load modules.
c.plugins.plugins = pluginlist
end
end
def authenticate(m)
name = m.user.name
stafffile = "data/staff/#{name}.yaml"
return false unless File.exist?(stafffile)
staffdata = YAML.load_file(stafffile)
authtype = staffdata['authtype']
if authtype == 'host'
return true if staffdata['host'] == m.user.host
end
if authtype == 'username'
return true if staffdata['user'] == m.user.user
end
if authtype == 'nickname'
return true if staffdata['nick'] == m.user.nick
end
if authtype == 'userhost'
return true if staffdata['user'] == m.user.user && staffdata['host'] == m.user.host
end
if authtype == 'all'
return true if staffdata['user'] == m.user.user && staffdata['host'] == m.user.host && staffdata['nick'] == m.user.nick
end
false
end
def checkperm(_m, user, perm)
stafffile = "data/staff/#{user}.yaml"
return unless File.exist?(stafffile)
staffdata = YAML.load_file(stafffile)
return true if staffdata['all'] == true
return true if staffdata[perm] == true
false
end
def checkchan(_m, chan, setting)
chan = chan.to_s[1..chan.to_s.length]
channelfile = "data/channels/#{chan}.yaml"
unless File.exist?(channelfile)
File.new(channelfile, 'w+')
exconfig = YAML.load_file('data/channels/channel.example.yaml')
exconfig['name'] = channel
File.open(channelfile, 'w') { |f| f.write exconfig.to_yaml }
end
data = false
data = YAML.load_file(channelfile) while data == false
return true if data[setting] == 'true'
false
end
# START THE BOT
bot.start