cinch-logsearch 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +20 -1
- data/cinch-logsearch.gemspec +9 -11
- data/lib/cinch/plugins/logsearch.rb +45 -43
- data/lib/cinch/plugins/logsearch/version.rb +1 -1
- data/spec/cinch-logsearch_spec.rb +15 -13
- metadata +27 -36
- data/spec/secret.rb +0 -4
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: 539f25b720fc7069294eb3dc6441813c2163425b
|
4
|
+
data.tar.gz: f43efe6302319444492fd2220a49abc3c6a061d0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dec9b6b89c3e5e3f45e07965a389ad32d9af8e34f65822b57c5b107172aff00690502b594e47a062279db0dbffdc54f487ad8b16786873b7824f56ec4535855d
|
7
|
+
data.tar.gz: 088dd753b61637807274b05b2020d25cd7edd63da736943356c5455a6b1cec464af37db463281aad663ddf1002e3a237f99c2d83cc416d2c43641d8473d30302
|
data/.travis.yml
CHANGED
@@ -1,4 +1,23 @@
|
|
1
1
|
language: ruby
|
2
|
+
env:
|
3
|
+
global:
|
4
|
+
- "JRUBY_OPTS=-Xcext.enabled=true"
|
2
5
|
rvm:
|
3
|
-
- 1.
|
6
|
+
- 2.1.0
|
7
|
+
- 2.0.0
|
4
8
|
- 1.9.3
|
9
|
+
- 1.9.2
|
10
|
+
- 1.8.7
|
11
|
+
- jruby-18mode
|
12
|
+
- jruby-19mode
|
13
|
+
- ruby-head
|
14
|
+
- jruby-head
|
15
|
+
- ree
|
16
|
+
matrix:
|
17
|
+
allow_failures:
|
18
|
+
- rvm: 1.8.7
|
19
|
+
- rvm: ree
|
20
|
+
- rvm: jruby-18mode
|
21
|
+
- rvm: jruby-19mode
|
22
|
+
- rvm: jruby-head
|
23
|
+
fast_finish: true
|
data/cinch-logsearch.gemspec
CHANGED
@@ -8,20 +8,18 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Cinch::Plugins::LogSearch::VERSION
|
9
9
|
gem.authors = ['Brian Haberer']
|
10
10
|
gem.email = ['bhaberer@gmail.com']
|
11
|
-
gem.description = %q
|
12
|
-
gem.summary = %q
|
11
|
+
gem.description = %q(Cinch Plugin to search log files for users.)
|
12
|
+
gem.summary = %q(Cinch Plugin for searching irc logs.)
|
13
13
|
gem.homepage = 'https://github.com/bhaberer/cinch-logsearch'
|
14
14
|
gem.license = 'MIT'
|
15
|
-
|
16
15
|
gem.files = `git ls-files`.split($/)
|
17
|
-
gem.executables = gem.files.grep(
|
18
|
-
gem.test_files = gem.files.grep(
|
16
|
+
gem.executables = gem.files.grep(/^bin\//).map { |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(/^(test|spec|features)\//)
|
19
18
|
gem.require_paths = ['lib']
|
20
19
|
|
21
|
-
gem.add_development_dependency 'rake'
|
22
|
-
gem.add_development_dependency 'rspec'
|
23
|
-
gem.add_development_dependency 'coveralls'
|
24
|
-
gem.add_development_dependency 'cinch-test'
|
25
|
-
|
26
|
-
gem.add_dependency 'cinch', '~> 2.0.0'
|
20
|
+
gem.add_development_dependency 'rake', '~> 10'
|
21
|
+
gem.add_development_dependency 'rspec', '~> 3'
|
22
|
+
gem.add_development_dependency 'coveralls', '~> 0.7'
|
23
|
+
gem.add_development_dependency 'cinch-test', '~> 0.1', '>= 0.1.0'
|
24
|
+
gem.add_dependency 'cinch', '~> 2'
|
27
25
|
end
|
@@ -1,62 +1,64 @@
|
|
1
1
|
# -*- encoding : utf-8 -*-
|
2
2
|
require 'cinch'
|
3
3
|
|
4
|
-
module Cinch
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
module Cinch
|
5
|
+
module Plugins
|
6
|
+
# CInch Plugin to search logs
|
7
|
+
class LogSearch
|
8
|
+
include Cinch::Plugin
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
self.help = 'Use .search <text> to search the logs. *Only works via ' \
|
11
|
+
'private message*, limited to 5 results for now.'
|
11
12
|
|
12
|
-
|
13
|
+
match(/search (.*)/, react_on: :private)
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def initialize(*args)
|
16
|
+
super
|
17
|
+
@max_results = config[:max_results] || 5
|
18
|
+
@log_directory = config[:logs_directory] ||
|
19
|
+
File.join('.', 'logs', '*.log')
|
20
|
+
end
|
20
21
|
|
21
|
-
|
22
|
-
|
22
|
+
def execute(m, search)
|
23
|
+
return unless log_files_exist?
|
23
24
|
|
24
|
-
|
25
|
+
matches = search_for(search)
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
if matches.empty?
|
28
|
+
m.user.msg 'No matches found!'
|
29
|
+
return
|
30
|
+
end
|
30
31
|
|
31
|
-
|
32
|
-
|
32
|
+
msg = ['Found', matches.count, 'matches before giving up,',
|
33
|
+
'here\'s the most recent', @max_results]
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
m.user.msg msg.join(' ')
|
36
|
+
matches.each { |match| m.user.msg match }
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
+
private
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
def log_files_exist?
|
42
|
+
return true if File.exist?(@log_directory)
|
43
|
+
debug 'Log files not found!'
|
44
|
+
false
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
47
|
+
def search_for(search_term)
|
48
|
+
matches = []
|
48
49
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
50
|
+
# Search the logs for the phrase, this is pretty simple and kind of
|
51
|
+
# dumb. I should probably make this smarter by using a real search
|
52
|
+
# algo at some point, if people care.
|
53
|
+
Dir[@log_directory].sort.reverse.each do |file|
|
54
|
+
matches += File.open(file, 'r').grep(Regexp.new(search_term))
|
55
|
+
# For the sake of sanity, stop looking once we find @max_results
|
56
|
+
break if matches.length > @max_results
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
-
|
59
|
+
# I hate new lines.
|
60
|
+
matches.map(&:chomp).reverse[0..(@max_results - 1)].reverse
|
61
|
+
end
|
60
62
|
end
|
61
63
|
end
|
62
64
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
|
-
LOG = File.join('/tmp', 'cinch-testing.log')
|
4
|
+
LOG = File.join('/tmp', 'cinch-testing.log')
|
5
5
|
|
6
6
|
describe Cinch::Plugins::LogSearch do
|
7
7
|
include Cinch::Test
|
@@ -12,28 +12,30 @@ describe Cinch::Plugins::LogSearch do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should not find anything if no logs are present' do
|
15
|
-
get_replies(make_message(@bot, '!search foo'), :private).
|
16
|
-
|
15
|
+
msg = get_replies(make_message(@bot, '!search foo'), :private).first
|
16
|
+
expect(msg.text).to eq('No matches found!')
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'should not return any response when users search in channel' do
|
20
|
-
get_replies(make_message(@bot, '!search foo'
|
21
|
-
|
20
|
+
expect(get_replies(make_message(@bot, '!search foo', { channel: '#foo' })))
|
21
|
+
.to be_empty
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'should let users search log files' do
|
25
|
-
get_replies(make_message(@bot, '!search movie'), :private).
|
26
|
-
|
25
|
+
msg = get_replies(make_message(@bot, '!search movie'), :private).first
|
26
|
+
expect(msg.text)
|
27
|
+
.to eq('Found 1 matches before giving up, here\'s the most recent 5')
|
27
28
|
end
|
28
29
|
|
29
|
-
it 'should allow users to do complex searches' do
|
30
|
-
get_replies(make_message(@bot, '!search \sw.+\s'), :private).
|
31
|
-
|
30
|
+
it 'should allow users to do complex searches' do
|
31
|
+
msg = get_replies(make_message(@bot, '!search \sw.+\s'), :private).first
|
32
|
+
expect(msg.text)
|
33
|
+
.to eq('Found 3 matches before giving up, here\'s the most recent 5')
|
32
34
|
end
|
33
35
|
end
|
34
36
|
|
35
|
-
def build_logs
|
36
|
-
log = <<" EOF"
|
37
|
+
def build_logs
|
38
|
+
log = <<" EOF"
|
37
39
|
[2012-07-24 23:09:15] <Carnivor> Oh. Good. You timed out.
|
38
40
|
[2012-07-24 23:09:20] <feen> no
|
39
41
|
[2012-07-24 23:09:22] <feen> i got back home
|
@@ -54,7 +56,7 @@ def build_logs
|
|
54
56
|
[2012-07-24 23:10:51] <feen> ten thousand times
|
55
57
|
[2012-07-24 23:11:27] <silveridea> well im going to attempt sleep
|
56
58
|
EOF
|
57
|
-
File.open(LOG, 'w') do |file|
|
59
|
+
File.open(LOG, 'w') do |file|
|
58
60
|
file.write(log)
|
59
61
|
end
|
60
62
|
end
|
metadata
CHANGED
@@ -1,96 +1,91 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch-logsearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Brian Haberer
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-08-01 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ~>
|
20
18
|
- !ruby/object:Gem::Version
|
21
|
-
version: '
|
19
|
+
version: '10'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ~>
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
26
|
+
version: '10'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: rspec
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ~>
|
36
32
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
33
|
+
version: '3'
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ~>
|
44
39
|
- !ruby/object:Gem::Version
|
45
|
-
version: '
|
40
|
+
version: '3'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: coveralls
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ~>
|
52
46
|
- !ruby/object:Gem::Version
|
53
|
-
version: '0'
|
47
|
+
version: '0.7'
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ~>
|
60
53
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
54
|
+
version: '0.7'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: cinch-test
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.1'
|
67
62
|
- - ! '>='
|
68
63
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
64
|
+
version: 0.1.0
|
70
65
|
type: :development
|
71
66
|
prerelease: false
|
72
67
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
68
|
requirements:
|
69
|
+
- - ~>
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0.1'
|
75
72
|
- - ! '>='
|
76
73
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
74
|
+
version: 0.1.0
|
78
75
|
- !ruby/object:Gem::Dependency
|
79
76
|
name: cinch
|
80
77
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
78
|
requirements:
|
83
79
|
- - ~>
|
84
80
|
- !ruby/object:Gem::Version
|
85
|
-
version: 2
|
81
|
+
version: '2'
|
86
82
|
type: :runtime
|
87
83
|
prerelease: false
|
88
84
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
85
|
requirements:
|
91
86
|
- - ~>
|
92
87
|
- !ruby/object:Gem::Version
|
93
|
-
version: 2
|
88
|
+
version: '2'
|
94
89
|
description: Cinch Plugin to search log files for users.
|
95
90
|
email:
|
96
91
|
- bhaberer@gmail.com
|
@@ -109,35 +104,31 @@ files:
|
|
109
104
|
- lib/cinch/plugins/logsearch.rb
|
110
105
|
- lib/cinch/plugins/logsearch/version.rb
|
111
106
|
- spec/cinch-logsearch_spec.rb
|
112
|
-
- spec/secret.rb
|
113
107
|
- spec/spec_helper.rb
|
114
108
|
homepage: https://github.com/bhaberer/cinch-logsearch
|
115
109
|
licenses:
|
116
110
|
- MIT
|
111
|
+
metadata: {}
|
117
112
|
post_install_message:
|
118
113
|
rdoc_options: []
|
119
114
|
require_paths:
|
120
115
|
- lib
|
121
116
|
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
-
none: false
|
123
117
|
requirements:
|
124
118
|
- - ! '>='
|
125
119
|
- !ruby/object:Gem::Version
|
126
120
|
version: '0'
|
127
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
-
none: false
|
129
122
|
requirements:
|
130
123
|
- - ! '>='
|
131
124
|
- !ruby/object:Gem::Version
|
132
125
|
version: '0'
|
133
126
|
requirements: []
|
134
127
|
rubyforge_project:
|
135
|
-
rubygems_version:
|
128
|
+
rubygems_version: 2.2.2
|
136
129
|
signing_key:
|
137
|
-
specification_version:
|
130
|
+
specification_version: 4
|
138
131
|
summary: Cinch Plugin for searching irc logs.
|
139
132
|
test_files:
|
140
133
|
- spec/cinch-logsearch_spec.rb
|
141
|
-
- spec/secret.rb
|
142
134
|
- spec/spec_helper.rb
|
143
|
-
has_rdoc:
|
data/spec/secret.rb
DELETED