-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 10da8ad
Showing
3 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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... |
This file contains 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
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 |
This file contains 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
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 |