-
Notifications
You must be signed in to change notification settings - Fork 0
/
history_bot.rb
39 lines (31 loc) · 944 Bytes
/
history_bot.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require "socket"
class History_Bot
def initialize
server = "chat.freenode.net"
port = "6667"
nick = "HistoryBot"
@channel = "#botmaker"
@irc_server = TCPSocket.open(server, port)
@irc_server.puts "USER historybot 0 * HistoryBot"
@irc_server.puts "NICK #{nick}"
@irc_server.puts "JOIN #{@channel}"
@irc_server.puts "PRIVMSG #{@channel} :This is the HistoryBot. The command is !get_me_up_to_speed(num), where num gets the last num lines"
@records = File.open("records.md", "a+")
end
def librarian
until @irc_server.eof? do
@input = @irc_server.gets
if @input.include?("PRIVMSG #{@channel} :")
usr = @input[/:[a-zA-Z_\-@]*!/]
msg = @input.sub(/.*?(?=PRIVMSG #{@channel})PRIVMSG #{@channel} :/, '')
@records.syswrite(usr[1...-1] + ': ' + msg + "\n")
end
end
end
def get_me_up_to_speed(num)
@records.rewind
@records.read
end
end
@historyBot = History_Bot.new
@historyBot.librarian