libfchat 1.2 → 1.3

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.
@@ -13,6 +13,7 @@ module Libfchat
13
13
  require 'libfchat/webapi'
14
14
 
15
15
  class Fchat
16
+ attr_accessor :spam
16
17
  attr_reader :ticket
17
18
  attr_accessor :websocket
18
19
 
@@ -41,6 +42,7 @@ module Libfchat
41
42
  @version = version
42
43
  @users = Hash.new
43
44
  @rooms = Hash.new
45
+ @spam = true
44
46
  end
45
47
 
46
48
  ##
@@ -50,12 +52,33 @@ module Libfchat
50
52
  def method_missing(method_name, *args, &block)
51
53
  # Try to handle all three-letter strings
52
54
  if method_name.to_s[4,7] =~ /[A-Z]{3}/
53
- #puts "Dunno how to handle #{method_name.to_s}"
55
+ return nil
54
56
  else
55
57
  super(method_name,*args,&block)
56
58
  end
57
59
  end
58
60
 
61
+ ##
62
+ # Parse message received from server
63
+ def parse_message(msg)
64
+ type = msg[0,3]
65
+ begin
66
+ data = MultiJson.load(msg[4..-1])
67
+ rescue
68
+ data = MultiJson.load('{}')
69
+ end
70
+
71
+ # Output if spamminess is enabled
72
+ if @spam
73
+ puts "<< #{msg}"
74
+ end
75
+
76
+ begin
77
+ self.send("got_#{type}",data)
78
+ rescue
79
+ end
80
+ end
81
+
59
82
  ##
60
83
  # Login to fchat as a specific user, and start the event machine
61
84
 
@@ -68,7 +91,7 @@ module Libfchat
68
91
 
69
92
  @websocket.onopen = lambda do |event|
70
93
  #When we connect, log in
71
- self.send('IDN',account,character,ticket)
94
+ self.IDN(account, character, ticket)
72
95
  end
73
96
 
74
97
  @websocket.onclose = lambda do |event|
@@ -76,27 +99,23 @@ module Libfchat
76
99
  end
77
100
 
78
101
  @websocket.onmessage = lambda do |event|
79
- type = event.data[0,3]
80
- begin
81
- data = MultiJson.load(event.data[4..-1])
82
- rescue
83
- data = MultiJson.load('{}')
84
- end
85
- puts "<< [#{type}] #{MultiJson.dump(data)}"
86
- begin
87
- self.send("got_#{type}",data)
88
- rescue
89
- end
102
+ self.parse_message(event.data)
90
103
  end
91
104
  }
92
105
  end
93
106
 
94
107
  ##
95
108
  # Generic message sender
96
- def send_message(type,json)
109
+ def send_message(type, json)
97
110
  jsonstr = ::MultiJson.dump(json)
98
111
  msg = "#{type} #{jsonstr}"
99
- puts ">> #{msg}"
112
+ if @spam
113
+ if type == 'IDN'
114
+ json[:ticket] = '[REDACTED]'
115
+ end
116
+ filteredjsonstr = ::MultiJson.dump(json)
117
+ puts ">> #{type} #{filteredjsonstr}"
118
+ end
100
119
  @websocket.send(msg)
101
120
  end
102
121
 
@@ -122,11 +141,11 @@ module Libfchat
122
141
  elsif message['variable'] == 'lfrp_flood'
123
142
  @lfrp_flood = message['value']
124
143
  elsif message['variable'] == 'msg_flood'
125
- @msg_max = message['value']
144
+ @msg_flood = message['value']
126
145
  elsif message['variable'] == 'permissions'
127
146
  @permissions = message['value']
128
147
  else
129
- puts "ERROR: Do not know how to handle VAR #{message}"
148
+ raise "ERROR: Do not know how to handle VAR #{message}"
130
149
  end
131
150
  end
132
151
 
@@ -194,7 +213,6 @@ module Libfchat
194
213
  def got_JCH(message)
195
214
  begin
196
215
  @rooms[message['channel']]['characters'].push(message['character']['identity'])
197
- puts "Someone else joined a room"
198
216
  rescue
199
217
  @rooms[message['channel']] = {
200
218
  'title' => message['title'],
@@ -202,7 +220,6 @@ module Libfchat
202
220
  'characters' => [],
203
221
  'ops' => [],
204
222
  }
205
- puts "I joined a new room"
206
223
  end
207
224
  end
208
225
 
@@ -220,12 +237,6 @@ module Libfchat
220
237
  end
221
238
  end
222
239
 
223
- ##
224
- # Handle user joining chatroom
225
- def got_LCH(message)
226
- @rooms[message['channel']]['characters'].delete(message['character'])
227
- end
228
-
229
240
  ##
230
241
  # Handle user leaving chatroom
231
242
  def got_LCH(message)
@@ -250,7 +261,7 @@ module Libfchat
250
261
  # *This command requires chat op or higher.*
251
262
  def ACB(character)
252
263
  json = {:character => character}
253
- self.send('send_message','ACB',json)
264
+ self.send_message('ACB',json)
254
265
  end
255
266
 
256
267
  ##
@@ -259,7 +270,7 @@ module Libfchat
259
270
  # *This command is admin only.*
260
271
  def AOP(character)
261
272
  json = {:character => character}
262
- self.send('send_message','AOP',json)
273
+ self.send_message('AOP',json)
263
274
  end
264
275
 
265
276
  ##
@@ -268,7 +279,7 @@ module Libfchat
268
279
  # *This command requires chat op or higher.*
269
280
  def AWC(character)
270
281
  json = {:character => character}
271
- self.send('send_message','AWC',json)
282
+ self.send_message('AWC',json)
272
283
  end
273
284
 
274
285
  ##
@@ -276,7 +287,7 @@ module Libfchat
276
287
  # *This command is admin only.*
277
288
  def BRO(message)
278
289
  json = {:message => message}
279
- self.send('send_message','AWC',json)
290
+ self.send_message('AWC',json)
280
291
  end
281
292
 
282
293
  ##
@@ -285,7 +296,7 @@ module Libfchat
285
296
  # *This command requires channel op or higher.*
286
297
  def CBL(channel)
287
298
  json = {:channel => channel}
288
- self.send('send_message','CBL',json)
299
+ self.send_message('CBL',json)
289
300
  end
290
301
 
291
302
  ##
@@ -295,14 +306,14 @@ module Libfchat
295
306
  def CBU(channel,character)
296
307
  json = {:channel => channel,
297
308
  :character => character}
298
- self.send('send_message','CBU',json)
309
+ self.send_message('CBU',json)
299
310
  end
300
311
 
301
312
  ##
302
313
  # Create an Ad-hoc Channel
303
314
  def CCR(channel)
304
315
  json = {:channel => channel}
305
- self.send('send_message','CCR',json)
316
+ self.send_message('CCR',json)
306
317
  end
307
318
 
308
319
  ##
@@ -310,15 +321,16 @@ module Libfchat
310
321
  # channel description.
311
322
  #
312
323
  # *This command requires channel op or higher.*
313
- def CCR(channel)
314
- json = {:channel => channel}
315
- self.send('send_message','CCR',json)
324
+ def CDS(channel, description)
325
+ json = {:channel => channel,
326
+ :description => description}
327
+ self.send_message('CDS',json)
316
328
  end
317
329
 
318
330
  ##
319
331
  # Request a list of all public channels
320
332
  def CHA()
321
- self.send('send_message','CHA',{})
333
+ self.send_message('CHA',{})
322
334
  end
323
335
 
324
336
  ##
@@ -326,7 +338,7 @@ module Libfchat
326
338
  def CIU(channel,character)
327
339
  json = {:channel => channel,
328
340
  :character => character }
329
- self.send('send_message','CIU',json)
341
+ self.send_message('CIU',json)
330
342
  end
331
343
 
332
344
  ##
@@ -336,7 +348,7 @@ module Libfchat
336
348
  def CKU(channel,character)
337
349
  json = {:channel => channel,
338
350
  :character => character }
339
- self.send('send_message','CKU',json)
351
+ self.send_message('CKU',json)
340
352
  end
341
353
 
342
354
  ##
@@ -346,14 +358,14 @@ module Libfchat
346
358
  def COA(channel,character)
347
359
  json = {:channel => channel,
348
360
  :character => character }
349
- self.send('send_message','COA',json)
361
+ self.send_message('COA',json)
350
362
  end
351
363
 
352
364
  ##
353
365
  # Request a list of channel ops
354
- def COA(channel)
366
+ def COL(channel)
355
367
  json = {:channel => channel }
356
- self.send('send_message','CKU',json)
368
+ self.send_message('COL',json)
357
369
  end
358
370
 
359
371
  ##
@@ -362,7 +374,7 @@ module Libfchat
362
374
  # *This command is admin only*
363
375
  def CRC(channel)
364
376
  json = {:channel => channel }
365
- self.send('send_message','CRC',json)
377
+ self.send_message('CRC',json)
366
378
  end
367
379
 
368
380
  ##
@@ -372,7 +384,7 @@ module Libfchat
372
384
  def CUB(channel,character)
373
385
  json = {:channel => channel,
374
386
  :character => character }
375
- self.send('send_message','CUB',json)
387
+ self.send_message('CUB',json)
376
388
  end
377
389
 
378
390
  ##
@@ -381,7 +393,7 @@ module Libfchat
381
393
  # *This command is admin only*
382
394
  def DOP(character)
383
395
  json = { :character => character }
384
- self.send('send_message','DOP',json)
396
+ self.send_message('DOP',json)
385
397
  end
386
398
 
387
399
  ##
@@ -389,7 +401,7 @@ module Libfchat
389
401
  def FKS(kink,genders)
390
402
  json = { :kink => kink,
391
403
  :genders => genders }
392
- self.send('send_message','FKS',json)
404
+ self.send_message('FKS',json)
393
405
  end
394
406
 
395
407
  ##
@@ -409,7 +421,7 @@ module Libfchat
409
421
  :cname => cname,
410
422
  :cversion => cversion,
411
423
  :method => 'ticket'}
412
- self.send('send_message','IDN',json)
424
+ self.send_message('IDN', json)
413
425
  end
414
426
 
415
427
  ##
@@ -422,7 +434,7 @@ module Libfchat
422
434
  def IGN(action,character)
423
435
  json = { :action => action,
424
436
  :character => character }
425
- self.send('send_message','IGN',json)
437
+ self.send_message('IGN',json)
426
438
  end
427
439
 
428
440
  ##
@@ -431,14 +443,14 @@ module Libfchat
431
443
  # *This command is admin only*
432
444
  def IPB(character)
433
445
  json = { :character => character }
434
- self.send('send_message','IPB',json)
446
+ self.send_message('IPB',json)
435
447
  end
436
448
 
437
449
  ##
438
450
  # Send a channel join request
439
451
  def JCH(channel)
440
452
  json = { :channel => channel }
441
- self.send('send_message','JCH',json)
453
+ self.send_message('JCH',json)
442
454
  end
443
455
 
444
456
  ##
@@ -447,21 +459,21 @@ module Libfchat
447
459
  # *This command requires channel op or higher*
448
460
  def KIK(character)
449
461
  json = {:character => character }
450
- self.send('send_message','KIK',json)
462
+ self.send_message('KIK',json)
451
463
  end
452
464
 
453
465
  ##
454
466
  # Request a character's list of kinks
455
467
  def KIN(character)
456
468
  json = {:character => character }
457
- self.send('send_message','KIN',json)
469
+ self.send_message('KIN',json)
458
470
  end
459
471
 
460
472
  ##
461
473
  # Leave a channel
462
474
  def LCH(channel)
463
475
  json = {:channel => channel }
464
- self.send('send_message','LCH',json)
476
+ self.send_message('LCH',json)
465
477
  end
466
478
 
467
479
  ##
@@ -469,25 +481,25 @@ module Libfchat
469
481
  def MSG(channel,message)
470
482
  json = {:channel => channel,
471
483
  :message => message }
472
- self.send('send_message','MSG',json)
484
+ self.send_message('MSG',json)
473
485
  end
474
486
 
475
487
  ##
476
488
  # List presence of ops in all rooms
477
489
  def OPP()
478
- self.send('send_message','OPP',{})
490
+ self.send_message('OPP',{})
479
491
  end
480
492
 
481
493
  ##
482
494
  # Request a list of open private rooms
483
495
  def ORS()
484
- self.send('send_message','ORS',{})
496
+ self.send_message('ORS',{})
485
497
  end
486
498
 
487
499
  ##
488
500
  # Respond to a ping request
489
501
  def PIN()
490
- self.send('send_message','PIN',{})
502
+ self.send_message('PIN',{})
491
503
  end
492
504
 
493
505
  ##
@@ -495,14 +507,14 @@ module Libfchat
495
507
  def PRI(recipient,message)
496
508
  json = {:recipient => recipient,
497
509
  :message => message }
498
- self.send('send_message','PRI',json)
510
+ self.send_message('PRI',json)
499
511
  end
500
512
 
501
513
  ##
502
514
  # Do a profile request
503
515
  def PRO(character)
504
516
  json = {:character => character }
505
- self.send('send_message','PRO',json)
517
+ self.send_message('PRO',json)
506
518
  end
507
519
 
508
520
  ##
@@ -510,7 +522,7 @@ module Libfchat
510
522
  # in the given channel
511
523
  def RAN(channel)
512
524
  json = {:channel => channel }
513
- self.send('send_message','RAN',json)
525
+ self.send_message('RAN',json)
514
526
  end
515
527
 
516
528
  ##
@@ -518,7 +530,7 @@ module Libfchat
518
530
  def RLL(channel,dice)
519
531
  json = {:channel => channel,
520
532
  :dice => dice }
521
- self.send('send_message','RLL',json)
533
+ self.send_message('RLL',json)
522
534
  end
523
535
 
524
536
  ##
@@ -528,7 +540,7 @@ module Libfchat
528
540
  def RST(channel,status)
529
541
  json = {:channel => channel,
530
542
  :status => status }
531
- self.send('send_message','RST',json)
543
+ self.send_message('RST',json)
532
544
  end
533
545
 
534
546
  ##
@@ -537,7 +549,7 @@ module Libfchat
537
549
  # *This command is admin only*
538
550
  def RWD(character)
539
551
  json = {:character => character }
540
- self.send('send_message','RWD',json)
552
+ self.send_message('RWD',json)
541
553
  end
542
554
 
543
555
  ##
@@ -545,7 +557,7 @@ module Libfchat
545
557
  def STA(status,statusmsg)
546
558
  json = {:status => status,
547
559
  :statusmsg => statusmsg }
548
- self.send('send_message','STA',json)
560
+ self.send_message('STA',json)
549
561
  end
550
562
 
551
563
  ##
@@ -557,7 +569,7 @@ module Libfchat
557
569
  json = {:character => character,
558
570
  :time => time,
559
571
  :reason => reason }
560
- self.send('send_message','TMO',json)
572
+ self.send_message('TMO',json)
561
573
  end
562
574
 
563
575
  ##
@@ -567,7 +579,7 @@ module Libfchat
567
579
  def TPN(character,status)
568
580
  json = {:character => character,
569
581
  :status => status }
570
- self.send('send_message','TPN',json)
582
+ self.send_message('TPN',json)
571
583
  end
572
584
 
573
585
  ##
@@ -576,7 +588,7 @@ module Libfchat
576
588
  # *This command requires chat op or higher*
577
589
  def UBN(character)
578
590
  json = {:character => character }
579
- self.send('send_message','UBN',json)
591
+ self.send_message('UBN',json)
580
592
  end
581
593
 
582
594
  end #End of class
@@ -2,5 +2,5 @@ module Libfchat
2
2
  # We're doing this because we might write tests that deal
3
3
  # with other versions of Libfchat and we are unsure how to
4
4
  # handle this better.
5
- VERSION = "1.2" unless defined?(::Libfchat::VERSION)
5
+ VERSION = "1.3" unless defined?(::Libfchat::VERSION)
6
6
  end
@@ -19,6 +19,8 @@ module Libfchat
19
19
  json = MultiJson.load(res.body)
20
20
  if json['ticket']
21
21
  @ticket = json['ticket']
22
+ else
23
+ raise json['error']
22
24
  end
23
25
  return json
24
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libfchat
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.3'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-06-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: turn
16
- requirement: &9466340 !ruby/object:Gem::Requirement
16
+ requirement: &9248400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.9.5
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *9466340
24
+ version_requirements: *9248400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: miniunit
27
- requirement: &9560780 !ruby/object:Gem::Requirement
27
+ requirement: &9247820 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.2.1
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *9560780
35
+ version_requirements: *9247820
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: multi_json
38
- requirement: &9560240 !ruby/object:Gem::Requirement
38
+ requirement: &9247220 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.3.6
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *9560240
46
+ version_requirements: *9247220
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: faye-websocket
49
- requirement: &9559760 !ruby/object:Gem::Requirement
49
+ requirement: &9246660 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 0.4.6
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *9559760
57
+ version_requirements: *9246660
58
58
  description: A library for connecting to F-chat ( http://f-list.net )
59
59
  email: cheetahmorph@gmail.com
60
60
  executables: []
@@ -64,8 +64,6 @@ files:
64
64
  - lib/libfchat/version.rb
65
65
  - lib/libfchat/webapi.rb
66
66
  - lib/libfchat/fchat.rb
67
- - test/webapi_test.rb
68
- - test/fchat_test.rb
69
67
  homepage: http://github.com/jippen/libfchat-ruby
70
68
  licenses:
71
69
  - MIT
@@ -91,6 +89,4 @@ rubygems_version: 1.8.11
91
89
  signing_key:
92
90
  specification_version: 3
93
91
  summary: A library for connection to F-chat
94
- test_files:
95
- - test/webapi_test.rb
96
- - test/fchat_test.rb
92
+ test_files: []
data/test/fchat_test.rb DELETED
@@ -1,14 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.unshift File.expand_path("../lib", __FILE__)
3
-
4
- require 'test_helper'
5
- require 'libfchat/fchat'
6
-
7
- class TestFchat < Test::Unit::TestCase
8
-
9
- def test_can_create_object
10
- j = Libfchat::Fchat.new
11
- assert_equal true, j.is_a?(Object)
12
- end
13
-
14
- end
data/test/webapi_test.rb DELETED
@@ -1,28 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- $:.unshift File.expand_path("../lib", __FILE__)
3
-
4
- require 'test_helper'
5
- require 'libfchat/webapi'
6
-
7
- class TestWebAPI < Test::Unit::TestCase
8
-
9
- def test_can_create_object
10
- j = Libfchat::WebAPI.new
11
- assert_equal true, j.is_a?(Object)
12
- end
13
-
14
- def test_no_credentials_gives_error
15
- j = Libfchat::WebAPI.new
16
- ticket = j.get_ticket('','')
17
- assert_not_nil ticket['error']
18
- assert_not_equal '', ticket['error']
19
- end
20
-
21
- def test_bad_password_gives_error
22
- j = Libfchat::WebAPI.new
23
- ticket = j.get_ticket('jippenbots','')
24
- assert_not_nil ticket['error']
25
- assert_not_equal '', ticket['error']
26
- end
27
-
28
- end