butler 1.8.3 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. data/CHANGELOG.txt +293 -37
  2. data/README.txt +10 -0
  3. data/Rakefile +24 -13
  4. data/bin/botcontrol +6 -5
  5. data/data/butler/dialogs/create.rb +21 -6
  6. data/data/butler/dialogs/create_config.rb +5 -2
  7. data/data/butler/dialogs/en/create.yaml +6 -3
  8. data/data/butler/dialogs/en/create_config.yaml +1 -0
  9. data/data/butler/dialogs/en/quickcreate.yaml +1 -1
  10. data/data/butler/dialogs/en/sync.yaml +7 -0
  11. data/data/butler/dialogs/en/username.yaml +2 -0
  12. data/data/butler/dialogs/quickcreate.rb +6 -2
  13. data/data/butler/dialogs/sync.rb +83 -0
  14. data/data/butler/dialogs/username.rb +1 -0
  15. data/data/butler/plugins/core/ping.rb +22 -0
  16. data/data/butler/plugins/core/remote.rb +38 -0
  17. data/data/butler/plugins/dev/eval.rb +6 -4
  18. data/data/butler/plugins/dev/onhandlers.rb +93 -0
  19. data/data/butler/plugins/dev/rawlog.rb +109 -45
  20. data/data/butler/plugins/games/countdown.rb +23 -14
  21. data/data/butler/plugins/games/eightball.rb +21 -13
  22. data/data/butler/plugins/games/roll.rb +12 -12
  23. data/data/butler/plugins/irc/join.rb +2 -2
  24. data/data/butler/plugins/irc/notice.rb +10 -10
  25. data/data/butler/plugins/irc/part.rb +12 -12
  26. data/data/butler/plugins/irc/privmsg.rb +10 -10
  27. data/data/butler/plugins/irc/quit.rb +12 -12
  28. data/data/butler/plugins/operator/devoice.rb +1 -1
  29. data/data/butler/plugins/public/help.rb +10 -4
  30. data/data/butler/plugins/{util → service}/calculator.rb +0 -0
  31. data/data/butler/plugins/service/define.rb +16 -13
  32. data/data/butler/plugins/service/log.rb +85 -0
  33. data/data/butler/plugins/service/seen.rb +64 -0
  34. data/data/butler/plugins/service/svn.rb +6 -5
  35. data/data/butler/plugins/util/load.rb +3 -1
  36. data/data/butler/services/org.rubyforge.butler/calculator/1/service.rb +96 -0
  37. data/data/butler/services/org.rubyforge.butler/log/1/service.rb +148 -68
  38. data/lib/access/admin.rb +5 -0
  39. data/lib/blank.rb +32 -0
  40. data/lib/butler.rb +4 -4
  41. data/lib/butler/bot.rb +118 -33
  42. data/lib/butler/control.rb +5 -4
  43. data/lib/butler/debuglog.rb +12 -4
  44. data/lib/butler/dialog.rb +1 -1
  45. data/lib/butler/initialvalues.rb +1 -1
  46. data/lib/butler/irc/client.rb +31 -12
  47. data/lib/butler/irc/message.rb +32 -13
  48. data/lib/butler/irc/parser.rb +67 -30
  49. data/lib/butler/irc/parser/{commands.rb → command.rb} +0 -38
  50. data/lib/butler/irc/parser/generic.rb +9 -12
  51. data/lib/butler/irc/parser/rfc2812.rb +40 -2
  52. data/lib/butler/irc/socket.rb +66 -41
  53. data/lib/butler/irc/string.rb +1 -5
  54. data/lib/butler/plugin.rb +56 -23
  55. data/lib/butler/plugin/configproxy.rb +1 -0
  56. data/lib/butler/plugin/more.rb +2 -2
  57. data/lib/butler/plugins.rb +7 -1
  58. data/lib/butler/remote/connection.rb +113 -0
  59. data/lib/butler/remote/message.rb +157 -0
  60. data/lib/butler/remote/server.rb +85 -0
  61. data/lib/butler/remote/user.rb +46 -0
  62. data/lib/butler/service.rb +2 -1
  63. data/lib/butler/services.rb +2 -2
  64. data/lib/butler/version.rb +2 -2
  65. data/lib/configuration.rb +13 -16
  66. data/lib/ostructfixed.rb +0 -6
  67. data/lib/ruby/array/random.rb +2 -1
  68. data/lib/scriptfile.rb +63 -14
  69. data/lib/timingoutresource.rb +54 -0
  70. data/test/test_scriptfile.rb +51 -0
  71. metadata +63 -61
  72. data/data/butler/dialogs/en/sync_plugins.yaml +0 -3
  73. data/data/butler/dialogs/sync_plugins.rb +0 -30
  74. data/data/butler/services/org.rubyforge.butler/calculator/1/calculator.rb +0 -68
  75. data/lib/log/splitter.rb +0 -30
  76. data/test/test_access/privilege/banners.statistics.yaml +0 -3
  77. data/test/test_access/privilege/banners.yaml +0 -3
  78. data/test/test_access/privilege/news.create.yaml +0 -3
  79. data/test/test_access/privilege/news.delete.yaml +0 -3
  80. data/test/test_access/privilege/news.edit.yaml +0 -3
  81. data/test/test_access/privilege/news.read.yaml +0 -3
  82. data/test/test_access/privilege/news.yaml +0 -3
  83. data/test/test_access/privilege/paid_content.yaml +0 -3
  84. data/test/test_access/privilege/statistics.ftp.yaml +0 -3
  85. data/test/test_access/privilege/statistics.web.yaml +0 -3
  86. data/test/test_access/privilege/statistics.yaml +0 -3
  87. data/test/test_access/role/chiefeditor.yaml +0 -7
  88. data/test/test_access/role/editor.yaml +0 -9
  89. data/test/test_access/user/test.yaml +0 -12
@@ -11,13 +11,14 @@ Butler.create(nil, name)
11
11
  bot = Butler.new(nil, name)
12
12
 
13
13
  nick = name
14
- bot.config["connections/main/server"] = ask(:server, "irc.freenode.org", String, :min => 3)
14
+ bot.config["connections/main/server"] = server=ask(:server, "irc.freenode.org", String, :min => 3)
15
15
  bot.config["connections/main/port"] = ask(:port, 6667, Integer, :between => [0, 65535])
16
16
  bot.config["connections/main/host"] = nil
17
+ bot.config["connections/main/serverpass"] = server=ask(:serverpass, nil, String)
17
18
  bot.config["connections/main/reconnect_delay"] = ask(:reconnect_delay, 60, Integer, :greater_or_equal => 0)
18
19
  bot.config["connections/main/reconnect_tries"] = ask(:reconnect_tries, -1, Integer, :greater_or_equal => -1)
19
20
  bot.config["connections/main/charset"] = server_encoding = ask(:server_encoding, 'utf-8', String)
20
- bot.config["connections/main/language"] = lang = ask(:language, "en", String, :min => 2)
21
+ bot.config["connections/main/language"] = lang = ask(:language, "en", String, :matching => /\A[A-Za-z0-9_.-]{2,40}\z/)
21
22
  bot.config["connections/main/nick"] = nick = ask(:nick, name, String, :between => [1, 32])
22
23
  bot.config["connections/main/alternative"] = ask(:nick2, '[1]'+nick, String, :between => [1, 32])
23
24
  bot.config["connections/main/user"] = ask(:user, nick, String, :between => [1, 32])
@@ -27,16 +28,30 @@ bot.config["connections/main/identify"] = :auto
27
28
  bot.config["connections/main/channels"] = channels=ask(:channels, (server == "irc.freenode.org" ? ["#butler"] : nil), Array, String, :matching => /\A#[^\0\s,]+\z/)
28
29
  channels.each { |channel|
29
30
  say(:config_channel, :name => channel)
30
- prefix = "channels/#{server.config_key}/#{channel.config_key}"
31
+ prefix = "channels/#{Configuration.escape(server)}/#{Configuration.escape(channel)}"
31
32
  bot.config["#{prefix}/password"] = ask(:channel_password, nil, String)
32
33
  bot.config["#{prefix}/language"] = ask(:channel_language, lang, String)
33
34
  bot.config["#{prefix}/charset"] = ask(:channel_encoding, server_encoding, String)
34
35
  }
35
36
  user = ask(:admin_user, nil, String, :min => 3)
36
37
  pass = ask(:admin_pass, nil, String, :min => 3)
37
- bot.access.user.create(user, pass, nil, true, :active => true)
38
- user = bot.access.user.create("default_user", nil, nil, false, :active => true)
39
- user.privileges.add(%w[plugin/public])
40
38
 
39
+ # setup basic access data
40
+ admin = bot.access.user.create(user, pass, nil, true, :active => true)
41
+ role = bot.access.role.create("default_role", "This role is applied to every user")
42
+ %w[
43
+ plugin/public
44
+ plugin/core/login
45
+ plugin/core/logout
46
+ plugin/core/help
47
+ plugin/core/usage
48
+ ].each { |priv| role.privileges.add_oid(priv) }
49
+ default_user = bot.access.user.create("default_user", nil, nil, false, :active => true)
50
+ %w[default_role].each { |role|
51
+ default_user.roles.add_oid(role)
52
+ }
53
+ bot.config["invocation"] = Regexp.escape(ask(:invocation, "!", String, :matching => /\A[!@\#$%^&*_:<>?\/\\~{}()\[\]\-"':;+=,.]\z/))
54
+
55
+ # finish
41
56
  puts
42
57
  say(:how_to_start, :botname => nick, :user => user, :pass => pass)
@@ -1,6 +1,9 @@
1
1
  begin
2
- user = variables.user || variables.botcontrol.user # can be nil
3
- variables.botcontrol.configure_user(user) unless variables.botcontrol.configured?(user)
2
+ user = variables.user || variables.botcontrol.user
3
+ unless variables.botcontrol.configured?(user)
4
+ say :configuring, :user => user
5
+ variables.botcontrol.configure_user(user)
6
+ end
4
7
  Butler.path = variables.botcontrol.butler_path(user)
5
8
  rescue Errno::EACCES
6
9
  say :cant_configure, :user => user, :app => $0
@@ -2,14 +2,15 @@
2
2
  :sudo_user: "You are running 'create' with sudo, botcontrol will create the bot for <%= ENV['SUDO_USER'] %>, continue"
3
3
  :name: "Please choose a name for the bot (alphanumeric characters only)"
4
4
  :delete_existing: "A bot named <%= name %> already exists, do you wish to delete it"
5
- :quicksetup: "Do you wish to do a quick configuration (you can use '<%= $0 %> config <%= name %>' any time)"
6
5
  :server: "Servername to connect to"
7
6
  :port: "Port to connect on"
8
- :connect_delay: "Delay before trying to reconnect"
9
- :connect_tries: "Number of tries to reconnect"
7
+ :serverpass: "The password for the server (empty if none required)"
8
+ :reconnect_delay: "Delay before trying to reconnect"
9
+ :reconnect_tries: "Number of tries to reconnect"
10
10
  :server_encoding: "Main charset-encoding of the server"
11
11
  :language: "The main language"
12
12
  :nick: "Nickname of the bot"
13
+ :nick2: "Alternative nickname"
13
14
  :user: "Username of the bot"
14
15
  :real: "Realname of the bot"
15
16
  :nickpass: "The password for the nick (empty if not registered)"
@@ -20,6 +21,8 @@
20
21
  :channel_encoding: "Charset encoding used in the channel"
21
22
  :admin_user: "Please choose a username for the bot-admin"
22
23
  :admin_pass: "The password for the bot-admin"
24
+ :invocation: "Alternative way to invoke commands (e.g. '!bot help' instead of 'bot, help', leave empty for none)"
23
25
  :how_to_start: |
24
26
  You can now start your bot using '<%= $0 %> start <%= name %>'.
25
27
  You can then authenticate as administrator of the bot in irc using '/msg <%= botname %> login <%= user %> <%= pass %>'.
28
+ :invocation: "Alternative method of calling commands"
@@ -1,2 +1,3 @@
1
1
  ---
2
+ :configuring: "Configuring for '<%= user %>'."
2
3
  :cant_configure: "Can't configure for '<%= user %>', you should run <%= app %> with sudo."
@@ -2,8 +2,8 @@
2
2
  :sudo_user: "You are running 'create' with sudo, botcontrol will create the bot for <%= ENV['SUDO_USER'] %>, continue"
3
3
  :name: "Please choose a name for the bot (alphanumeric characters only)"
4
4
  :delete_existing: "A bot named <%= name %> already exists, do you wish to delete it"
5
- :quicksetup: "Do you wish to do a quick configuration (you can use '<%= $0 %> config <%= name %>' any time)"
6
5
  :server: "Servername to connect to"
6
+ :serverpass: "The password for the server (empty if none required)"
7
7
  :language: "The main language"
8
8
  :channels: "Comma separated list of channels to join on login"
9
9
  :user: "Please choose a username for the bot-admin"
@@ -0,0 +1,7 @@
1
+ ---
2
+ :updating: "Updating plugins and services for '<%= name %>'"
3
+ :update_plugin: "Update plugin <%= name %> from revision #<%= a %> to #<%= b %>"
4
+ :update_service: "Update service <%= name %> from revision #<%= a %> to #<%= b %>"
5
+ :error_copying_plugin: "An error occurred while copying plugin <%= name %>: <%= error %>"
6
+ :error_copying_service: "An error occurred while copying service <%= name %>: <%= error %>"
7
+ :ignoring_invalid_yaml: "Plugin <%= name %> has no or invalid metadata, ignoring."
@@ -0,0 +1,2 @@
1
+ ---
2
+ :username: "The name of the user"
@@ -14,10 +14,11 @@ nick = name
14
14
  bot.config["connections/main/server"] = server=ask(:server, "irc.freenode.org", String, :min => 3)
15
15
  bot.config["connections/main/port"] = 6667
16
16
  bot.config["connections/main/host"] = nil
17
+ bot.config["connections/main/serverpass"] = server=ask(:serverpass, nil, String)
17
18
  bot.config["connections/main/reconnect_delay"] = 60
18
19
  bot.config["connections/main/reconnect_tries"] = -1
19
20
  bot.config["connections/main/charset"] = 'utf-8'
20
- bot.config["connections/main/language"] = lang=ask(:language, "en", String, :matching => /\A#[A-Za-z0-9_-]{2,40}\z/)
21
+ bot.config["connections/main/language"] = lang=ask(:language, "en", String, :matching => /\A[A-Za-z0-9_.-]{2,40}\z/)
21
22
  bot.config["connections/main/nick"] = name
22
23
  bot.config["connections/main/alternative"] = name[0,7]+"_"
23
24
  bot.config["connections/main/user"] = name
@@ -26,13 +27,15 @@ bot.config["connections/main/password"] = ask(:nickpass, nil, String)
26
27
  bot.config["connections/main/identify"] = :auto
27
28
  bot.config["connections/main/channels"] = channels=ask(:channels, (server == "irc.freenode.org" ? ["#butler"] : nil), Array, String, :matching => /\A#[^\0\s,]+\z/)
28
29
  channels.each { |channel|
29
- prefix = "channels/#{server.config_key}/#{channel.config_key}"
30
+ prefix = "channels/#{Configuration.escape(server)}/#{Configuration.escape(channel)}"
30
31
  bot.config["#{prefix}/password"] = nil
31
32
  bot.config["#{prefix}/language"] = lang
32
33
  bot.config["#{prefix}/charset"] = 'utf-8'
33
34
  }
34
35
  user = ask(:user, nil, String, :min => 3)
35
36
  pass = ask(:pass, nil, String, :min => 3)
37
+
38
+ # setup basic access data
36
39
  admin = bot.access.user.create(user, pass, nil, true, :active => true)
37
40
  role = bot.access.role.create("default_role", "This role is applied to every user")
38
41
  %w[
@@ -47,5 +50,6 @@ default_user = bot.access.user.create("default_user", nil, nil, false, :active =
47
50
  default_user.roles.add_oid(role)
48
51
  }
49
52
 
53
+ # finish
50
54
  puts
51
55
  say(:how_to_start, :botname => nick, :user => user, :pass => pass)
@@ -0,0 +1,83 @@
1
+ require 'scriptfile'
2
+
3
+ def revision(plugin)
4
+ revision = YAML.load(ScriptFile.read(plugin))
5
+ (revision && revision[:revision] && revision[:revision][:plugin]) || 0
6
+ rescue ArgumentError # invalid yaml
7
+ nil
8
+ end
9
+
10
+ bots = variables.botname ? [variables.botname] : Butler.list(variables.path)
11
+ bots_path = variables.path.bots
12
+
13
+ # scan global plugins repository, get an array with [path-to-plugin-in-global-repo, plugin-base, revision]
14
+ dirlist = Dir[variables.path.plugin_repository+"/**/*"]
15
+ plugindirs, plugins = dirlist.partition { |filepath| File.directory?(filepath) }
16
+ slice = (variables.path.plugin_repository.length+1)..-1
17
+ plugindirs.map! { |dir| dir[slice] }
18
+ plugins.map! { |plugin|
19
+ [plugin, plugin[slice], revision(plugin)]
20
+ }
21
+ plugins.each { |full, base, revision|
22
+ say(:ignoring_invalid_yaml, :name => base) unless revision
23
+ }
24
+ plugins.reject! { |full, base, revision| !revision }
25
+
26
+
27
+ # scan global services repository, get an array with data to copy
28
+ services = [] # [rdn, name, version, ary_of_files]
29
+ Dir.glob("#{variables.path.service_repository}/*/*/*/service.rb") { |service|
30
+ rdn, name, version = service.match(%r{([^/]+)/([^/]+)/([^/]+)/service\.rb$}).captures
31
+ slice = (File.dirname(service).length+1)..-1
32
+ dirs, files = Dir[File.dirname(service)+'/**/*'].partition { |filepath| File.directory?(filepath) }
33
+ dirs.map! { |file| file[slice] }
34
+ files.map! { |file| file[slice] }
35
+ services << [rdn, name, version, "#{rdn}/#{name}/#{version}", dirs, files]
36
+ }
37
+
38
+ # updating the bots
39
+ bots.each { |name|
40
+ say(:updating, :name => name)
41
+ bot_path = "#{bots_path}/#{name}"
42
+ FileUtils.mkdir_p(plugindirs.map { |dir| "#{bot_path}/plugins/#{dir}" }, :mode => 0755)
43
+
44
+ # update plugins for this bot
45
+ plugins.each { |from, to, rev|
46
+ begin
47
+ full_to = "#{bot_path}/plugins/#{to}"
48
+ if File.exist?(full_to) then
49
+ to_rev = revision(full_to)
50
+ if rev > to_rev then
51
+ next unless prompt(:update_plugin, true,
52
+ :name => to,
53
+ :a => to_rev,
54
+ :b => rev
55
+ )
56
+ end
57
+ #puts("Deleting #{full_to}")
58
+ File.delete(full_to)
59
+ end
60
+ #puts("Copying #{from} to #{full_to}")
61
+ FileUtils.cp(from, "#{full_to}")
62
+ rescue Interrupt; raise # ignore interrupts
63
+ rescue Exception => e
64
+ say(:error_copying_plugin, :name => to, :error => e)
65
+ puts e, *e.backtrace
66
+ end
67
+ }
68
+
69
+ # update services for this bot
70
+ services.each { |rdn, name, version, base, dirs, files|
71
+ begin
72
+ FileUtils.mkdir_p(dirs.map { |dir| "#{bot_path}/services/#{dir}" }, :mode => 0755)
73
+ files.each { |file|
74
+ FileUtils.cp("#{variables.path.service_repository}/#{base}/#{file}", "#{bot_path}/services/#{base}/#{file}")
75
+ }
76
+ rescue Interrupt; raise # ignore interrupts
77
+ rescue Exception => e
78
+ say(:error_copying_service, :name => name, :error => e)
79
+ puts e, *e.backtrace
80
+ end
81
+ }
82
+ }
83
+
@@ -0,0 +1 @@
1
+ response(:ask, :username, nil, String)
@@ -0,0 +1,22 @@
1
+ #--
2
+ # Copyright 2007 by Stefan Rusterholz
3
+ # This code is based on work by Colin Shea.
4
+ # All rights reserved.
5
+ # See LICENSE.txt for permissions.
6
+ #++
7
+
8
+
9
+
10
+ plugin_attribute :count, 0
11
+
12
+ every minute do |event|
13
+ begin
14
+ if @butler.connected? then
15
+ @count += 1
16
+ @butler.irc.write_with_eol "PING :#{@count}"
17
+ end
18
+ rescue Exception => e
19
+ exception(e) # log it
20
+ event.postpone
21
+ end
22
+ end
@@ -0,0 +1,38 @@
1
+ #--
2
+ # Copyright 2007 by Stefan Rusterholz.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+
8
+
9
+ configuration(
10
+ "active" => false,
11
+ "host" => "0.0.0.0",
12
+ "port" => 7776
13
+ )
14
+
15
+
16
+
17
+ def self.on_load
18
+ if @config["active"] then
19
+ @butler.remote.start(@config["host"], @config["port"])
20
+ end
21
+ end
22
+
23
+ __END__
24
+ ---
25
+ :about:
26
+ :mail: "apeiros@gmx.net"
27
+ :version: "1.0.0"
28
+ :author: "Stefan Rusterholz"
29
+ :help:
30
+ en:
31
+ "": |
32
+ Control butlers remote connections server.
33
+ :revision:
34
+ :plugin: 1
35
+ :summary:
36
+ en: "Control butlers remote connections server."
37
+ :usage:
38
+ en: "No commands available."
@@ -17,7 +17,7 @@ def previous(*n)
17
17
  n.empty? ? plugin.state : plugin.state[*n]
18
18
  end
19
19
 
20
- def _0; previous(0); end
20
+ def _; previous(0); end
21
21
  def _1; previous(1); end
22
22
  def _2; previous(2); end
23
23
  def _3; previous(3); end
@@ -33,17 +33,19 @@ def on_trigger
33
33
  result = eval(@message.post_arguments[1])
34
34
  plugin.state.unshift(result)
35
35
  plugin.state.pop
36
+ rescue Interrupt
37
+ raise
36
38
  rescue Exception => e
37
39
  answer(:exception, :exception => e)
38
40
  else
39
- answer(">> "+result.inspect[0,300].split(/\n/).first(3).join("\n"))
41
+ answer(">> "+result.inspect)
40
42
  end
41
43
  end
42
44
 
43
45
  __END__
44
46
  ---
45
47
  :revision:
46
- :plugin: 1
48
+ :plugin: 2
47
49
  :summary:
48
50
  en: Let butler eval a piece of code.
49
51
  :about:
@@ -54,7 +56,7 @@ __END__
54
56
  :exception:
55
57
  en: |
56
58
  Exception <%= exception.class %> '<%= exception.message %>' in:
57
- <%= exception.backtrace.first(3).join("\n") %>
59
+ <%= exception.backtrace.join("\n") %>
58
60
  :usage:
59
61
  en: |
60
62
  ![b]eval![o] *![c(blue)]code![o]
@@ -0,0 +1,93 @@
1
+ #--
2
+ # Copyright 2007 by Stefan Rusterholz.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+
8
+
9
+ extend OnHandlers
10
+
11
+ configuration(
12
+ "active" => false
13
+ )
14
+
15
+ trigger "onhandlers"
16
+
17
+ def on_trigger
18
+ if @message.arguments[1] && @message.arguments[1].downcase == "on" then
19
+ plugin.config["active"] = true
20
+ else
21
+ plugin.config["active"] = false
22
+ end
23
+ end
24
+
25
+ def on_join(listener, user, channel)
26
+ debug("on_join triggered, #{user} joined #{channel}") if plugin.config["active"]
27
+ end
28
+ def on_privmsg(listener, user, text)
29
+ debug("on_privmsg triggered, #{user} wrote #{text}") if plugin.config["active"]
30
+ end
31
+ def on_notice(listener, user, text)
32
+ debug("on_notice triggered, #{user} wrote #{text}") if plugin.config["active"]
33
+ end
34
+ def on_nick(listener, user, old_nick)
35
+ debug("on_nick triggered, #{user} changed his nick from #{old_nick}") if plugin.config["active"]
36
+ end
37
+ def on_topic(listener, user, channel, topic)
38
+ debug("on_topic triggered, #{user} changed topic of #{channel} to #{topic}") if plugin.config["active"]
39
+ end
40
+ def on_part(listener, user, channel, reason)
41
+ debug("on_part triggered, #{user} parted #{channel}") if plugin.config["active"]
42
+ end
43
+ def on_quit(listener, user, reason)
44
+ debug("on_quit triggered, #{user} has quit with #{reason}") if plugin.config["active"]
45
+ end
46
+ def on_kick(listener)
47
+ debug("on_kick triggered with #{@message}") if plugin.config["active"]
48
+ end
49
+ def on_kill(listener)
50
+ debug("on_kill triggered with #{@message}") if plugin.config["active"]
51
+ end
52
+ def on_kline(listener)
53
+ debug("on_kline triggered with #{@message}") if plugin.config["active"]
54
+ end
55
+ def on_invocation(listener)
56
+ debug("on_invocation triggered with #{@message}") if plugin.config["active"]
57
+ end
58
+ def on_ban(listener, *masks)
59
+ debug("on_ban triggered with #{@message}") if plugin.config["active"]
60
+ end
61
+ def on_unban(listener, *masks)
62
+ debug("on_unban triggered with #{@message}") if plugin.config["active"]
63
+ end
64
+ def on_op(listener, *users)
65
+ debug("on_op triggered with #{@message}") if plugin.config["active"]
66
+ end
67
+ def on_deop(listener, *users)
68
+ debug("on_deop triggered with #{@message}") if plugin.config["active"]
69
+ end
70
+ def on_voice(listener, *users)
71
+ debug("on_voice triggered with #{@message}") if plugin.config["active"]
72
+ end
73
+ def on_devoice(listener, *users)
74
+ debug("on_devoice triggered with #{@message}") if plugin.config["active"]
75
+ end
76
+
77
+ __END__
78
+ ---
79
+ :revision:
80
+ :plugin: 2
81
+ :summary:
82
+ en: Testing all possible on_handlers
83
+ :about:
84
+ :mail: "apeiros@gmx.net"
85
+ :version: "1.0.0"
86
+ :author: "Stefan Rusterholz"
87
+ :strings:
88
+ :usage:
89
+ en: "This plugin does not offer a specific interface."
90
+ :help:
91
+ en:
92
+ "": |
93
+ This plugin is meant for diagnostic purposes only.
@@ -7,71 +7,135 @@
7
7
 
8
8
 
9
9
  configuration(
10
- "active" => true
10
+ "out" => false,
11
+ "in" => false,
12
+ "append" => true,
13
+ "time" => "%F %T"
11
14
  )
12
15
 
13
16
  @logfile = nil
14
17
 
15
- def self.on_load(*a)
16
- @logfile = File.open(@butler.path.log+"/rawlog.txt", "a")
17
- @logfile.sync = true
18
+ class <<self
19
+ def on_load(*a)
20
+ @logfile = File.open(@butler.path.log+"/rawlog.txt", @config["append"] ? "ab" : "wb")
21
+ @lock = Mutex.new
22
+ @logfile.sync = true
23
+ @log_listener = nil
24
+ activate
25
+ end
26
+
27
+ def activate
28
+ if @config["in"] then
29
+ @log_listener = subscribe(nil, 10) { |listener, message|
30
+ @lock.synchronize {
31
+ @logfile.puts("-> #{Time.now.strftime(@config['time'])} #{message.raw.inspect}") unless @logfile.closed?
32
+ }
33
+ }
34
+ else
35
+ @log_listener.unsubscribe if @log_listener
36
+ end
37
+ @butler.irc.log_out = @config["out"] ? self : nil
38
+ end
39
+
40
+ def puts(*messages)
41
+ @lock.synchronize {
42
+ messages.each { |message|
43
+ @logfile.puts("<- #{Time.now.strftime(@config['time'])} #{message.inspect}")
44
+ } unless @logfile.closed?
45
+ }
46
+ end
47
+
48
+ def on_unload(*a)
49
+ @lock.synchronize {
50
+ @butler.irc.log_out = nil
51
+ @logfile.close
52
+ }
53
+ end
18
54
  end
19
55
 
20
- def self.on_unload(*a)
21
- @logfile.close
56
+ def on_status(params)
57
+ answer(:status, :status_in => plugin.config["in"], :status_out => plugin.config["out"])
22
58
  end
23
59
 
24
- subscribe(nil, 10) { |listener, message|
25
- if @config["active"] && @logfile then
26
- @logfile.puts("#{Time.now.strftime('%F %T')}> #{message.raw}")
27
- end
28
- }
29
-
30
- trigger "rawlog"
31
-
32
- def on_trigger
33
- arg = @message.arguments[1] && @message.arguments[1].downcase
34
- case arg
35
- when nil
36
- usage
37
-
38
- when _(:on)
39
- plugin.config["active"] = true
40
- answer(:activated)
60
+ def on_wipe(params)
61
+ plugin.logfile.truncate
62
+ answer :wiped
63
+ end
41
64
 
42
- when _(:off)
43
- plugin.config["active"] = false
44
- answer(:deactivated)
65
+ def on_activate(params)
66
+ if params["in"] then
67
+ plugin.config["in"] = true
68
+ answer(:activated_in)
69
+ elsif params["out"] then
70
+ plugin.config["out"] = true
71
+ answer(:activated_out)
72
+ else
73
+ plugin.config["in"] = true
74
+ plugin.config["out"] = true
75
+ answer(:activated_both)
76
+ end
77
+ plugin.activate
78
+ end
45
79
 
80
+ def on_deactivate(params)
81
+ if params["in"] then
82
+ plugin.config["in"] = false
83
+ answer(:deactivated_in)
84
+ elsif params["out"] then
85
+ plugin.config["out"] = false
86
+ answer(:deactivated_out)
87
+ else
88
+ plugin.config["in"] = false
89
+ plugin.config["out"] = false
90
+ answer(:deactivated_both)
46
91
  end
92
+ plugin.activate
47
93
  end
48
94
 
49
95
  __END__
50
96
  ---
51
- :revision:
52
- :configuration: 1
53
- :summary:
54
- en: |
55
- Writes all messages butler receives into a raw log.
56
97
  :about:
57
98
  :mail: "apeiros@gmx.net"
58
99
  :version: "1.0.0"
59
100
  :author: "Stefan Rusterholz"
60
- :strings:
61
- :on:
62
- en: "on"
63
- :off:
64
- en: "off"
65
- :activated:
66
- en: |
67
- Activated raw logging
68
- :deactivated:
69
- en: |
70
- Deactivated raw logging
71
- :usage:
72
- en: |
73
- ![b]rawlog![o] ('on' | 'off')
74
101
  :help:
75
102
  en:
76
103
  "": |
77
104
  Writes all messages butler receives into a raw log.
105
+ :map:
106
+ :on_status:
107
+ en: rawlog status
108
+ :on_wipe:
109
+ en: wipe rawlog
110
+ :on_activate:
111
+ en: activate rawlog [:direction{in,out}]
112
+ :on_deactivate:
113
+ en: deactivate rawlog [:direction{in,out}]
114
+ :revision:
115
+ :configuration: 1
116
+ :strings:
117
+ :status:
118
+ en: |
119
+ Incomming messages are <%= status_in ? '' : 'not ' %>logged, outgoing messages are <%= status_out ? '' : 'not ' %>logged.
120
+ :wiped:
121
+ en: Wiped raw log.
122
+ :activated_in:
123
+ en: Activated raw log for incomming messages.
124
+ :activated_out:
125
+ en: Activated raw log for outgoing messages.
126
+ :activated_both:
127
+ en: Activated raw log for incomming and outgoing messages.
128
+ :deactivated_in:
129
+ en: Deactivated raw log for incomming messages.
130
+ :deactivated_out:
131
+ en: Deactivated raw log for outgoing messages.
132
+ :deactivated_both:
133
+ en: Deactivated raw log for incomming and outgoing messages.
134
+ :summary:
135
+ en: |
136
+ Writes all messages butler receives and/or sends into a raw log.
137
+ :usage:
138
+ en: |
139
+ activate rawlog [in|out]
140
+ deactivate rawlog [in|out]
141
+ wipe rawlog