Skip to content

Instantly share code, notes, and snippets.

@hikilaka
Created November 11, 2015 06:20
Show Gist options
  • Save hikilaka/db173587a1aeddae5980 to your computer and use it in GitHub Desktop.
Save hikilaka/db173587a1aeddae5980 to your computer and use it in GitHub Desktop.
require 'cinch'
require 'nokogiri'
require 'open-uri'
class FML
include Cinch::Plugin
match /fml/
def initialize(*args)
super
@cache = []
@timer = Time.at(0)
self.load_fml
end
def load_fml
page = Nokogiri::HTML(open('http://www.fmylife.com/random'))
page.css("div[class='post article']").each do |article|
lines = article.css("a[class='fmllink']");
@cache.push(lines.map {|line| line = line.text}.join(''))
end
end
def execute(m)
current = Time.new
if (current - @timer) >= 3
@timer = current
m.reply @cache.pop
self.load_fml if @cache.length == 0
else
m.user.send('FML requests can only be sent every 3 seconds')
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment