Skip to content

Commit 2e28b35

Browse files
lukeisDominikDary
authored andcommitted
adding local logging of chat
1 parent 25d290d commit 2e28b35

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
notes.yml
22
selbotseen.yml
33
tmp/
4-
.bundle
4+

bin/selbot2.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@
1818
# Selbot2::SeleniumHQ,
1919
Selbot2::CI,
2020
Selbot2::Google,
21+
<<<<<<< HEAD
2122
# Selbot2::WhoBrokeIt
23+
=======
24+
Selbot2::Log,
25+
Selbot2::WhoBrokeIt
26+
>>>>>>> adding local logging of chat
2227
]
2328

2429
# if File.exist?("twitter.conf")

lib/selbot2.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55

66
module Selbot2
77
PREFIX = ":"
8+
<<<<<<< HEAD
89
CHANNELS = Array(ENV['SELBOT_CHANNEL'] || ["#selendroid"])
10+
=======
11+
CHANNELS = Array(ENV['SELBOT_CHANNEL'])
12+
>>>>>>> adding local logging of chat
913
HELPS = []
1014
end
1115

@@ -25,3 +29,4 @@ module Selbot2
2529
# require 'selbot2/twitter'
2630
require 'selbot2/google'
2731
require 'selbot2/whobrokeit'
32+
require 'selbot2/log'

lib/selbot2/log.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require 'fileutils'
2+
3+
module Selbot2
4+
class Log
5+
include Cinch::Plugin
6+
7+
listen_to :channel, :join, :part, :quit, :nick
8+
9+
def listen(m)
10+
return unless m.user
11+
nick = m.command == 'NICK' ? m.user.last_nick : m.user.nick
12+
13+
e = Event.new(nick, m.message, m.command, Time.now)
14+
FileUtils.mkpath "log/#{(Time.new).strftime('%Y/%m')}"
15+
File.open("log/#{(Time.new).strftime('%Y/%m/%d')}.txt", 'a') {|f| f.puts(e.to_s) }
16+
end
17+
18+
private
19+
20+
class Event
21+
def initialize(nick, message, type, time)
22+
@nick = nick
23+
@message = message
24+
@type = type
25+
@time = time
26+
end
27+
28+
def to_s
29+
msg = "#{(Time.new).strftime('[%Y-%m-%d %H:%M:%S] ')}"
30+
31+
case @type
32+
when 'JOIN'
33+
msg << "#{@nick}, joining. (#{@message})"
34+
when 'PART'
35+
msg << "#{@nick}, leaving. (#{@message})"
36+
when 'QUIT'
37+
msg << "#{@nick}, quitting. (#{@message})"
38+
when 'NICK'
39+
msg << "#{@nick}, changing nick to #{@message}."
40+
else
41+
if @message =~ /^\001ACTION (.+?)\001/
42+
msg << "*#{@nick} #{$1}'"
43+
else
44+
msg << "#{@nick}: #{@message}"
45+
end
46+
end
47+
end
48+
end
49+
50+
end
51+
end

0 commit comments

Comments
 (0)