slacky 0.1 → 0.1.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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- slacky (0.1)
4
+ slacky (0.1.1)
5
5
  dotenv
6
6
  em-cron
7
7
  eventmachine
@@ -31,10 +31,10 @@ GEM
31
31
  multipart-post (>= 1.2, < 3)
32
32
  faraday_middleware (0.10.0)
33
33
  faraday (>= 0.7.4, < 0.10)
34
- faye-websocket (0.10.3)
34
+ faye-websocket (0.10.4)
35
35
  eventmachine (>= 0.12.0)
36
36
  websocket-driver (>= 0.5.1)
37
- gli (2.13.4)
37
+ gli (2.14.0)
38
38
  hashie (3.4.4)
39
39
  i18n (0.7.0)
40
40
  json (1.8.3)
@@ -43,7 +43,7 @@ GEM
43
43
  parse-cron (0.1.4)
44
44
  pg (0.18.4)
45
45
  rake (11.1.2)
46
- slack-ruby-client (0.7.2)
46
+ slack-ruby-client (0.7.3)
47
47
  activesupport
48
48
  faraday
49
49
  faraday_middleware
@@ -56,7 +56,7 @@ GEM
56
56
  thread_safe (~> 0.1)
57
57
  tzinfo-data (1.2016.4)
58
58
  tzinfo (>= 1.0.0)
59
- websocket-driver (0.6.3)
59
+ websocket-driver (0.6.4)
60
60
  websocket-extensions (>= 0.1.0)
61
61
  websocket-extensions (0.1.2)
62
62
 
@@ -8,8 +8,6 @@ module Slacky
8
8
  attr_reader :client, :config, :slack_id
9
9
 
10
10
  def initialize(config)
11
- puts "#{config.name} is starting up..."
12
-
13
11
  @config = config
14
12
  @restarts = []
15
13
  @command_handlers = []
@@ -42,9 +40,6 @@ module Slacky
42
40
 
43
41
  Channel.bot = self
44
42
  Message.bot = self
45
-
46
- populate_users
47
- populate_channels
48
43
  end
49
44
 
50
45
  def web_client
@@ -133,6 +128,12 @@ module Slacky
133
128
  end
134
129
 
135
130
  def run
131
+ @config.log "#{config.name} is starting up..."
132
+ puts "#{config.name} is starting up..."
133
+
134
+ populate_users
135
+ populate_channels
136
+
136
137
  @bookkeeper.keep_the_books
137
138
 
138
139
  @client.on :message do |data|
@@ -2,12 +2,11 @@ module Slacky
2
2
  class CLI
3
3
  attr_reader :bot
4
4
 
5
- def initialize(name, opts)
5
+ def initialize(name, bot_class, opts)
6
6
  throw "CLI must be passed a name" unless name
7
7
  @options = { :verbose => false }.merge opts
8
8
  config = Config.new name
9
- @bot = Bot.new config
10
- daemon = Daemon.new config, bot
9
+ daemon = Daemon.new config, bot_class
11
10
  @service = Service.new config, daemon
12
11
  end
13
12
 
@@ -12,11 +12,14 @@ module Slacky
12
12
  Dotenv.load ".env", "#{config_dir}/.env"
13
13
  FileUtils.mkdir config_dir unless File.directory? config_dir
14
14
  @pid_file = "#{config_dir}/pid"
15
- @db = PG.connect(db_connect_params)
16
- User.db = @db
17
- User.initialize_table
18
-
19
15
  @timestamps = {}
16
+ User.config = self
17
+ end
18
+
19
+ def db
20
+ db = PG.connect db_connect_params
21
+ db.exec 'set client_min_messages = warning'
22
+ db
20
23
  end
21
24
 
22
25
  def down_name
@@ -1,9 +1,9 @@
1
1
  module Slacky
2
2
  class Daemon
3
3
 
4
- def initialize(config, bot)
4
+ def initialize(config, bot_class)
5
5
  @config = config
6
- @bot = bot
6
+ @bot_class = bot_class
7
7
  @active = true
8
8
  @running = false
9
9
  end
@@ -20,8 +20,12 @@ module Slacky
20
20
  end
21
21
 
22
22
  begin
23
- @slackthread = Thread.new { @bot.run }
24
- run @bot
23
+ @slackthread = Thread.new do
24
+ bot = Bot.new @config
25
+ bot.run
26
+ @bot_class.new bot
27
+ end
28
+ run
25
29
  rescue => e
26
30
  @config.log "Unexpected error", e
27
31
  ensure
@@ -35,11 +39,9 @@ module Slacky
35
39
 
36
40
  private
37
41
 
38
- def run(slackbot)
42
+ def run
39
43
  @config.log "#{@config.name} is running."
40
44
  while active? do
41
- # TODO: handle timed tasks
42
- #slackbot.ask_all if time.min % 10 == 0 # every 10 minutes
43
45
  sleep 0.5
44
46
  end
45
47
  @config.log "#{@config.name} got killed"
@@ -5,18 +5,25 @@ module Slacky
5
5
  attr_accessor :username, :slack_id, :slack_im_id, :first_name, :last_name, :email, :timezone, :presence, :data
6
6
  attr_reader :tz
7
7
 
8
- @@decorator = @@db = nil
8
+ @@decorator = @@config = @@db = nil
9
9
 
10
10
  def self.decorator=(decorator)
11
11
  @@decorator = decorator
12
12
  end
13
13
 
14
- def self.db=(db)
15
- @@db = db
14
+ def self.config=(config)
15
+ @@config = config
16
+ end
17
+
18
+ def self.db
19
+ return @@db if @@db
20
+ @@db = @@config.db
21
+ initialize_table
22
+ @@db
16
23
  end
17
24
 
18
25
  def self.initialize_table
19
- @@db.exec <<-SQL
26
+ self.db.exec <<-SQL
20
27
  create table if not exists users (
21
28
  username varchar(64) not null,
22
29
  slack_id varchar(20) not null,
@@ -33,9 +40,9 @@ SQL
33
40
 
34
41
  def self.find(user)
35
42
  return user.map { |u| User.find u }.compact if user.is_a? Array
36
- result = @@db.exec_params "select * from users where slack_id = $1", [ user ]
43
+ result = self.db.exec_params "select * from users where slack_id = $1", [ user ]
37
44
  if result.ntuples == 0
38
- result = @@db.exec_params "select * from users where username = $1", [ user ]
45
+ result = self.db.exec_params "select * from users where username = $1", [ user ]
39
46
  end
40
47
  return nil if result.ntuples == 0
41
48
 
@@ -77,10 +84,10 @@ SQL
77
84
  end
78
85
 
79
86
  def save
80
- @@db.exec_params "delete from users where slack_id = $1", [ @slack_id ]
81
- @@db.exec_params "insert into users (username, slack_id, slack_im_id, first_name, last_name, email, timezone, presence, data)
82
- values ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
83
- [ @username, @slack_id, @slack_im_id, @first_name, @last_name, @email, @timezone, @presence, JSON.dump(@data) ]
87
+ User.db.exec_params "delete from users where slack_id = $1", [ @slack_id ]
88
+ User.db.exec_params "insert into users (username, slack_id, slack_im_id, first_name, last_name, email, timezone, presence, data)
89
+ values ($1, $2, $3, $4, $5, $6, $7, $8, $9)",
90
+ [ @username, @slack_id, @slack_im_id, @first_name, @last_name, @email, @timezone, @presence, JSON.dump(@data) ]
84
91
  self
85
92
  end
86
93
 
@@ -1,3 +1,3 @@
1
1
  module Slacky
2
- VERSION = "0.1"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slacky
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -226,7 +226,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
226
226
  version: '0'
227
227
  segments:
228
228
  - 0
229
- hash: -3373873093616992315
229
+ hash: 1909049652841046300
230
230
  required_rubygems_version: !ruby/object:Gem::Requirement
231
231
  none: false
232
232
  requirements:
@@ -235,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
235
  version: '0'
236
236
  segments:
237
237
  - 0
238
- hash: -3373873093616992315
238
+ hash: 1909049652841046300
239
239
  requirements: []
240
240
  rubyforge_project:
241
241
  rubygems_version: 1.8.23