Class: Libfchat::Fchat

Inherits:
Object
  • Object
show all
Defined in:
lib/libfchat/fchat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clientname = "libfchat-ruby by Jippen Faddoul ( http://github.com/jippen/libfchat-ruby )", version = Libfchat::VERSION, level = Logger::DEBUG) ⇒ Fchat

Initialize the object with the name and version. Default to just identifying as the library



44
45
46
47
48
49
50
51
# File 'lib/libfchat/fchat.rb', line 44

def initialize(clientname="libfchat-ruby by Jippen Faddoul ( http://github.com/jippen/libfchat-ruby )",version=Libfchat::VERSION, level=Logger::DEBUG)
  @clientname = clientname
  @version = version
  @users = InsensitiveHash.new
  @rooms = InsensitiveHash.new
  @logger = Logger.new(STDOUT)
  @logger.level = level
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

Some method_missing magic to make ruby handle just throwing around commands that may or may not exist.



57
58
59
60
61
62
63
64
# File 'lib/libfchat/fchat.rb', line 57

def method_missing(method_name, *args, &block)
  # Try to handle all three-letter strings
  if method_name.to_s[4,7] =~ /[A-Z]{3}/
    return nil
  else
    super(method_name,*args,&block)
  end
end

Instance Attribute Details

#chat_maxObject (readonly)

Returns the value of attribute chat_max.



26
27
28
# File 'lib/libfchat/fchat.rb', line 26

def chat_max
  @chat_max
end

#clientnameObject (readonly)

Returns the value of attribute clientname.



23
24
25
# File 'lib/libfchat/fchat.rb', line 23

def clientname
  @clientname
end

#friendsObject (readonly)

Returns the value of attribute friends.



33
34
35
# File 'lib/libfchat/fchat.rb', line 33

def friends
  @friends
end

#ignoreObject (readonly)

Returns the value of attribute ignore.



34
35
36
# File 'lib/libfchat/fchat.rb', line 34

def ignore
  @ignore
end

#lfrp_floodObject (readonly)

Returns the value of attribute lfrp_flood.



29
30
31
# File 'lib/libfchat/fchat.rb', line 29

def lfrp_flood
  @lfrp_flood
end

#lfrp_maxObject (readonly)

Returns the value of attribute lfrp_max.



28
29
30
# File 'lib/libfchat/fchat.rb', line 28

def lfrp_max
  @lfrp_max
end

#loggerObject

Returns the value of attribute logger.



38
39
40
# File 'lib/libfchat/fchat.rb', line 38

def logger
  @logger
end

#meObject (readonly)

Returns the value of attribute me.



24
25
26
# File 'lib/libfchat/fchat.rb', line 24

def me
  @me
end

#msg_floodObject (readonly)

Returns the value of attribute msg_flood.



30
31
32
# File 'lib/libfchat/fchat.rb', line 30

def msg_flood
  @msg_flood
end

#opsObject (readonly)

Returns the value of attribute ops.



35
36
37
# File 'lib/libfchat/fchat.rb', line 35

def ops
  @ops
end

#permissionsObject (readonly)

Returns the value of attribute permissions.



31
32
33
# File 'lib/libfchat/fchat.rb', line 31

def permissions
  @permissions
end

#priv_maxObject (readonly)

Returns the value of attribute priv_max.



27
28
29
# File 'lib/libfchat/fchat.rb', line 27

def priv_max
  @priv_max
end

#roomsObject (readonly)

Returns the value of attribute rooms.



37
38
39
# File 'lib/libfchat/fchat.rb', line 37

def rooms
  @rooms
end

#ticketObject (readonly)

Returns the value of attribute ticket.



19
20
21
# File 'lib/libfchat/fchat.rb', line 19

def ticket
  @ticket
end

#usersObject (readonly)

Returns the value of attribute users.



36
37
38
# File 'lib/libfchat/fchat.rb', line 36

def users
  @users
end

#versionObject (readonly)

Returns the value of attribute version.



22
23
24
# File 'lib/libfchat/fchat.rb', line 22

def version
  @version
end

#websocketObject (readonly)

Returns the value of attribute websocket.



20
21
22
# File 'lib/libfchat/fchat.rb', line 20

def websocket
  @websocket
end

Instance Method Details

#ACB(character) ⇒ Object

Performs an account ban against a characters account.

*This command requires chat op or higher.*



277
278
279
280
# File 'lib/libfchat/fchat.rb', line 277

def ACB(character)
  json = {:character => character}
  self.send_message('ACB',json)
end

#AOP(character) ⇒ Object

Adds a character to the chat operator list.

*This command is admin only.*



286
287
288
289
# File 'lib/libfchat/fchat.rb', line 286

def AOP(character)
  json = {:character => character}
  self.send_message('AOP',json)
end

#AWC(character) ⇒ Object

Requests a list of currently connected alts for a characters account.

*This command requires chat op or higher.*



295
296
297
298
# File 'lib/libfchat/fchat.rb', line 295

def AWC(character)
  json = {:character => character}
  self.send_message('AWC',json)
end

#BRO(message) ⇒ Object

Broadcasts a message to all connections. *This command is admin only.*



303
304
305
306
# File 'lib/libfchat/fchat.rb', line 303

def BRO(message)
  json = {:message => message}
  self.send_message('AWC',json)
end

#CBL(channel) ⇒ Object

Request the channel banlist.

*This command requires channel op or higher.*



312
313
314
315
# File 'lib/libfchat/fchat.rb', line 312

def CBL(channel)
  json = {:channel => channel}
  self.send_message('CBL',json)
end

#CBU(channel, character) ⇒ Object

Bans a character from a channel

*This command requires channel op or higher.*



321
322
323
324
325
# File 'lib/libfchat/fchat.rb', line 321

def CBU(channel,character)
  json = {:channel   => channel,
          :character => character}
  self.send_message('CBU',json)
end

#CCR(channel) ⇒ Object

Create an Ad-hoc Channel



329
330
331
332
# File 'lib/libfchat/fchat.rb', line 329

def CCR(channel)
  json = {:channel => channel}
  self.send_message('CCR',json)
end

#CDS(channel, description) ⇒ Object

This command is used by an admin or channel owner to set a new channel description.

*This command requires channel op or higher.*



339
340
341
342
343
# File 'lib/libfchat/fchat.rb', line 339

def CDS(channel, description)
  json = {:channel => channel,
          :description => description}
  self.send_message('CDS',json)
end

#CHAObject

Request a list of all public channels



347
348
349
# File 'lib/libfchat/fchat.rb', line 347

def CHA()
  self.send_message('CHA',{})
end

#CIU(channel, character) ⇒ Object

Sends an invitation for a channel to a user



353
354
355
356
357
# File 'lib/libfchat/fchat.rb', line 353

def CIU(channel,character)
  json = {:channel   => channel,
          :character => character }
  self.send_message('CIU',json)
end

#CKU(channel, character) ⇒ Object

Kick a user from a channel

*This command requires channel op or higher*



363
364
365
366
367
# File 'lib/libfchat/fchat.rb', line 363

def CKU(channel,character)
  json = {:channel   => channel,
          :character => character }
  self.send_message('CKU',json)
end

#COA(channel, character) ⇒ Object

Op a user in a channel

*This command requires channel op or higher*



373
374
375
376
377
# File 'lib/libfchat/fchat.rb', line 373

def COA(channel,character)
  json = {:channel   => channel,
          :character => character }
  self.send_message('COA',json)
end

#COL(channel) ⇒ Object

Request a list of channel ops



381
382
383
384
# File 'lib/libfchat/fchat.rb', line 381

def COL(channel)
  json = {:channel => channel }
  self.send_message('COL',json)
end

#CRC(channel) ⇒ Object

Creates a global channel

*This command is admin only*



390
391
392
393
# File 'lib/libfchat/fchat.rb', line 390

def CRC(channel)
  json = {:channel => channel }
  self.send_message('CRC',json)
end

#CUB(channel, character) ⇒ Object

Unban a user from a channel

*This command requires channel op or higher*



399
400
401
402
403
# File 'lib/libfchat/fchat.rb', line 399

def CUB(channel,character)
  json = {:channel   => channel,
          :character => character }
  self.send_message('CUB',json)
end

#DOP(character) ⇒ Object

Request that a character be stripped of chatop status

*This command is admin only*



409
410
411
412
# File 'lib/libfchat/fchat.rb', line 409

def DOP(character)
  json = { :character => character }
  self.send_message('DOP',json)
end

#FKS(kink, genders) ⇒ Object

Do a search for a kink with specific genders



416
417
418
419
420
# File 'lib/libfchat/fchat.rb', line 416

def FKS(kink,genders)
  json = { :kink    => kink,
           :genders => genders }
  self.send_message('FKS',json)
end

#got_ADL(message) ⇒ Object

Store list of ops



161
162
163
# File 'lib/libfchat/fchat.rb', line 161

def got_ADL(message)
  @ops = message['ops']
end

#got_CDS(message) ⇒ Object

Store description for newly joined chatroom



255
256
257
# File 'lib/libfchat/fchat.rb', line 255

def got_CDS(message)
  @rooms[message['channel']]['description'] = message['description']
end

#got_CIU(message) ⇒ Object

Join chatrooms on invite



260
261
262
263
264
265
# File 'lib/libfchat/fchat.rb', line 260

def got_CIU(message)
  #Annoyingly, the json for this varies for public and private rooms.
  #So just try both and call it a day.
  self.send('JCH',message['name'])
  self.send('JCH',message['channel'])
end

#got_COL(message) ⇒ Object

Store ops list for room



235
236
237
# File 'lib/libfchat/fchat.rb', line 235

def got_COL(message)
  @rooms[message['channel']]['ops'] = message['oplist']
end

#got_FLN(message) ⇒ Object

Handle user logging off



211
212
213
214
215
216
# File 'lib/libfchat/fchat.rb', line 211

def got_FLN(message)
  @users.delete(message['character'])
  @rooms.each do |room|
    room['characters'].delete(message['character'])
  end
end

#got_FRL(message) ⇒ Object

Store list of friends



167
168
169
# File 'lib/libfchat/fchat.rb', line 167

def got_FRL(message)
  @friends = message['characters']
end

#got_ICH(message) ⇒ Object

Store userlist for newly joined chatroom



241
242
243
244
245
# File 'lib/libfchat/fchat.rb', line 241

def got_ICH(message)
  message['users'].each do |user|
    @rooms[message['channel']]['characters'].push(user['identity'])
  end
end

#got_IDN(message) ⇒ Object

Know thyself



135
136
137
# File 'lib/libfchat/fchat.rb', line 135

def got_IDN(message)
  @me = message['character']
end

#got_IGN(message) ⇒ Object

Store list of ignored users



173
174
175
# File 'lib/libfchat/fchat.rb', line 173

def got_IGN(message)
  @ops = message['characters']
end

#got_JCH(message) ⇒ Object

Store data about newly joined chatroom



220
221
222
223
224
225
226
227
228
229
230
231
# File 'lib/libfchat/fchat.rb', line 220

def got_JCH(message)
  begin
    @rooms[message['channel']]['characters'].push(message['character']['identity'])
  rescue
    @rooms[message['channel']] = {
      'title'       => message['title'],
      'description' => '',
      'characters'  => [],
      'ops'         => [],
    }
  end
end

#got_LCH(message) ⇒ Object

Handle user leaving chatroom



249
250
251
# File 'lib/libfchat/fchat.rb', line 249

def got_LCH(message)
  @rooms[message['channel']]['characters'].delete(message['character'])
end

#got_LIS(message) ⇒ Object

Store list of online users



179
180
181
182
183
184
185
186
187
# File 'lib/libfchat/fchat.rb', line 179

def got_LIS(message)
  message['characters'].each do |character|
    @users[character[0]] = {
      'gender'  => character[1],
      'status'  => character[2],
      'message' => character[3]
    }
  end
end

#got_NLN(message) ⇒ Object

Handle user logging on



191
192
193
194
195
196
197
# File 'lib/libfchat/fchat.rb', line 191

def got_NLN(message)
  @users[message['identity']] = {
      'gender'  => message['gender'],
      'status'  => message['status'],
      'message' => ""
    }
end

#got_PIN(message) ⇒ Object

Respond to keepalive ping messages



129
130
131
# File 'lib/libfchat/fchat.rb', line 129

def got_PIN(message)
  self.send('PIN')
end

#got_STA(message) ⇒ Object

Handle user changing status



201
202
203
204
205
206
207
# File 'lib/libfchat/fchat.rb', line 201

def got_STA(message)
  @users[message['character']] = {
      'gender'  => @users[message['character']]['gender'],
      'status'  => message['status'],
      'message' => message['statusmsg']
    }
end

#got_VAR(message) ⇒ Object

Store server-side variables



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/libfchat/fchat.rb', line 141

def got_VAR(message)
  if message['variable'] == 'chat_max'
    @chat_max = message['value']
  elsif message['variable'] == 'priv_max'
    @priv_max = message['value']
  elsif message['variable'] == 'lfrp_max'
    @lfrp_max = message['value']
  elsif message['variable'] == 'lfrp_flood'
    @lfrp_flood = message['value']
  elsif message['variable'] == 'msg_flood'
    @msg_flood = message['value']
  elsif message['variable'] == 'permissions'
    @permissions = message['value']
  else
    raise "ERROR: Do not know how to handle VAR #{message}"
  end
end

#IDN(account, character, ticket, cname = @clientname, cversion = @version, method = "ticket") ⇒ Object

This command is used to identify with the server. NOTE: If you send any commands before identifying, you will be disconnected.



426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/libfchat/fchat.rb', line 426

def IDN(,
        character,
        ticket,
        cname=@clientname,
        cversion=@version,
        method="ticket")
  # Initial identification with the server
  json = {:account   => ,
          :character => character,
          :ticket    => ticket['ticket'],
          :cname     => cname,
          :cversion  => cversion,
          :method    => 'ticket'}
  self.send_message('IDN', json)
end

#IGN(action, character) ⇒ Object

Deal with ignoring characters.

Available ‘actions’

notify: send this when someone on the ignore list sends a message to you
add: Add a character to your ignore list
remove: Remove a character from your ignore list


449
450
451
452
453
# File 'lib/libfchat/fchat.rb', line 449

def IGN(action,character)
  json = { :action    => action,
           :character => character }
  self.send_message('IGN',json)
end

#IPB(character) ⇒ Object

Request that a character be IP banned

*This command is admin only*



459
460
461
462
# File 'lib/libfchat/fchat.rb', line 459

def IPB(character)
  json = { :character => character }
  self.send_message('IPB',json)
end

#JCH(channel) ⇒ Object

Send a channel join request



466
467
468
469
# File 'lib/libfchat/fchat.rb', line 466

def JCH(channel)
  json = { :channel => channel }
  self.send_message('JCH',json)
end

#KIK(character) ⇒ Object

Request a character to be kicked

*This command requires channel op or higher*



475
476
477
478
# File 'lib/libfchat/fchat.rb', line 475

def KIK(character)
  json = {:character => character }
  self.send_message('KIK',json)
end

#KIN(character) ⇒ Object

Request a character’s list of kinks



482
483
484
485
# File 'lib/libfchat/fchat.rb', line 482

def KIN(character)
  json = {:character => character }
  self.send_message('KIN',json)
end

#LCH(channel) ⇒ Object

Leave a channel



489
490
491
492
# File 'lib/libfchat/fchat.rb', line 489

def LCH(channel)
  json = {:channel => channel }
  self.send_message('LCH',json)
end

#login(server, account, password, character, timeout = 30) ⇒ Object

Login to fchat as a specific user, and start the event machine



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/libfchat/fchat.rb', line 87

def (server,,password,character,timeout=30)
  webapi = Libfchat::WebAPI.new
  @ticket = webapi.getApiTicket(, password)
  @me = character

  EM.run {
    @websocket = Faye::WebSocket::Client.new(server)

    @websocket.onopen = lambda do |event|
      #When we connect, log in
      self.IDN(, character, ticket)
    end

    @websocket.onclose = lambda do |event|
      @websocket = nil
    end

    @websocket.onmessage = lambda do |event|
      self.parse_message(event.data)
    end
  }
end

#MSG(channel, message) ⇒ Object

Send a message to a channel



496
497
498
499
500
# File 'lib/libfchat/fchat.rb', line 496

def MSG(channel,message)
  json = {:channel => channel,
          :message => message }
  self.send_message('MSG',json)
end

#OPPObject

List presence of ops in all rooms



504
505
506
# File 'lib/libfchat/fchat.rb', line 504

def OPP()
  self.send_message('OPP',{})
end

#ORSObject

Request a list of open private rooms



510
511
512
# File 'lib/libfchat/fchat.rb', line 510

def ORS()
  self.send_message('ORS',{})
end

#parse_message(msg) ⇒ Object

Parse message received from server



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/libfchat/fchat.rb', line 68

def parse_message(msg)
  type = msg[0,3]
  begin
    data = MultiJson.load(msg[4..-1])
  rescue
    data = MultiJson.load('{}')
  end

  @logger.debug("<< #{msg}")

  begin
    self.send("got_#{type}",data)
  rescue
  end
end

#PINObject

Respond to a ping request



516
517
518
# File 'lib/libfchat/fchat.rb', line 516

def PIN()
  self.send_message('PIN',{})
end

#PRI(recipient, message) ⇒ Object

Sends a prive message to another user



522
523
524
525
526
# File 'lib/libfchat/fchat.rb', line 522

def PRI(recipient,message)
  json = {:recipient => recipient,
          :message   => message }
  self.send_message('PRI',json)
end

#PRO(character) ⇒ Object

Do a profile request



530
531
532
533
# File 'lib/libfchat/fchat.rb', line 530

def PRO(character)
  json = {:character => character }
  self.send_message('PRO',json)
end

#RAN(channel) ⇒ Object

Advertises the first open private channel owned by the client in the given channel



538
539
540
541
# File 'lib/libfchat/fchat.rb', line 538

def RAN(channel)
  json = {:channel => channel }
  self.send_message('RAN',json)
end

#RLL(channel, dice) ⇒ Object

Roll dice in a channel



545
546
547
548
549
# File 'lib/libfchat/fchat.rb', line 545

def RLL(channel,dice)
  json = {:channel => channel,
          :dice    => dice }
  self.send_message('RLL',json)
end

#RST(channel, status) ⇒ Object

Set a private room’s status to closed or open

*This command requires channel op or higher*



555
556
557
558
559
# File 'lib/libfchat/fchat.rb', line 555

def RST(channel,status)
  json = {:channel   => channel,
          :status    => status }
  self.send_message('RST',json)
end

#RWD(character) ⇒ Object

Reward a user, for instance, for finding a bug

*This command is admin only*



565
566
567
568
# File 'lib/libfchat/fchat.rb', line 565

def RWD(character)
  json = {:character => character }
  self.send_message('RWD',json)
end

#send_message(type, json) ⇒ Object

Generic message sender



112
113
114
115
116
117
118
119
120
121
# File 'lib/libfchat/fchat.rb', line 112

def send_message(type, json)
  jsonstr = ::MultiJson.dump(json)
  msg = "#{type} #{jsonstr}"
  if type == 'IDN'
    json[:ticket] = '[REDACTED]'
  end
  filteredjsonstr = ::MultiJson.dump(json)
  @logger.debug(">> #{type} #{filteredjsonstr}")
  @websocket.send(msg)
end

#STA(status, statusmsg) ⇒ Object

Request a new status to be set for your character



572
573
574
575
576
# File 'lib/libfchat/fchat.rb', line 572

def STA(status,statusmsg)
  json = {:status    => status,
          :statusmsg => statusmsg }
  self.send_message('STA',json)
end

#TMO(character, time, reason) ⇒ Object

Admin or chatop command to request a timeout for a user time must be a minimum of one minute, and maximum of 90 minutes

*This command requires channel op or higher*



583
584
585
586
587
588
# File 'lib/libfchat/fchat.rb', line 583

def TMO(character,time,reason)
  json = {:character => character,
          :time      => time,
          :reason    => reason }
  self.send_message('TMO',json)
end

#to_yaml_propertiesObject

Remove useless properties from to_yaml conversion



611
612
613
# File 'lib/libfchat/fchat.rb', line 611

def to_yaml_properties
  super - ["@logger", "@users", "@rooms"]
end

#TPN(character, status) ⇒ Object

User x is typing/stopped typing/entered text for private messages

Available values for status: clear, paused, typing



594
595
596
597
598
# File 'lib/libfchat/fchat.rb', line 594

def TPN(character,status)
  json = {:character => character,
          :status    => status }
  self.send_message('TPN',json)
end

#UBN(character) ⇒ Object

Unban a character

*This command requires chat op or higher*



604
605
606
607
# File 'lib/libfchat/fchat.rb', line 604

def UBN(character)
  json = {:character => character }
  self.send_message('UBN',json)
end