david-logbot 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +20 -0
- data/README +4 -0
- data/Rakefile +26 -0
- data/TODO +13 -0
- data/config/logbot.conf.sample +6 -0
- data/lib/logbot.rb +13 -0
- data/lib/logbot/channel.rb +15 -0
- data/lib/logbot/daemon.rb +66 -0
- data/lib/logbot/event.rb +12 -0
- data/lib/logbot/logging.rb +20 -0
- data/script/logbot +16 -0
- metadata +83 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2007 David Leal
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/gempackagetask'
|
3
|
+
require 'spec/rake/spectask'
|
4
|
+
|
5
|
+
load 'logbot.gemspec'
|
6
|
+
|
7
|
+
Rake::GemPackageTask.new(SPEC) do |pkg|
|
8
|
+
pkg.gem_spec = SPEC
|
9
|
+
end
|
10
|
+
|
11
|
+
task :install => [:package] do
|
12
|
+
sh %{sudo gem install pkg/#{GEM}-#{VERSION}}
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Run all specs"
|
16
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
17
|
+
t.spec_files = FileList['spec/**/*.rb']
|
18
|
+
t.spec_opts = %w{--color}
|
19
|
+
end
|
20
|
+
|
21
|
+
desc "Run all specs with rcov"
|
22
|
+
Spec::Rake::SpecTask.new('spec:rcov') do |t|
|
23
|
+
t.spec_files = FileList['spec/**/*.rb']
|
24
|
+
t.rcov = true
|
25
|
+
t.rcov_opts = %w{--exclude spec --text-summary}
|
26
|
+
end
|
data/TODO
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
TODO:
|
2
|
+
* When invited
|
3
|
+
* say hi (?)
|
4
|
+
* When kicked
|
5
|
+
* warn subscribers that the channel is not being logged anymore (?)
|
6
|
+
* PM email interface (? feed reader instead?)
|
7
|
+
* subscribe channel[, channel]* email [html]
|
8
|
+
* unsubscribe channel[, channel]
|
9
|
+
* help
|
10
|
+
* Public interface
|
11
|
+
* feed: returns channel feed location
|
12
|
+
* last x: returns the last x messages (in a PM)
|
13
|
+
* offtherecord x: stop logging for x minutes
|
data/lib/logbot.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
gem 'dm-core', '> 0.9.0'
|
4
|
+
|
5
|
+
require 'dm-core'
|
6
|
+
require 'dm-types'
|
7
|
+
require 'dm-timestamps'
|
8
|
+
require 'minibot'
|
9
|
+
|
10
|
+
require File.join(File.dirname(__FILE__), 'logbot', 'channel')
|
11
|
+
require File.join(File.dirname(__FILE__), 'logbot', 'event')
|
12
|
+
require File.join(File.dirname(__FILE__), 'logbot', 'daemon')
|
13
|
+
require File.join(File.dirname(__FILE__), 'logbot', 'logging')
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'dm-core'
|
2
|
+
require 'dm-timestamps'
|
3
|
+
|
4
|
+
module LogBot
|
5
|
+
class Channel
|
6
|
+
include DataMapper::Resource
|
7
|
+
|
8
|
+
property :name, String, :key => true
|
9
|
+
property :topic_message, String
|
10
|
+
property :topic_author, String
|
11
|
+
property :topic_created_on, Date
|
12
|
+
property :created_on, Date
|
13
|
+
property :updated_on, Date
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'minibot'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module LogBot
|
5
|
+
class Daemon < MiniBot::Daemon
|
6
|
+
def message(channel, nick, msg)
|
7
|
+
Event.create :type => :message, :channel => channel, :nick => nick, :content => msg
|
8
|
+
end
|
9
|
+
|
10
|
+
def invited(channel, nick)
|
11
|
+
unless Channel.get(channel)
|
12
|
+
join channel
|
13
|
+
topic_fields = [:topic_message, :topic_author, :topic_created_on]
|
14
|
+
tpic = Hash[ *topic_fields.zip(topic channel).flatten ]
|
15
|
+
tpic[:topic_created_on] = Date.parse(tpic[:topic_created_on].strftime('%Y/%m/%d')) \
|
16
|
+
if tpic[:topic_created_on]
|
17
|
+
|
18
|
+
Channel.create({ :name => channel }.merge(tpic).inject({}) { |h, (k, v)| h[k.to_sym] = v; h })
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def kicked(channel, nick, message)
|
23
|
+
Channel.all(:name => channel).destroy!;
|
24
|
+
end
|
25
|
+
|
26
|
+
def action(channel, nick, msg)
|
27
|
+
Event.create :type => :action, :channel => channel, :nick => nick, :content => msg
|
28
|
+
end
|
29
|
+
|
30
|
+
def user_joined(channel, nick)
|
31
|
+
Event.create :type => :user_joined, :channel => channel, :nick => nick
|
32
|
+
end
|
33
|
+
|
34
|
+
def user_parted(channel, nick)
|
35
|
+
Event.create :type => :user_parted, :channel => channel, :nick => nick
|
36
|
+
end
|
37
|
+
|
38
|
+
def topic_changed(channel, nick, topic)
|
39
|
+
Event.create :type => :topic_changed, :channel => channel, :nick => nick, :content => topic
|
40
|
+
end
|
41
|
+
|
42
|
+
def ready
|
43
|
+
join *Channel.all.map { |c| c.name }
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def initialize(config_file)
|
49
|
+
config = read config_file
|
50
|
+
logger = MiniBot::Logger.new(config.delete :log_file)
|
51
|
+
logger.level = config.delete :log_level
|
52
|
+
setup_repository config.delete :db_uri
|
53
|
+
super config
|
54
|
+
end
|
55
|
+
|
56
|
+
def setup_repository(uri)
|
57
|
+
DataMapper.setup(:default, uri)
|
58
|
+
repository(:default).adapter.resource_naming_convention =
|
59
|
+
DataMapper::NamingConventions::UnderscoredAndPluralizedWithoutModule
|
60
|
+
end
|
61
|
+
|
62
|
+
def read(config_file)
|
63
|
+
YAML.load_file(config_file).inject({}) { |h, (k, v)| h[k.to_sym] = v; h }
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
data/lib/logbot/event.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module LogBot
|
2
|
+
class Event
|
3
|
+
include DataMapper::Resource
|
4
|
+
|
5
|
+
property :type, DataMapper::Types::Enum[
|
6
|
+
:message, :action, :user_joined, :user_parted, :topic_changed ]
|
7
|
+
property :channel, String
|
8
|
+
property :nick, String
|
9
|
+
property :content, String
|
10
|
+
property :created_at, DateTime, :key => true
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'minibot/logger'
|
2
|
+
require 'extlib/hook'
|
3
|
+
|
4
|
+
MiniBot::Logger.with_level :debug do |l|
|
5
|
+
MiniBot::Events.send :include, Extlib::Hook
|
6
|
+
MiniBot::Events.before :dispatch do |msg|
|
7
|
+
l.write "<< #{msg}"
|
8
|
+
end
|
9
|
+
|
10
|
+
MiniBot::Server.send :include, Extlib::Hook
|
11
|
+
MiniBot::Server.before :write do |cmd, *rest|
|
12
|
+
l.write ">> #{cmd}"
|
13
|
+
end
|
14
|
+
|
15
|
+
LogBot::Daemon.class_eval do
|
16
|
+
define_method :handle_exception do |e|
|
17
|
+
l.write "!! #{e.class}:#{e.message}\n #{e.backtrace.join("\n ")}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/script/logbot
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'daemons'
|
5
|
+
require 'logbot'
|
6
|
+
|
7
|
+
Daemons.run_proc 'freenode-logger' do
|
8
|
+
config_file = ARGV.pop || "/etc/logbot.conf"
|
9
|
+
|
10
|
+
unless File.exists?(config_file)
|
11
|
+
puts "Config file not found"
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
|
15
|
+
LogBot::Daemon.new(config_file).run
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: david-logbot
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Leal
|
8
|
+
autorequire: logbot
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-25 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: minibot
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
24
|
+
- !ruby/object:Gem::Dependency
|
25
|
+
name: dm-core
|
26
|
+
version_requirement:
|
27
|
+
version_requirements: !ruby/object:Gem::Requirement
|
28
|
+
requirements:
|
29
|
+
- - ">="
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: "0"
|
32
|
+
version:
|
33
|
+
description: An IRC logger bot
|
34
|
+
email: dgleal@gmail.com
|
35
|
+
executables: []
|
36
|
+
|
37
|
+
extensions: []
|
38
|
+
|
39
|
+
extra_rdoc_files:
|
40
|
+
- README
|
41
|
+
- LICENSE
|
42
|
+
- TODO
|
43
|
+
files:
|
44
|
+
- LICENSE
|
45
|
+
- README
|
46
|
+
- Rakefile
|
47
|
+
- TODO
|
48
|
+
- script/logbot
|
49
|
+
- config/logbot.conf.sample
|
50
|
+
- lib/logbot.rb
|
51
|
+
- lib/logbot
|
52
|
+
- lib/logbot/daemon.rb
|
53
|
+
- lib/logbot/event.rb
|
54
|
+
- lib/logbot/logging.rb
|
55
|
+
- lib/logbot/channel.rb
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: ""
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
version:
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: "0"
|
74
|
+
version:
|
75
|
+
requirements: []
|
76
|
+
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 1.2.0
|
79
|
+
signing_key:
|
80
|
+
specification_version: 2
|
81
|
+
summary: An IRC logger bot
|
82
|
+
test_files: []
|
83
|
+
|