cinch-logsearch 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -0
- data/Rakefile +6 -0
- data/cinch-logsearch.gemspec +7 -0
- data/lib/cinch/plugins/logsearch/logsearch.rb +39 -26
- data/lib/cinch/plugins/logsearch/version.rb +1 -1
- data/spec/cinch-logsearch_spec.rb +60 -0
- data/spec/secret.rb +4 -0
- data/spec/spec_helper.rb +12 -0
- metadata +93 -5
data/.travis.yml
ADDED
data/Rakefile
CHANGED
data/cinch-logsearch.gemspec
CHANGED
@@ -16,4 +16,11 @@ Gem::Specification.new do |gem|
|
|
16
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rake'
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
gem.add_development_dependency 'coveralls'
|
23
|
+
gem.add_development_dependency 'cinch-test'
|
24
|
+
|
25
|
+
gem.add_dependency 'cinch', '~> 2.0.0'
|
19
26
|
end
|
@@ -1,44 +1,57 @@
|
|
1
|
+
require 'cinch'
|
2
|
+
|
1
3
|
module Cinch::Plugins
|
2
4
|
class LogSearch
|
3
5
|
include Cinch::Plugin
|
4
6
|
|
5
7
|
self.help = "Use .search <text> to search the logs. *Only works via private message*, limited to 5 results for now."
|
6
8
|
|
7
|
-
match /search (.*)
|
8
|
-
|
9
|
-
def execute(m, search)
|
10
|
-
# Don't listen to searches in channels. Reduce SPAM.
|
11
|
-
return if m.channel?
|
9
|
+
match /search (.*)/, react_on: :private
|
12
10
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
@max_results = config[:max_results] || 5
|
19
|
-
@matches = []
|
11
|
+
def initialize(*args)
|
12
|
+
super
|
13
|
+
@max_results = config[:max_results] || 5
|
14
|
+
@log_directory = config[:logs_directory] || File.join('.', 'logs', '*.log')
|
15
|
+
end
|
20
16
|
|
21
|
-
|
22
|
-
|
23
|
-
@matches += File.open(file, 'r').grep(Regexp.new(search))
|
24
|
-
# For the sake of sanity, stop looking once we find @max_results
|
25
|
-
break if @matches.length > @max_results
|
26
|
-
end
|
17
|
+
def execute(m, search)
|
18
|
+
return unless log_files_exist?
|
27
19
|
|
28
|
-
|
29
|
-
@matches.map! { |msg| msg.chomp }
|
20
|
+
matches = search_for(search)
|
30
21
|
|
31
|
-
if
|
22
|
+
if matches.empty?
|
32
23
|
m.user.msg "No matches found!"
|
33
24
|
else
|
34
|
-
msg =
|
35
|
-
|
36
|
-
msg
|
37
|
-
|
38
|
-
@matches[-@max_results..-1].each do |match|
|
25
|
+
msg = ['Found', matches.count, 'matches before giving up,',
|
26
|
+
'here\'s the most recent', @max_results]
|
27
|
+
m.user.msg msg.join(' ')
|
28
|
+
matches.reverse[0..(@max_results - 1)].reverse.each do |match|
|
39
29
|
m.user.msg match
|
40
30
|
end
|
41
31
|
end
|
42
32
|
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def log_files_exist?
|
37
|
+
return true if File.exist?(@log_directory)
|
38
|
+
debug 'Log files not found!'
|
39
|
+
false
|
40
|
+
end
|
41
|
+
|
42
|
+
def search_for(search_term)
|
43
|
+
matches = []
|
44
|
+
|
45
|
+
# Search the logs for the phrase, this is pretty simple and kind of dumb.
|
46
|
+
# Probably make this smarter by using a real search algo at some point if people care.
|
47
|
+
Dir[@log_directory].sort.reverse.each do |file|
|
48
|
+
matches += File.open(file, 'r').grep(Regexp.new(search_term))
|
49
|
+
# For the sake of sanity, stop looking once we find @max_results
|
50
|
+
break if matches.length > @max_results
|
51
|
+
end
|
52
|
+
|
53
|
+
# I hate new lines.
|
54
|
+
matches.map(&:chomp)
|
55
|
+
end
|
43
56
|
end
|
44
57
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
LOG = File.join('/tmp', 'cinch-testing.log')
|
5
|
+
|
6
|
+
describe Cinch::Plugins::LogSearch do
|
7
|
+
include Cinch::Test
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
@bot = make_bot(Cinch::Plugins::LogSearch, { logs_directory: LOG })
|
11
|
+
build_logs
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should not find anything if no logs are present' do
|
15
|
+
get_replies(make_message(@bot, '!search foo'), :private).
|
16
|
+
first.text.should == "No matches found!"
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should not return any response when users search in channel' do
|
20
|
+
get_replies(make_message(@bot, '!search foo'), :channel).
|
21
|
+
should be_empty
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should let users search log files' do
|
25
|
+
get_replies(make_message(@bot, '!search movie'), :private).
|
26
|
+
first.text.should == "Found 1 matches before giving up, here's the most recent 5"
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should allow users to do complex searches' do
|
30
|
+
get_replies(make_message(@bot, '!search \sw.+\s'), :private).
|
31
|
+
first.text.should == "Found 3 matches before giving up, here's the most recent 5"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def build_logs
|
36
|
+
log = <<" EOF"
|
37
|
+
[2012-07-24 23:09:15] <Carnivor> Oh. Good. You timed out.
|
38
|
+
[2012-07-24 23:09:20] <feen> no
|
39
|
+
[2012-07-24 23:09:22] <feen> i got back home
|
40
|
+
[2012-07-24 23:09:31] <Carnivor> Oh. So you got that.
|
41
|
+
[2012-07-24 23:09:37] <Carnivor> Yay not having to resend.
|
42
|
+
[2012-07-24 23:10:05] <silveridea> oh god, i cant know this
|
43
|
+
[2012-07-24 23:10:12] <feen> sorry
|
44
|
+
[2012-07-24 23:10:12] <feen> ill stop
|
45
|
+
[2012-07-24 23:10:16] <silveridea> heh
|
46
|
+
[2012-07-24 23:10:20] <silveridea> i just wanted to quote mal
|
47
|
+
[2012-07-24 23:10:24] <feen> hahahahaha
|
48
|
+
[2012-07-24 23:10:30] <feen> i need to watch a good movie
|
49
|
+
[2012-07-24 23:10:35] <feen> OH SHIT I STILL HAVENT WATCHED TINKER TAILOR
|
50
|
+
[2012-07-24 23:10:37] <silveridea> heat
|
51
|
+
[2012-07-24 23:10:44] <silveridea> actually tinker tailor is pretty good
|
52
|
+
[2012-07-24 23:10:49] <silveridea> be prepared to pay attention
|
53
|
+
[2012-07-24 23:10:49] <feen> i've seen heat like
|
54
|
+
[2012-07-24 23:10:51] <feen> ten thousand times
|
55
|
+
[2012-07-24 23:11:27] <silveridea> well im going to attempt sleep
|
56
|
+
EOF
|
57
|
+
File.open(LOG, 'w') do |file|
|
58
|
+
file.write(log)
|
59
|
+
end
|
60
|
+
end
|
data/spec/secret.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
require 'simplecov'
|
3
|
+
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
Coveralls::SimpleCov::Formatter
|
7
|
+
]
|
8
|
+
SimpleCov.start
|
9
|
+
|
10
|
+
require 'json'
|
11
|
+
require 'cinch-logsearch'
|
12
|
+
require 'cinch/test'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch-logsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,88 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
13
|
-
dependencies:
|
12
|
+
date: 2013-08-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: coveralls
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: cinch-test
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: cinch
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 2.0.0
|
86
|
+
type: :runtime
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 2.0.0
|
14
94
|
description: Cinch Plugin to search log files for users.
|
15
95
|
email:
|
16
96
|
- bhaberer@gmail.com
|
@@ -19,6 +99,7 @@ extensions: []
|
|
19
99
|
extra_rdoc_files: []
|
20
100
|
files:
|
21
101
|
- .gitignore
|
102
|
+
- .travis.yml
|
22
103
|
- Gemfile
|
23
104
|
- LICENSE.txt
|
24
105
|
- README.md
|
@@ -27,6 +108,9 @@ files:
|
|
27
108
|
- lib/cinch-logsearch.rb
|
28
109
|
- lib/cinch/plugins/logsearch/logsearch.rb
|
29
110
|
- lib/cinch/plugins/logsearch/version.rb
|
111
|
+
- spec/cinch-logsearch_spec.rb
|
112
|
+
- spec/secret.rb
|
113
|
+
- spec/spec_helper.rb
|
30
114
|
homepage: https://github.com/bhaberer/cinch-logsearch
|
31
115
|
licenses: []
|
32
116
|
post_install_message:
|
@@ -47,8 +131,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
47
131
|
version: '0'
|
48
132
|
requirements: []
|
49
133
|
rubyforge_project:
|
50
|
-
rubygems_version: 1.8.
|
134
|
+
rubygems_version: 1.8.25
|
51
135
|
signing_key:
|
52
136
|
specification_version: 3
|
53
137
|
summary: Cinch Plugin for searching irc logs.
|
54
|
-
test_files:
|
138
|
+
test_files:
|
139
|
+
- spec/cinch-logsearch_spec.rb
|
140
|
+
- spec/secret.rb
|
141
|
+
- spec/spec_helper.rb
|
142
|
+
has_rdoc:
|