slackbot_frd 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/slackbot-frd +87 -5
- data/lib/slackbot_frd/lib/log.rb +2 -1
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5bb68aca99439d177c185daf2ca3009ed2926868
|
4
|
+
data.tar.gz: 8d35953ceec1d879df5d1cd0735cbef50b63f439
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6e04365893893331d10d2a7f4c31cf9f23e78d9a9d18263b051d41a889ad5760133bf376aa28f8816f6518aae187166f8302ec5b658a4066bf69af9fba86177
|
7
|
+
data.tar.gz: f34fed3e5bb0ff20ac207834f17838160322cdc295c52cbc342992319806b597b39751184966e7695b865bdddb7918905e599c99b6217db36c300aa441c1129c
|
data/bin/slackbot-frd
CHANGED
@@ -3,6 +3,8 @@
|
|
3
3
|
require 'thor'
|
4
4
|
require 'json'
|
5
5
|
|
6
|
+
require 'active_support/core_ext/string'
|
7
|
+
|
6
8
|
require 'slackbot_frd/initializer/bot_starter'
|
7
9
|
require 'slackbot_frd/lib/slack_connection'
|
8
10
|
require 'slackbot_frd/lib/bot'
|
@@ -45,8 +47,31 @@ class SlackbotFrdBin < Thor
|
|
45
47
|
long_desc <<-LONGDESC
|
46
48
|
new will generate a skeleton for a new slackbot_frd project
|
47
49
|
LONGDESC
|
48
|
-
|
49
|
-
|
50
|
+
option :nospec, type: :boolean, aliases: 'n'
|
51
|
+
def new(proj_name)
|
52
|
+
if Dir.exists?(proj_name)
|
53
|
+
puts "Directory '#{proj_name}' already exists".red
|
54
|
+
return
|
55
|
+
end
|
56
|
+
Dir.mkdir(proj_name)
|
57
|
+
Dir.chdir(proj_name)
|
58
|
+
genconfig
|
59
|
+
File.write("Gemfile", <<-GEMFILE.strip_heredoc)
|
60
|
+
source "https://rubygems.org"
|
61
|
+
|
62
|
+
gem "slackbot_frd"
|
63
|
+
GEMFILE
|
64
|
+
Dir.mkdir("bots")
|
65
|
+
write_example_bot("bots/example_bot.rb")
|
66
|
+
Dir.mkdir("lib")
|
67
|
+
|
68
|
+
unless options[:nospec]
|
69
|
+
File.append("Gemfile", <<-GEMFILE.strip_heredoc)
|
70
|
+
|
71
|
+
gem "rspec", "~> 3.2"
|
72
|
+
GEMFILE
|
73
|
+
Dir.mkdir("spec")
|
74
|
+
end
|
50
75
|
end
|
51
76
|
|
52
77
|
desc "genconfig", "Generate a skeleton config file"
|
@@ -55,7 +80,7 @@ class SlackbotFrdBin < Thor
|
|
55
80
|
can be customized
|
56
81
|
LONGDESC
|
57
82
|
def genconfig
|
58
|
-
File.write(config_file_location, <<-CONFIG_FILE_SKELETON)
|
83
|
+
File.write(config_file_location, <<-CONFIG_FILE_SKELETON.strip_heredoc)
|
59
84
|
{
|
60
85
|
"token" : "<put-token-here>",
|
61
86
|
"botdir" : ".",
|
@@ -77,8 +102,10 @@ class SlackbotFrdBin < Thor
|
|
77
102
|
LONGDESC
|
78
103
|
option :daemonize, type: :boolean, aliases: 'd'
|
79
104
|
option :botdir, type: :string, aliases: 'b'
|
80
|
-
option 'config-file'.to_sym, type: :string, aliases: 'c'
|
81
105
|
option :token, type: :string, aliases: 't'
|
106
|
+
option 'config-file', type: :string, aliases: 'c'
|
107
|
+
option 'log-level', type: :string, aliases: 'll'
|
108
|
+
option 'log-file', type: :string, aliases: 'lf'
|
82
109
|
def start(*bots)
|
83
110
|
if running?(watcher_pid)
|
84
111
|
SlackbotFrd::Log.warn("Already running. Not starting again")
|
@@ -88,7 +115,7 @@ class SlackbotFrdBin < Thor
|
|
88
115
|
delete_pid_files
|
89
116
|
delfile(ERROR_FILE)
|
90
117
|
|
91
|
-
config_file = options['config-file'
|
118
|
+
config_file = options['config-file']
|
92
119
|
config_file = config_file_location unless config_file
|
93
120
|
json = config_file_json(config_file) if config_file
|
94
121
|
json ||= {}
|
@@ -105,8 +132,35 @@ class SlackbotFrdBin < Thor
|
|
105
132
|
botdir = File.expand_path(botdir)
|
106
133
|
|
107
134
|
SlackbotFrd::Log.logfile = "#{botdir}/#{LOG_FILE}"
|
135
|
+
SlackbotFrd::Log.logfile = json["log_file"] if json["log_file"]
|
136
|
+
SlackbotFrd::Log.logfile = ENV["SLACKBOT_FRD_LOG_FILE"] if ENV["SLACKBOT_FRD_LOG_FILE"]
|
137
|
+
SlackbotFrd::Log.logfile = options["log-file"] if options['log-file']
|
138
|
+
|
139
|
+
SlackbotFrd::Log.level = :info
|
140
|
+
SlackbotFrd::Log.level = json["log_level"] if json["log_level"]
|
141
|
+
SlackbotFrd::Log.level = ENV["SLACKBOT_FRD_LOG_LEVEL"] if ENV["SLACKBOT_FRD_LOG_LEVEL"]
|
142
|
+
SlackbotFrd::Log.level = options["log-level"] if options['log-level']
|
143
|
+
|
144
|
+
# If we got a number for log level that is valid, just use that
|
145
|
+
if SlackbotFrd::Log.level =~ /\d+/ && SlackbotFrd::Log.levels.values.include?(SlackbotFrd::Log.level.to_i)
|
146
|
+
SlackbotFrd::Log.level = SlackbotFrd::Log.levels.key(SlackbotFrd::Log.level.to_i)
|
147
|
+
else
|
148
|
+
SlackbotFrd::Log.level = SlackbotFrd::Log.level.to_sym
|
149
|
+
end
|
150
|
+
|
151
|
+
if !SlackbotFrd::Log.levels.keys.include?(SlackbotFrd::Log.level) &&
|
152
|
+
!SlackbotFrd::Log.levels.values.include?(SlackbotFrd::Log.level)
|
153
|
+
setval = SlackbotFrd::Log.level
|
154
|
+
SlackbotFrd::Log.level = :info
|
155
|
+
SlackbotFrd::Log.error("Invalid log level '#{setval}'. Possible levels: #{SlackbotFrd::Log.levels.keys.map(&:to_s).join(" | ")}")
|
156
|
+
return
|
157
|
+
end
|
158
|
+
|
108
159
|
SlackbotFrd::Log.info("Logging to file '#{SlackbotFrd::Log.logfile}'")
|
109
160
|
|
161
|
+
SlackbotFrd::Log.warn("Logging to file '#{SlackbotFrd::Log.logfile}'")
|
162
|
+
SlackbotFrd::Log.warn("Logging level set to '#{SlackbotFrd::Log.level}'")
|
163
|
+
|
110
164
|
token = json["token"]
|
111
165
|
token = ENV["SLACKBOT_FRD_TOKEN"] if ENV["SLACKBOT_FRD_TOKEN"]
|
112
166
|
token = options[:token] if options[:token]
|
@@ -248,6 +302,34 @@ class SlackbotFrdBin < Thor
|
|
248
302
|
delfile(PID_FILE_WATCHER)
|
249
303
|
delfile(PID_FILE_CONNECTION)
|
250
304
|
end
|
305
|
+
|
306
|
+
private
|
307
|
+
def write_example_bot(file)
|
308
|
+
File.write(file, <<-EXAMPLE_BOT.strip_heredoc)
|
309
|
+
require 'slackbot_frd'
|
310
|
+
|
311
|
+
# Subclass SlackbotFrd::Bot so that slackbot-frd start runs our bot
|
312
|
+
class ExampleBot < SlackbotFrd::Bot
|
313
|
+
def add_callbacks(slack_connection)
|
314
|
+
# When a user sends a message, echo that message back in reverse
|
315
|
+
slack_connection.on_message do |user, channel, message|
|
316
|
+
slack_connection.send_message(channel, message.reverse)
|
317
|
+
end
|
318
|
+
|
319
|
+
# When a user joins a channel, greet that user as a bot
|
320
|
+
slack_connection.on_channel_joined do |user, channel|
|
321
|
+
slack_connection.send_message_as_user(
|
322
|
+
channel,
|
323
|
+
":skull: ohai \#{user}, welcome to #\#{channel}! :ghost:",
|
324
|
+
"Graveyard Greeting Bot",
|
325
|
+
":graveyard:",
|
326
|
+
true
|
327
|
+
)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
EXAMPLE_BOT
|
332
|
+
end
|
251
333
|
end
|
252
334
|
|
253
335
|
SlackbotFrdBin.start(ARGV)
|
data/lib/slackbot_frd/lib/log.rb
CHANGED
@@ -3,11 +3,12 @@ require 'colorize'
|
|
3
3
|
module SlackbotFrd
|
4
4
|
class Log
|
5
5
|
@levels = {verbose: 1, debug: 2, info: 3, warn: 4, error: 5}
|
6
|
-
@default_level = :
|
6
|
+
@default_level = :info
|
7
7
|
|
8
8
|
class << self
|
9
9
|
attr_writer :level
|
10
10
|
attr_accessor :logfile
|
11
|
+
attr_reader :levels
|
11
12
|
end
|
12
13
|
|
13
14
|
def self.level
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slackbot_frd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Porter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: ptools
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.3'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.3'
|
111
125
|
- !ruby/object:Gem::Dependency
|
112
126
|
name: byebug
|
113
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -190,3 +204,4 @@ specification_version: 4
|
|
190
204
|
summary: slackbot_frd provides a dirt-simple framework for implementing one or more
|
191
205
|
slack bots
|
192
206
|
test_files: []
|
207
|
+
has_rdoc:
|