Skip to content

Commit 7fa1cf1

Browse files
committed
first version
1 parent c2f5c71 commit 7fa1cf1

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*~
22
.bundle
3+
*.swp

robot.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
require 'cinch'
2+
3+
class QuestionRecord < Struct.new(:who, :what, :time)
4+
def to_s
5+
"[#{time.asctime}] #{who} had a question, '#{what}'"
6+
end
7+
end
8+
9+
bot = Cinch::Bot.new do
10+
configure do |c|
11+
c.nick = "HacketyRobot"
12+
c.password = ""
13+
c.server = "irc.freenode.org"
14+
c.channels = ["#hacketyhack"]
15+
@users = {}
16+
end
17+
18+
on :message, "hello" do |m|
19+
m.reply "Hello, #{m.user.nick}"
20+
end
21+
22+
on :message, /\?/ do |m|
23+
@users[m.user.nick] ||= []
24+
if @users[m.user.nick].length == 0
25+
m.channel.send "#{m.user.nick}: Thanks for asking a question! You can also get help here: http://bit.ly/hacketyhelp"
26+
end
27+
@users[m.user.nick] << QuestionRecord.new(m.user.nick, m.message, Time.new)
28+
m.channel.send "#{m.user.nick}: your question has been recorded."
29+
end
30+
31+
on :channel, /^!question (.+)/ do |m, nick|
32+
if nick == bot.nick
33+
m.reply "That's me!"
34+
elsif @users.key?(nick)
35+
@users[nick].each do |qr|
36+
m.reply qr.to_s
37+
end
38+
else
39+
m.reply "I haven't seen #{nick}"
40+
end
41+
end
42+
end
43+
44+
bot.start
45+

0 commit comments

Comments
 (0)