Permalink
Browse files

initial commit first commands

  • Loading branch information...
0 parents commit 10da8ad991768de1006cf648bf0c33f3477b4b62 @timrombergjakobsson committed Mar 15, 2012
Showing with 73 additions and 0 deletions.
  1. +2 −0 README
  2. +54 −0 bot.rb
  3. +17 −0 lunch.rb
2 README
@@ -0,0 +1,2 @@
+A simple irc bot in Ruby...
+Nothing much yet more to come...
54 bot.rb
@@ -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
@@ -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.