wesabot 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/wesabot +22 -2
- data/config/wesabot.yml.sample +2 -1
- data/lib/campfire/configuration.rb +2 -1
- data/lib/campfire/polling_bot/plugin.rb +16 -1
- data/lib/campfire/polling_bot/plugins/airbrake/airbrake_plugin.rb +1 -0
- data/lib/campfire/polling_bot/plugins/deploy/deploy_plugin.rb +2 -1
- data/lib/campfire/polling_bot/plugins/tweet/tweet_plugin.rb +1 -0
- data/lib/campfire/sample_plugin.rb +30 -19
- data/lib/campfire/version.rb +1 -1
- metadata +4 -4
data/bin/wesabot
CHANGED
@@ -23,6 +23,16 @@ config = Campfire::Configuration.new
|
|
23
23
|
daemonize = false
|
24
24
|
pidfile = nil
|
25
25
|
|
26
|
+
# if there's an /etc/wesabot directory, set that as the default config
|
27
|
+
# location, and load wesabot.yml if it exists
|
28
|
+
DEFAULT_CONFIG_DIR = "/etc/wesabot" # yeah, screw Windows
|
29
|
+
if File.directory?(DEFAULT_CONFIG_DIR) and File.readable?(DEFAULT_CONFIG_DIR)
|
30
|
+
if File.readable?(wesabot_config = File.join(DEFAULT_CONFIG_DIR, "wesabot.yml"))
|
31
|
+
config = Campfire::FileConfiguration.new(wesabot_config)
|
32
|
+
end
|
33
|
+
config.config_dir = DEFAULT_CONFIG_DIR
|
34
|
+
end
|
35
|
+
|
26
36
|
# get configuration from ARGV
|
27
37
|
optparse = OptionParser.new do |opts|
|
28
38
|
opts.banner = "Usage: #{File.basename($0)} [options]"
|
@@ -30,12 +40,22 @@ optparse = OptionParser.new do |opts|
|
|
30
40
|
opts.separator ""
|
31
41
|
opts.separator "Options:"
|
32
42
|
|
43
|
+
opts.on("--config-dir DIR", "Configuration directory for wesabot and plugins") do |path|
|
44
|
+
if File.directory?(path) and File.readable?(path)
|
45
|
+
# load wesabot.yml if it exists
|
46
|
+
if File.readable?(wesabot_config = File.join(path, "wesabot.yml"))
|
47
|
+
config = Campfire::FileConfiguration.new(wesabot_config)
|
48
|
+
end
|
49
|
+
config.config_dir = path
|
50
|
+
else
|
51
|
+
optparse.warn "Configuration directory #{path} does not exist or is not readable. Ignoring."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
33
55
|
opts.on("-c", "--config FILE", "Configuration file") do |path|
|
34
56
|
config = Campfire::FileConfiguration.new(File.expand_path(path, oldpwd))
|
35
57
|
end
|
36
58
|
|
37
|
-
opts.separator "OR"
|
38
|
-
|
39
59
|
opts.on("-t", "--token TOKEN", "API token (required)") do |api_token|
|
40
60
|
config.api_token = api_token
|
41
61
|
end
|
data/config/wesabot.yml.sample
CHANGED
@@ -20,12 +20,13 @@ module Campfire
|
|
20
20
|
self.logger = data[:logger] || data[:logfile] || Logger.new(STDOUT)
|
21
21
|
self.google_api_key = data[:google_api_key]
|
22
22
|
self.ssl_verify = data[:ssl_verify] != false
|
23
|
+
self.config_dir = data[:config_dir]
|
23
24
|
end
|
24
25
|
|
25
26
|
public
|
26
27
|
|
27
28
|
attr_accessor :api_token, :subdomain, :room, :verbose, :datauri, :logger,
|
28
|
-
:google_api_key, :ssl_verify
|
29
|
+
:google_api_key, :ssl_verify, :config_dir
|
29
30
|
|
30
31
|
alias_method :verbose?, :verbose
|
31
32
|
|
@@ -17,7 +17,8 @@ module Campfire
|
|
17
17
|
gsub(/([[:lower:]\d])([[:upper:]])/,'\1_\2').
|
18
18
|
tr("-", "_").
|
19
19
|
downcase
|
20
|
-
|
20
|
+
config_dir = bot.config.config_dir || self.class.directory
|
21
|
+
filepath = File.join(config_dir, "#{name}.yml")
|
21
22
|
if File.exists?(filepath)
|
22
23
|
self.config = YAML.load_file(filepath)
|
23
24
|
else
|
@@ -79,6 +80,8 @@ module Campfire
|
|
79
80
|
plugin_classes = self.subclasses.sort {|a,b| b.priority <=> a.priority }
|
80
81
|
# initialize plugins
|
81
82
|
plugins = plugin_classes.map { |p_class| p_class.new }
|
83
|
+
# remove any plugins that require a config and don't have one
|
84
|
+
plugins.reject! {|p| p.requires_config? and p.config.empty?}
|
82
85
|
return plugins
|
83
86
|
end
|
84
87
|
|
@@ -123,6 +126,18 @@ module Campfire
|
|
123
126
|
self.class.priority
|
124
127
|
end
|
125
128
|
|
129
|
+
def self.requires_config(flag = true)
|
130
|
+
@requires_config = flag
|
131
|
+
end
|
132
|
+
|
133
|
+
def self.requires_config?
|
134
|
+
@requires_config
|
135
|
+
end
|
136
|
+
|
137
|
+
def requires_config?
|
138
|
+
self.class.requires_config?
|
139
|
+
end
|
140
|
+
|
126
141
|
# called from Plugin objects to indicate what kinds of messages they accept
|
127
142
|
# if the :addressed_to_me flag is true, it will only accept messages addressed
|
128
143
|
# to the bot (e.g. "Wes, ____" or "______, Wes")
|
@@ -3,7 +3,8 @@ require 'open-uri'
|
|
3
3
|
# Plugin to get a list of commits that are on deck to be deployed
|
4
4
|
class DeployPlugin < Campfire::PollingBot::Plugin
|
5
5
|
accepts :text_message, :addressed_to_me => true
|
6
|
-
|
6
|
+
requires_config
|
7
|
+
|
7
8
|
def process(message)
|
8
9
|
case message.command
|
9
10
|
when /deploy\s([^\s\!]+)(?:(?: to)? (staging|nine|production))?( with migrations)?/
|
@@ -1,12 +1,14 @@
|
|
1
|
-
# Sample Campfire plugin. Plugins must be placed in the plugins directory in
|
1
|
+
# Sample Campfire plugin. Plugins must be placed in the plugins directory in
|
2
|
+
# order to be loaded.
|
2
3
|
class SamplePlugin < Campfire::PollingBot::Plugin
|
3
|
-
# accept - specify which kinds of messages this plugin accepts. Put each type
|
4
|
-
# You may optionally set :addressed_to_me => true to get only
|
4
|
+
# accept - specify which kinds of messages this plugin accepts. Put each type
|
5
|
+
# on its own line. You may optionally set :addressed_to_me => true to get only
|
6
|
+
# messages addressed to the bot.
|
5
7
|
# For example,
|
6
8
|
# accept :text_message, :addressed_to_me => true
|
7
|
-
# Will only accept text messages that are in the form "<bot name>, ..." or
|
8
|
-
# The body of the message minus the bot name will be
|
9
|
-
# message.
|
9
|
+
# Will only accept text messages that are in the form "<bot name>, ..." or
|
10
|
+
# "... <bot name>". The body of the message minus the bot name will be
|
11
|
+
# returned by the 'command' method of the message.
|
10
12
|
#
|
11
13
|
# Message types are:
|
12
14
|
# - :all - all messages
|
@@ -24,31 +26,40 @@ class SamplePlugin < Campfire::PollingBot::Plugin
|
|
24
26
|
accepts :text_message, :addressed_to_me => true
|
25
27
|
accepts :paste_message
|
26
28
|
|
27
|
-
# priority is used to determine the plugin's order in the plugin queue. A
|
28
|
-
# a higher priority. There are no upper or lower
|
29
|
-
# to 0.
|
29
|
+
# priority is used to determine the plugin's order in the plugin queue. A
|
30
|
+
# higher number represents a higher priority. There are no upper or lower
|
31
|
+
# bounds. If you don't specify a priority, it defaults to 0.
|
30
32
|
|
31
33
|
priority 10
|
32
34
|
|
33
|
-
#
|
35
|
+
# include requires_config if the plugin requires a configuration file, and
|
36
|
+
# shouldn't be loaded if a configuration file can't be found
|
37
|
+
|
38
|
+
requires_config
|
39
|
+
|
40
|
+
# If you need to do any one-time setup when the plugin is initially loaded,
|
41
|
+
# do it here. Optional.
|
34
42
|
def initialize
|
35
43
|
end
|
36
44
|
|
37
|
-
# If your plugin implements the heartbeat method, it will be called every
|
38
|
-
# for activity (currently every 3 seconds),
|
39
|
-
#
|
45
|
+
# If your plugin implements the heartbeat method, it will be called every
|
46
|
+
# time the bot polls the room for activity (currently every 3 seconds),
|
47
|
+
# whether or not there are any new messages. The heartbeat method is optional.
|
48
|
+
# It does not take any parameters.
|
40
49
|
def heartbeat
|
41
50
|
end
|
42
51
|
|
43
|
-
# process is the only method your plugin needs to implement. This is called
|
44
|
-
# has a new message that matches one of the message
|
45
|
-
# for message
|
46
|
-
#
|
52
|
+
# process is the only method your plugin needs to implement. This is called
|
53
|
+
# by the bot whenever it has a new message that matches one of the message
|
54
|
+
# types accepted by the plugin. See Campfire::Message for message
|
55
|
+
# documentation.
|
56
|
+
# If no other plugins should receive the message after this plugin, return
|
57
|
+
# HALT.
|
47
58
|
def process(message)
|
48
59
|
end
|
49
60
|
|
50
|
-
# help is actually functionality provided by another plugin, HelpPlugin. Just
|
51
|
-
# ['command', 'description'] tuples
|
61
|
+
# help is actually functionality provided by another plugin, HelpPlugin. Just
|
62
|
+
# return an array of ['command', 'description'] tuples
|
52
63
|
def help
|
53
64
|
[['some command', 'description of some command'],
|
54
65
|
['some other command', 'description of some other command']]
|
data/lib/campfire/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wesabot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
- 0
|
9
8
|
- 1
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Brad Greenlee
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-09-
|
20
|
+
date: 2011-09-14 00:00:00 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: tinder
|