cinch-logsearch 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +1 -0
- data/cinch-logsearch.gemspec +19 -0
- data/lib/cinch-logsearch.rb +2 -0
- data/lib/cinch/plugins/logsearch/logsearch.rb +44 -0
- data/lib/cinch/plugins/logsearch/version.rb +7 -0
- metadata +54 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Brian Haberer
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# Cinch::Plugins::Logsearch
|
2
|
+
|
3
|
+
Cinch Plugin to allow users to search through channel logs, easiest used with cinch-simplelog.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'cinch-logsearch'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install cinch-logsearch
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Just add the plugin to your list:
|
22
|
+
|
23
|
+
@bot = Cinch::Bot.new do
|
24
|
+
configure do |c|
|
25
|
+
c.plugins.plugins = [Cinch::Plugins::LogSearch]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
If your logs are not in `logs/*.logs` you will need to set a config
|
30
|
+
value to point to the location of your logs.
|
31
|
+
|
32
|
+
c.plugins.options[Cinch::Plugins::LogSearch][:log_path] = '/var/logs/irc/*.log'
|
33
|
+
|
34
|
+
You can also change the number of results returned (Default: 5) by setting an additional config value:
|
35
|
+
|
36
|
+
c.plugins.options[Cinch::Plugins::LogSearch][:max_results] = 10
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it
|
41
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
42
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
43
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
44
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'cinch/plugins/logsearch/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "cinch-logsearch"
|
8
|
+
gem.version = Cinch::Plugins::LogSearch::VERSION
|
9
|
+
gem.authors = ["Brian Haberer"]
|
10
|
+
gem.email = ["bhaberer@gmail.com"]
|
11
|
+
gem.description = %q{Cinch Plugin to search log files for users.}
|
12
|
+
gem.summary = %q{Cinch Plugin for searching irc logs.}
|
13
|
+
gem.homepage = "https://github.com/bhaberer/cinch-logsearch"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Cinch::Plugins
|
2
|
+
class LogSearch
|
3
|
+
include Cinch::Plugin
|
4
|
+
|
5
|
+
self.help = "Use .search <text> to search the logs. *Only works via private message*, limited to 5 results for now."
|
6
|
+
|
7
|
+
match /search (.*)/
|
8
|
+
|
9
|
+
def execute(m, search)
|
10
|
+
# Don't listen to searches in channels. Reduce SPAM.
|
11
|
+
return if m.channel?
|
12
|
+
|
13
|
+
# However, make sure the user is in a channel with the bot
|
14
|
+
chans = @bot.channels
|
15
|
+
chans.delete_if { |chan| !chan.has_user?(m.user) }
|
16
|
+
return if chans.empty?
|
17
|
+
|
18
|
+
@max_results = config[:max_results] || 5
|
19
|
+
@matches = []
|
20
|
+
|
21
|
+
# Search the logs for the phrase, this is pretty simple.
|
22
|
+
Dir[config[:log_path] || File.join('.', 'logs', '*.log')].sort.reverse.each do |file|
|
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
|
27
|
+
|
28
|
+
# I hate new lines.
|
29
|
+
@matches.map! { |msg| msg.chomp }
|
30
|
+
|
31
|
+
if @matches.empty?
|
32
|
+
m.user.msg "No matches found!"
|
33
|
+
else
|
34
|
+
msg = "Found #{@matches.count} matches"
|
35
|
+
msg << "before giving up" if @matches.length > @max_results
|
36
|
+
msg << ". Here's the last #{@max_results}:"
|
37
|
+
m.user.msg msg
|
38
|
+
@matches[-@max_results..-1].each do |match|
|
39
|
+
m.user.msg match
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cinch-logsearch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Haberer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-05-07 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Cinch Plugin to search log files for users.
|
15
|
+
email:
|
16
|
+
- bhaberer@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- cinch-logsearch.gemspec
|
27
|
+
- lib/cinch-logsearch.rb
|
28
|
+
- lib/cinch/plugins/logsearch/logsearch.rb
|
29
|
+
- lib/cinch/plugins/logsearch/version.rb
|
30
|
+
homepage: https://github.com/bhaberer/cinch-logsearch
|
31
|
+
licenses: []
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
require_paths:
|
35
|
+
- lib
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.8.24
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: Cinch Plugin for searching irc logs.
|
54
|
+
test_files: []
|