Created
November 11, 2015 06:20
-
-
Save hikilaka/db173587a1aeddae5980 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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