Created
June 1, 2011 13:29
-
-
Save rbarfoed/1002294 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
#!/usr/bin/env ruby -KU | |
require 'cinch' | |
require 'iconv' | |
require_relative 'quote' | |
require_relative 'seen' | |
bot = Cinch::Bot.new do | |
configure do |c| | |
c.server = "irc.freenode.org" | |
c.nick = "xxxx" | |
c.channels = ["#xxx"] | |
@qs = Quotes.new | |
@users = {} | |
end | |
helpers do | |
def random_quote() | |
@qs.random_quote | |
end | |
def related_quote(text) | |
@qs.related_quote(text) | |
end | |
def conv(text) | |
Iconv.iconv('utf-8', 'latin1',text)[0] | |
end | |
end | |
on :message, /dolph/i do |m, who, text| | |
m.reply conv(random_quote['quote']) | |
end | |
on :message, /!reload/ do |m, who, text| | |
if 'barfoed' == m.user.nick | |
synchronize(:quotes_reload) do | |
m.reply "Dumping.." | |
@qs.reload | |
end | |
end | |
end | |
on :channel do |m| | |
if (rep = related_quote(m.message.downcase) ) | |
m.reply conv(rep['quote']) | |
end | |
end | |
on :channel do |m| | |
@users[m.user.nick] = Seen.new(m.user.nick, m.channel, m.message, Time.new) | |
end | |
on :channel, /^!seen (.+)/ do |m, nick| | |
if nick == bot.nick | |
m.reply "Jeg er Dolph!" | |
elsif nick == m.user.nick | |
m.reply "Du er svag selvom du er her!" | |
elsif @users.key?(nick) | |
m.reply @users[nick].to_s | |
else | |
m.reply "#{nick} har gemt sig og det svage mobel!" | |
end | |
end | |
end | |
bot.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment