tkellem 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tkellem (0.9.2)
4
+ tkellem (0.9.3)
5
5
  activerecord (~> 4.0.0.rc2)
6
6
  eventmachine (~> 1.0.3)
7
7
  rails-observers (~> 0.1.1)
@@ -13,8 +13,6 @@ class Bouncer
13
13
  cattr_accessor :plugins
14
14
  self.plugins = []
15
15
 
16
- class Room < Struct.new(:name, :topic, :topic_setter, :topic_time); end
17
-
18
16
  def initialize(network_user)
19
17
  @network_user = network_user
20
18
  @user = network_user.user
@@ -24,7 +22,7 @@ class Bouncer
24
22
  # maps { client_conn => state_hash }
25
23
  @active_conns = {}
26
24
  @welcomes = []
27
- @rooms = {}
25
+ @rooms = Room.where(network_user_id: network_user.id).each_with_object({}) { |room,h| h[room.name] = room }
28
26
  # maps { client_conn => away_status_or_nil }
29
27
  @away = {}
30
28
  # plugin data
@@ -114,10 +112,18 @@ class Bouncer
114
112
  ready! if msg.command == "376" # end of MOTD
115
113
  false
116
114
  when 'JOIN'
117
- @rooms[msg.args.first] = Room.new(msg.args.first) if msg.target_user == @nick
115
+ room_name = msg.args.first
116
+ if msg.target_user == @nick && !@rooms[room_name]
117
+ room = Room.create!(network_user_id: network_user.id, name: room_name)
118
+ @rooms[room_name] = room
119
+ end
118
120
  true
119
121
  when 'PART'
120
- @rooms.delete(msg.args.first) if msg.target_user == @nick
122
+ room_name = msg.args.first
123
+ if msg.target_user == @nick
124
+ room = @rooms.delete(room_name)
125
+ room.destroy
126
+ end
121
127
  true
122
128
  when 'TOPIC'
123
129
  if room = @rooms[msg.args.first]
@@ -223,7 +229,7 @@ class Bouncer
223
229
  end
224
230
 
225
231
  def ready!
226
- @rooms.each_key do |room|
232
+ @rooms.each_value do |room|
227
233
  send_msg("JOIN #{room.name}")
228
234
  end
229
235
 
@@ -0,0 +1,10 @@
1
+ class AddRooms < ActiveRecord::Migration
2
+ def self.up
3
+ create_table 'rooms' do |t|
4
+ t.integer :network_user_id
5
+ t.string :name
6
+ end
7
+ end
8
+ end
9
+
10
+
@@ -0,0 +1,6 @@
1
+ class Room < ActiveRecord::Base
2
+ # these aren't persisted, we just grab them on connect
3
+ attr_accessor :topic, :topic_setter, :topic_time
4
+
5
+ belongs_to :network_user
6
+ end
@@ -204,7 +204,7 @@ class Backlog
204
204
 
205
205
  def send_backlog(conn, ctx_name, stream)
206
206
  while line = stream.gets
207
- timestamp, msg = parse_line(line, ctx_name)
207
+ timestamp, msg = self.class.parse_line(line, ctx_name)
208
208
  next unless msg
209
209
  privmsg = msg.args.first[0] != '#'[0]
210
210
  if msg.prefix
@@ -232,7 +232,7 @@ class Backlog
232
232
  end
233
233
  end
234
234
 
235
- def parse_line(line, ctx_name)
235
+ def self.parse_line(line, ctx_name)
236
236
  timestamp = Time.parse(line[0, 19])
237
237
  case line[20..-1]
238
238
  when %r{^> (\* )?(.+)$}
@@ -241,7 +241,7 @@ class Backlog
241
241
  msg.ctcp = 'ACTION'
242
242
  end
243
243
  return timestamp, msg
244
- when %r{^< (\* )?([^:]+): (.+)$}
244
+ when %r{^< (\* )?([^ ]+): (.+)$}
245
245
  msg = IrcMessage.new($2, 'PRIVMSG', [ctx_name, $3])
246
246
  if $1 == '* '
247
247
  msg.ctcp = 'ACTION'
@@ -11,6 +11,7 @@ require 'tkellem/models/host'
11
11
  require 'tkellem/models/listen_address'
12
12
  require 'tkellem/models/network'
13
13
  require 'tkellem/models/network_user'
14
+ require 'tkellem/models/room'
14
15
  require 'tkellem/models/setting'
15
16
  require 'tkellem/models/user'
16
17
 
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Tkellem
3
- VERSION = "0.9.2"
3
+ VERSION = "0.9.3"
4
4
  end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'tkellem/irc_message'
3
+ require 'time'
4
+
5
+ include Tkellem
6
+
7
+ describe Backlog do
8
+ describe '.parse_line' do
9
+ it "should parse other user names" do
10
+ def cmp(username, message = "test 1 2")
11
+ timestamp, msg = Backlog.parse_line(%{10-07-2013 10:10:36 < #{username}: #{message}}, '#testroom')
12
+ expected = IrcMessage.new(username, 'PRIVMSG', ['#testroom', message])
13
+ msg.should == expected
14
+ end
15
+
16
+ cmp("dude")
17
+ cmp("dude@some/fancy/web/addr.blah")
18
+ cmp("dude!~dude@12:34:56")
19
+ cmp("dude!~dude@12:34:56", "hey dude: test")
20
+ end
21
+ end
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tkellem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 0.9.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-28 00:00:00.000000000 Z
12
+ date: 2013-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
@@ -115,11 +115,13 @@ files:
115
115
  - lib/tkellem/migrations/002_at_connect_columns.rb
116
116
  - lib/tkellem/migrations/003_settings.rb
117
117
  - lib/tkellem/migrations/004_add_backlog_positions.rb
118
+ - lib/tkellem/migrations/005_add_rooms.rb
118
119
  - lib/tkellem/models/backlog_position.rb
119
120
  - lib/tkellem/models/host.rb
120
121
  - lib/tkellem/models/listen_address.rb
121
122
  - lib/tkellem/models/network.rb
122
123
  - lib/tkellem/models/network_user.rb
124
+ - lib/tkellem/models/room.rb
123
125
  - lib/tkellem/models/setting.rb
124
126
  - lib/tkellem/models/user.rb
125
127
  - lib/tkellem/plugins/backlog.rb
@@ -135,6 +137,7 @@ files:
135
137
  - spec/bouncer_connection_spec.rb
136
138
  - spec/irc_message_spec.rb
137
139
  - spec/irc_server_spec.rb
140
+ - spec/plugins/backlog_spec.rb
138
141
  - spec/spec_helper.rb
139
142
  - tkellem.gemspec
140
143
  homepage: http://github.com/codekitchen/tkellem
@@ -151,7 +154,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
151
154
  version: '0'
152
155
  segments:
153
156
  - 0
154
- hash: -1609570308087987502
157
+ hash: -2551777789450779146
155
158
  required_rubygems_version: !ruby/object:Gem::Requirement
156
159
  none: false
157
160
  requirements:
@@ -160,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
160
163
  version: '0'
161
164
  segments:
162
165
  - 0
163
- hash: -1609570308087987502
166
+ hash: -2551777789450779146
164
167
  requirements: []
165
168
  rubyforge_project:
166
169
  rubygems_version: 1.8.23
@@ -172,4 +175,5 @@ test_files:
172
175
  - spec/bouncer_connection_spec.rb
173
176
  - spec/irc_message_spec.rb
174
177
  - spec/irc_server_spec.rb
178
+ - spec/plugins/backlog_spec.rb
175
179
  - spec/spec_helper.rb