This repository has been archived by the owner on May 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathelfari.rb
269 lines (240 loc) · 7.94 KB
/
elfari.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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#
# Needs rubygems and cinch:
#
# sudo apt-get install rubygems
# gem install cinch
# gem install rest-client
#
$: << File.dirname(__FILE__) + "/modules"
require 'rubygems'
require 'webee'
require 'cinch'
require 'yaml'
require 'rest-client'
require 'alchemist'
require 'rufus/scheduler'
require 'abiquo-deployer'
require 'uri'
#$SAFE = 4
module ElFari
class Config
def self.config
YAML.load_file(File.expand_path(File.dirname(__FILE__)) + '/config.yml')
end
end
end
class Motherfuckers
include Cinch::Plugin
timer 900, method: :say
def say
ElFari::Config.config[:channels].each do |c|
Channel(c.split.first).send "Any news, motherfuckers?"
end
end
end
class GitDude
include Cinch::Plugin
timer 5, method: :new_stuff
def new_stuff
conf = ElFari::Config.config[:gitdude]
conf[:repos].each do |r|
next if not File.directory?(r[:path])
ENV['GIT_DIR'] = r[:path] + '/.git'
changes = []
`git fetch -v 2>&1 | grep -F -- '->'`.each_line do |l|
if l =~ /.*\.\..*/
changes << l
end
end
changes.each do |l|
tokens = l.split
commit_range = tokens[0]
branch_name = tokens[1]
commit_messages = `git log #{commit_range} --pretty=format:'%s (%an)'`
ElFari::Config.config[:channels].each do |c|
commit_messages.each_line do |l|
Channel(c.split.first).send "* [#{r[:name]}] #{l}\n\n"
end
end
end
end
end
end
if RUBY_VERSION =~ /1.9/
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8
end
conf = ElFari::Config.config
WeBee::Api.user = conf[:abiquo][:user]
WeBee::Api.password = conf[:abiquo][:password]
WeBee::Api.url = "http://#{conf[:abiquo][:host]}/api"
class ControlWS
def self.say(text, voice = :spanish)
if voice == :english
RestClient.post "http://bigdick.local:4567/say", :text => text, :voice => 'Alex'
else
RestClient.post "http://bigdick.local:4567/say", :text => text
end
end
end
bot = Cinch::Bot.new do
configure do |c|
c.server = conf[:server]
c.channels = conf[:channels]
c.nick = conf[:nick]
c.plugins.plugins = [Motherfuckers]
end
on :message, /ponmelo\s*(http:\/\/www\.youtube\.com.*)/ do |m, query|
RestClient.post "http://bigdick.local:4567/youtube", :url => query
title = RestClient.get('http://bigdick.local:4567/current_video')
while title.nil? or title.strip.chomp.empty?
title = RestClient.get('http://bigdick.local:4567/current_video')
end
m.reply "Tomalo, chato: #{title}"
end
on :message, /dimelo (.*)/ do |m, query|
RestClient.post "http://bigdick.local:4567/say", :text => query
end
on :message, /in-inglis (.*)/ do |m, query|
RestClient.post "http://bigdick.local:4567/say", :text => query, :voice => 'Alex'
end
on :message, /ayudame/ do |m|
m.reply 'Ahi van los comandos, chavalote!: ayudame dimelo ponmelo volumen mele in-inglis ponmeargo ponmeer quetiene'
end
on :message, /volumen (.*)/ do |m, query|
RestClient.post "http://bigdick.local:4567/volume", :vol => query
end
on :message, /mele/ do |m, query|
RestClient.post "http://bigdick.local:4567/video", :url => 'http://gobarbra.com/hit/new-0416a9aa8de56543b149d7ffb477196f'
m.reply "Paralo Paul!!!"
end
on :message, /vino/ do |m, query|
RestClient.post "http://bigdick.local:4567/video", :url => 'http://www.youtube.com/watch?v=-nQgsEbU9C4'
m.reply "Viva el vino!!!"
end
on :message, /ponme\s*argo\s*(.*)/ do |m, query|
db = File.readlines('database')
play = db[(rand * (db.size - 1)).to_i].split(/ /)[0]
RestClient.post "http://bigdick.local:4567/youtube", :url => play
title = RestClient.get('http://bigdick.local:4567/current_video')
while title.nil? or title.strip.chomp.empty?
title = RestClient.get('http://bigdick.local:4567/current_video')
end
m.reply "Tomalo, chato: #{title}"
end
on :message, /ponme\s*er\s*(.*)/ do |m, query|
db = File.readlines('database')
found = false
db.each do |line|
if line =~ /#{query}/i
play = line.split(/ /)[0]
RestClient.post "http://bigdick.local:4567/youtube", :url => play
title = RestClient.get('http://bigdick.local:4567/current_video')
while title.nil? or title.strip.chomp.empty?
title = RestClient.get('http://bigdick.local:4567/current_video')
end
m.reply "Tomalo, chato: #{title}"
found = true
break
end
end
RestClient.post "http://bigdick.local:4567/say", :text => "No tengo er #{query}" if !found
m.reply "No tengo er: #{query}" if !found
end
on :message, /que\s*tiene/ do |m, query|
db = File.readlines('database')
list = "Tengo esto piltrafa:\n"
i=1
db.each do |line|
f=line.split(/ - /)[0].length + 3
list += i.to_s() + " " + line[f..line.length]
i+=1
end
m.reply "#{list}"
end
on :message, /rimamelo (.*)/ do |m, query|
uri = "http://rimamelo.herokuapp.com/web/api?model.rhyme=#{URI.escape(query)}"
rhyme = RestClient.get(uri)
rhyme["<rhyme>"] = ""
rhyme["</rhyme>"] = ""
rhyme["<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"] = ""
m.reply "#{rhyme}"
RestClient.post "http://bigdick.local:4567/say", :text => "#{rhyme}"
end
on :message, /mothership abusers/ do |m, query|
abusers = {}
WeBee::Enterprise.all.each do |ent|
ent.users.each do |user|
vms = (user.virtual_machines.find_all{ |vm| vm.state == 'RUNNING'})
abusers[user.name] = { :full_name => "#{user.name} #{user.surname}", :email => user.email, :vms_number => vms.size, :vms => vms }
end
end
abusers = abusers.sort do |a,b|
a[1][:vms_number] <=> b[1][:vms_number]
end.reverse
m.reply "Running VMs, per user"
abusers.each do |a|
if a[1][:vms_number] > 0
m.reply "User: " + "#{a[1][:full_name]}".ljust(40) + "VMs: " + "#{a[1][:vms_number]}"
end
end
end
on :message, /mothership cloud-stats/ do |m, query|
stats = {
:free_hd => 0,
:real_hd => 0,
:used_hd => 0,
:hypervisors => 0,
:free_ram => 0,
:real_ram => 0,
:used_ram => 0,
:available_cpus => 0
}
WeBee::Datacenter.all.each do |dc|
dc.racks.each do |rack|
rack.machines.each do |m|
stats[:hypervisors] += 1
stats[:used_ram] += m.ram_used.to_i
stats[:real_ram] += m.real_ram.to_i
stats[:available_cpus] += m.real_cpu.to_i
stats[:used_hd] += m.hd_used.to_i.bytes.to.gigabytes.to_f.round
stats[:real_hd] += m.real_hd.to_i.bytes.to.gigabytes.to_f.round
end
end
end
stats[:free_ram] = stats[:real_ram] - stats[:used_ram]
stats[:free_hd] = stats[:real_hd] - stats[:used_hd]
m.reply 'Cloud Statistics for ' + conf[:abiquo][:host].upcase
m.reply "Hypevisors: #{stats[:hypervisors]}"
m.reply "Available CPUs: #{stats[:available_cpus]}"
m.reply "Total RAM: #{stats[:real_ram].megabytes.to.gigabytes} GB"
m.reply "Free RAM: #{stats[:free_ram].megabytes.to.gigabytes} GB"
m.reply "Used RAM: #{stats[:used_ram].megabytes.to.gigabytes} GB"
m.reply "Total HD: #{stats[:real_hd]} GB"
m.reply "Free HD: #{stats[:free_hd]} GB"
m.reply "Used HD: #{stats[:used_hd]} GB"
end
on :message, /!deploy (.*)/ do |m|
if not AbiquoDeployer.authorized?(m.user.nick)
m.reply "I'm sorry folk, you are not authorized to deploy"
else
AbiquoDeployer.client = m
AbiquoDeployer.deploy
end
end
on :message, /!list vms (.*)/ do |m, query|
#require 'pp'
AbiquoDeployer.list_vms(:host => query)
#m.reply "#{vm.name} #{vm.memory_size}"
#rescue Exception => e
# m.reply "** Error when talking to the hypervisor"
#end
end
#on :message, /eval (.*)/ do |m, query|
# begin
# rs = ControlWS
# eval query
# rescue SyntaxError
#end
end
bot.start