Skip to content

Instantly share code, notes, and snippets.

@mattbailey
Created January 7, 2013 03:58
Show Gist options
  • Save mattbailey/4472183 to your computer and use it in GitHub Desktop.
Save mattbailey/4472183 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'rubygems'
require 'redis'
require 'RMagick'
require 'sqlite3'
require 'time'
require 'eaal'
ENV['REDIS_HOST'] = 'localhost' unless ENV['REDIS_HOST']
ENV['REDIS_PORT'] = '6379' unless ENV['REDIS_PORT']
ENV['REDIS_PASS'] = nil unless ENV['REDIS_PASS']
$redis = Redis.new(:host => ENV['REDIS_HOST'], :port => ENV['REDIS_PORT'], :password => ENV['REDIS_PASS'])
def weechat_init
Weechat.register("bigscript", "ribo", "1.0", "GPL3", "ermagherd all the scripts", "", "")
Weechat.hook_print "", "", ".aaf", 1, "aaf", ""
Weechat.hook_print "", "", ".eve", 1, "eve", ""
Weechat.hook_print "", "", ".cc", 1, "charlie", ""
Weechat.hook_print "", "", ".ymf", 1, "ymf", ""
return Weechat::WEECHAT_RC_OK
end
$api = EAAL::API.new(nil,nil)
def seconds_to_units(seconds)
'%d days, %d hours, %d minutes, %d seconds' %
# the .reverse lets us put the larger units first for readability
[24,60,60].reverse.inject([seconds]) {|result, unitsize|
result[0,0] = result.shift.divmod(unitsize)
result
}
end
def findskillname(typeid)
$api.scope = 'eve'
$api.SkillTree.skillGroups.each do |group|
group.container['skills'].each do |skill|
group.container['skills'].each do |skill|
if skill.typeID == typeid
return skill.typeName
end
end
end
end
end
def training(charid, id, vcode)
$api.keyid = id
$api.vcode = vcode
$api.scope = 'char'
cache = $api.SkillInTraining(:characterID => charid)
if cache.skillInTraining == "1"
skill = findskillname(cache.trainingTypeID)
level = cache.trainingToLevel
finish = seconds_to_units(Time.parse(cache.trainingEndTime) - Time.now)
else
skill = nil
level = nil
finish = nil
end
return {
:skill => skill,
:level => level,
:finish => finish
}
end
def getchars(keylist)
characters = Array.new
keylist.each do |vcode|
$api.keyid = vcode[:id]
$api.vcode = vcode[:vcode]
$api.scope = 'account'
$api.Characters.characters.each do |character|
characters << {
:id => vcode[:id],
:vcode => vcode[:vcode],
:name => character.name,
:characterID => character.characterID
}
end
end
return characters
end
$redis = Redis.new
def eve(data,buffer,time,tags,displayed,highlight,prefix,message)
@user = Array.new
$redis.smembers("weechat:eve:user:#{message.gsub('.eve ','')}").each do |auth|
@user << eval(auth)
end
getchars(@user).each do |character|
skill = training(character[:characterID], character[:id], character[:vcode])
if skill[:skill] != nil
Weechat.command(buffer, "#{character[:name]} - #{skill[:skill]} #{skill[:level]} - #{skill[:finish]}")
end
end
return Weechat::WEECHAT_RC_OK
end
def aaf(data,buffer,time,tags,displayed,highlight,prefix,message)
aaf = ''
while aaf == '' || aaf.lines.count > 10
aaf = `/usr/games/fortune ~/.weechat/aaf`
end
Weechat.command(buffer, aaf)
return Weechat::WEECHAT_RC_OK
end
def charlie(data,buffer,time,tags,displayed,highlight,prefix,message)
db = SQLite3::Database.open "/home/mbailey/.weechat/chan.sqlite"
r = Random.new
cc = db.get_first_value "SELECT quote FROM quotes WHERE num = #{r.rand(1...600)}"
Weechat.command(buffer, cc + " - Charlie Chan")
return Weechat::WEECHAT_RC_OK
end
def ymf(data,buffer,time,tags,displayed,highlight,prefix,message)
filename = "#{(0...8).map{65.+(rand(26)).chr}.join.downcase}.jpg"
url = "https://mdb.io/ymf/#{filename}"
image = Magick::Image.read('/var/www/ymf.jpg').first
captioned = Magick::Draw.new
string = message.gsub('.ymf ', '')
captioned.annotate(image, 0,0,0,0, string) {
self.font = '/var/www/ymf/Impact.ttf'
self.pointsize = 68
self.gravity = Magick::NorthGravity
self.stroke = 'white'
self.stroke_width = 2
self.fill = 'black'
}
image.write("/var/www/ymf/#{filename}")
Weechat.command(buffer, url)
return Weechat::WEECHAT_RC_OK
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment