Skip to content

Commit

Permalink
initial commit first commands
Browse files Browse the repository at this point in the history
  • Loading branch information
timrombergjakobsson committed Mar 15, 2012
0 parents commit 10da8ad
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
A simple irc bot in Ruby...
Nothing much yet more to come...
54 changes: 54 additions & 0 deletions bot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'cinch'

class Bot

COMMANDS = {}

bot = Cinch::Bot.new do
configure do |c|
c.server = "irc.quakenet.org"
c.nick = "Botio"
c.channels = ["#ad09"]
end

on :message, "hello" do | m |
m.reply "Hello, #{m.user.nick}"
end

on :message, "what's up" do | m |
m.reply "Nothing whats up with you?!"
end

on :message, /\?/ do |m|
unless @users.key? m.user.nick.to_sym
m.channel.send "#{m.user.nick}: Thanks for asking a question! You can also get help here: http://timromberg.se"
seen = Seen.new(m.user.nick)
seen.save
@users[m.user.nick.to_sym] = true
end
qr = Question.new(m.user.nick, m.message, Time.new)
qr.save
m.channel.send "#{m.user.nick}: your question has been recorded."
end

on :channel, /^!question (.+)/ do |m, nick|
if nick == bot.nick
m.reply "That's me!"
elsif @users.key?(nick.to_sym)
m.reply "The last 5 questions by #{nick} are:"
Question.find_for_nick(nick).each do |qr|
m.reply qr.to_s
end
m.reply "That's all!"
else
m.reply "I haven't seen #{nick}"
end
end

on :message, "quit" do | m |
bot.quit
end
end

bot.start
end
17 changes: 17 additions & 0 deletions lunch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Lunch < Bot::Command
respond_to "food"
require 'nokogiri'
require 'open-uri'

def self.respond
end

def self.fetch_lunch
on :message, "food" do | m |
doc = Nokogiri.HTML(open("http://www.kvartersmenyn.se/start/city/1/23").read)
doc.at_css("span a[href='http://ringos.kvartersmenyn.se/']").ancestors("table").at_css("td:nth-child(2)").inner_html.gsub("<br>","\n").gsub(/<div.*<\/div>/,"").strip
end

end

end

0 comments on commit 10da8ad

Please sign in to comment.