tkellem 0.8.0 → 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -17,11 +17,9 @@ functionality.
17
17
 
18
18
  This will have to do as a quickstart guide, for now:
19
19
 
20
- $ git clone git://github.com/codekitchen/tkellem.git
21
- $ cd tkellem
22
- $ bundle install
23
- $ bundle exec bin/tkellem start
24
- $ bundle exec bin/tkellem admin
20
+ $ gem install tkellem
21
+ $ tkellem start
22
+ $ tkellem admin
25
23
  > help
26
24
  > listen ircs://0.0.0.0:8765
27
25
  > user --add <my-name> --admin
@@ -37,3 +35,7 @@ Then connect to tkellem with an irc client:
37
35
  nickname: <my-name>
38
36
  login: <my-name>@freenode
39
37
  server password: <my-new-password>
38
+
39
+ Note that all config and log files are stored in ~/.tkellem of the user
40
+ you run `tkellem start` as. You also need to run `tkellem admin` as this
41
+ same user, in order to have access to the admin console.
@@ -205,6 +205,14 @@ class Bouncer
205
205
 
206
206
  # We're all initialized, allow connections
207
207
  @connected = true
208
+
209
+ @network_user.at_connect.each do |line|
210
+ cmd, args = line.split(' ', 2)
211
+ next unless cmd && args && cmd[0] == '/'[0]
212
+ msg = IrcMessage.parse("#{cmd[1..-1].upcase} #{args}")
213
+ send_msg(msg)
214
+ end
215
+
208
216
  @waiting_clients.each do |client|
209
217
  client.say_as_tkellem("Now connected.")
210
218
  connect_client(client)
@@ -0,0 +1,7 @@
1
+ class AtConnectColumns < ActiveRecord::Migration
2
+ def self.up
3
+ add_column 'networks', 'at_connect', 'text'
4
+ add_column 'network_users', 'at_connect', 'text'
5
+ end
6
+ end
7
+
@@ -7,6 +7,12 @@ class Network < ActiveRecord::Base
7
7
  # can join them.
8
8
  belongs_to :user
9
9
 
10
+ serialize :at_connect, Array
11
+
12
+ def at_connect
13
+ read_attribute(:at_connect) || []
14
+ end
15
+
10
16
  def public?
11
17
  !user
12
18
  end
@@ -4,9 +4,17 @@ class NetworkUser < ActiveRecord::Base
4
4
  belongs_to :network
5
5
  belongs_to :user
6
6
 
7
+ serialize :at_connect, Array
8
+
7
9
  def nick
8
10
  read_attribute(:nick) || user.name
9
11
  end
12
+
13
+ # we use the network's at_connect until it is modified and overwritten for
14
+ # this specific network user
15
+ def at_connect
16
+ read_attribute(:at_connect).presence || network.at_connect.presence || []
17
+ end
10
18
  end
11
19
 
12
20
  end
@@ -127,9 +127,9 @@ class TkellemBot
127
127
  register(name)
128
128
  cattr_accessor :model
129
129
  self.model = model
130
- options.set('add', '--add', '-a', "Add a #{model.name}")
131
- options.set('remove', '--remove', '-r', "Remove a #{model.name}")
132
- options.set('list', '--list', '-l', "List the current #{model.name.pluralize}")
130
+ options.set('add', '--add', '-a', "Add a #{model}")
131
+ options.set('remove', '--remove', '-r', "Remove a #{model}")
132
+ options.set('list', '--list', '-l', "List the current #{model.to_s.pluralize}")
133
133
  end
134
134
 
135
135
  def show(m)
@@ -254,6 +254,39 @@ class TkellemBot
254
254
  end
255
255
  end
256
256
 
257
+ class AtConnectCommand < CRUDCommand
258
+ register_crud 'atconnect', 'At-Connect'
259
+
260
+ # options.set('network', '--network=network', '-n', 'Network to modify at-connect on')
261
+ options.set('username', '--user=username', '-u', 'Modify a user-specific network for another user')
262
+
263
+ def list(args, user, network = nil)
264
+ network_name, network, user = NetworkCommand.get_network(args, user) unless network
265
+ raise(Command::ArgumentError, "No network found") unless network
266
+ r "At connect:"
267
+ network.at_connect.each { |line| r " /#{line}" }
268
+ end
269
+
270
+ def remove(args, user)
271
+ network_name, network, user = NetworkCommand.get_network(args, user)
272
+ raise(Command::ArgumentError, "No network found") unless network
273
+ line = args[:rest].join(' ')
274
+ network.at_connect = network.at_connect.reject { |l| l == line }
275
+ network.save
276
+ list(args, user, network)
277
+ end
278
+
279
+ def add(args, user)
280
+ network_name, network, user = NetworkCommand.get_network(args, user)
281
+ raise(Command::ArgumentError, "No network found") unless network
282
+ line = args[:rest].join(' ')
283
+ raise(Command::ArgumentError, "atconnect commands must start with a /") unless line[0] == '/'[0]
284
+ network.at_connect = network.at_connect + [line]
285
+ network.save
286
+ list(args, user, network)
287
+ end
288
+ end
289
+
257
290
  class NetworkCommand < CRUDCommand
258
291
  register_crud 'network', Host
259
292
 
@@ -269,7 +302,7 @@ class TkellemBot
269
302
  "#{host.network.name}#{' (public)' if host.network.public?} " + host.network.hosts.map { |h| "[#{h}]" }.join(' ')
270
303
  end
271
304
 
272
- def get_network(args, user)
305
+ def self.get_network(args, user)
273
306
  network_name = args[:rest].shift
274
307
  if args['username']
275
308
  if Command.admin_user?(user)
@@ -281,12 +314,16 @@ class TkellemBot
281
314
 
282
315
  network = Network.first(:conditions => { :name => network_name, :user_id => user.id }) if user
283
316
  network ||= Network.first(:conditions => { :name => network_name, :user_id => nil })
284
- if network && network.public? && !self.class.admin_user?(user)
317
+ if network && network.public? && !admin_user?(user)
285
318
  raise Command::ArgumentError, "Only admins can modify public networks"
286
319
  end
287
320
  return network_name, network, user
288
321
  end
289
322
 
323
+ def get_network(args, user)
324
+ self.class.get_network(args, user)
325
+ end
326
+
290
327
  def remove(args, user)
291
328
  network_name, network, user = get_network(args, user)
292
329
  if network
@@ -1,3 +1,3 @@
1
1
  module Tkellem
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: tkellem
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.8.0
5
+ version: 0.8.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Brian Palmer
@@ -136,6 +136,7 @@ files:
136
136
  - lib/tkellem/irc_message.rb
137
137
  - lib/tkellem/irc_server.rb
138
138
  - lib/tkellem/migrations/001_init_db.rb
139
+ - lib/tkellem/migrations/002_at_connect_columns.rb
139
140
  - lib/tkellem/models/host.rb
140
141
  - lib/tkellem/models/listen_address.rb
141
142
  - lib/tkellem/models/network.rb