class Libfchat::Fchat

Attributes

chat_max[R]
clientname[R]
friends[R]
ignore[R]
lfrp_flood[R]
lfrp_max[R]
logger[RW]
me[R]
msg_flood[R]
ops[R]
permissions[R]
priv_max[R]
rooms[R]
ticket[R]
users[R]
version[R]
websocket[R]

Public Class Methods

new(clientname="libfchat-ruby by Jippen Faddoul ( http://github.com/jippen/libfchat-ruby )",version=Libfchat::VERSION, level=Logger::DEBUG) click to toggle source

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

# 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

Public Instance Methods

ACB(character) click to toggle source

Performs an account ban against a characters account.

*This command requires chat op or higher.*

# File lib/libfchat/fchat.rb, line 277
def ACB(character)
  json = {:character => character}
  self.send_message('ACB',json)
end
AOP(character) click to toggle source

Adds a character to the chat operator list.

*This command is admin only.*

# File lib/libfchat/fchat.rb, line 286
def AOP(character)
  json = {:character => character}
  self.send_message('AOP',json)
end
AWC(character) click to toggle source

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

*This command requires chat op or higher.*

# File lib/libfchat/fchat.rb, line 295
def AWC(character)
  json = {:character => character}
  self.send_message('AWC',json)
end
BRO(message) click to toggle source

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

# File lib/libfchat/fchat.rb, line 303
def BRO(message)
  json = {:message => message}
  self.send_message('AWC',json)
end
CBL(channel) click to toggle source

Request the channel banlist.

*This command requires channel op or higher.*

# File lib/libfchat/fchat.rb, line 312
def CBL(channel)
  json = {:channel => channel}
  self.send_message('CBL',json)
end
CBU(channel,character) click to toggle source

Bans a character from a channel

*This command requires channel op or higher.*

# File lib/libfchat/fchat.rb, line 321
def CBU(channel,character)
  json = {:channel   => channel,
          :character => character}
  self.send_message('CBU',json)
end
CCR(channel) click to toggle source

Create an Ad-hoc Channel

# File lib/libfchat/fchat.rb, line 329
def CCR(channel)
  json = {:channel => channel}
  self.send_message('CCR',json)
end
CDS(channel, description) click to toggle source

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

*This command requires channel op or higher.*

# File lib/libfchat/fchat.rb, line 339
def CDS(channel, description)
  json = {:channel => channel,
          :description => description}
  self.send_message('CDS',json)
end
CHA() click to toggle source

Request a list of all public channels

# File lib/libfchat/fchat.rb, line 347
def CHA()
  self.send_message('CHA',{})
end
CIU(channel,character) click to toggle source

Sends an invitation for a channel to a user

# 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) click to toggle source

Kick a user from a channel

*This command requires channel op or higher*

# 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) click to toggle source

Op a user in a channel

*This command requires channel op or higher*

# File lib/libfchat/fchat.rb, line 373
def COA(channel,character)
  json = {:channel   => channel,
          :character => character }
  self.send_message('COA',json)
end
COL(channel) click to toggle source

Request a list of channel ops

# File lib/libfchat/fchat.rb, line 381
def COL(channel)
  json = {:channel => channel }
  self.send_message('COL',json)
end
CRC(channel) click to toggle source

Creates a global channel

*This command is admin only*

# File lib/libfchat/fchat.rb, line 390
def CRC(channel)
  json = {:channel => channel }
  self.send_message('CRC',json)
end
CUB(channel,character) click to toggle source

Unban a user from a channel

*This command requires channel op or higher*

# File lib/libfchat/fchat.rb, line 399
def CUB(channel,character)
  json = {:channel   => channel,
          :character => character }
  self.send_message('CUB',json)
end
DOP(character) click to toggle source

Request that a character be stripped of chatop status

*This command is admin only*

# File lib/libfchat/fchat.rb, line 409
def DOP(character)
  json = { :character => character }
  self.send_message('DOP',json)
end
FKS(kink,genders) click to toggle source

Do a search for a kink with specific genders

# File lib/libfchat/fchat.rb, line 416
def FKS(kink,genders)
  json = { :kink    => kink,
           :genders => genders }
  self.send_message('FKS',json)
end
IDN(account, character, ticket, cname=@clientname, cversion=@version, method="ticket") click to toggle source

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

# File lib/libfchat/fchat.rb, line 426
def IDN(account,
        character,
        ticket,
        cname=@clientname,
        cversion=@version,
        method="ticket")
  # Initial identification with the server
  json = {:account   => account,
          :character => character,
          :ticket    => ticket['ticket'],
          :cname     => cname,
          :cversion  => cversion,
          :method    => 'ticket'}
  self.send_message('IDN', json)
end
IGN(action,character) click to toggle source

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
# File lib/libfchat/fchat.rb, line 449
def IGN(action,character)
  json = { :action    => action,
           :character => character }
  self.send_message('IGN',json)
end
IPB(character) click to toggle source

Request that a character be IP banned

*This command is admin only*

# File lib/libfchat/fchat.rb, line 459
def IPB(character)
  json = { :character => character }
  self.send_message('IPB',json)
end
JCH(channel) click to toggle source

Send a channel join request

# File lib/libfchat/fchat.rb, line 466
def JCH(channel)
  json = { :channel => channel }
  self.send_message('JCH',json)
end
KIK(character) click to toggle source

Request a character to be kicked

*This command requires channel op or higher*

# File lib/libfchat/fchat.rb, line 475
def KIK(character)
  json = {:character => character }
  self.send_message('KIK',json)
end
KIN(character) click to toggle source

Request a character's list of kinks

# File lib/libfchat/fchat.rb, line 482
def KIN(character)
  json = {:character => character }
  self.send_message('KIN',json)
end
LCH(channel) click to toggle source

Leave a channel

# File lib/libfchat/fchat.rb, line 489
def LCH(channel)
  json = {:channel => channel }
  self.send_message('LCH',json)
end
MSG(channel,message) click to toggle source

Send a message to a channel

# File lib/libfchat/fchat.rb, line 496
def MSG(channel,message)
  json = {:channel => channel,
          :message => message }
  self.send_message('MSG',json)
end
OPP() click to toggle source

List presence of ops in all rooms

# File lib/libfchat/fchat.rb, line 504
def OPP()
  self.send_message('OPP',{})
end
ORS() click to toggle source

Request a list of open private rooms

# File lib/libfchat/fchat.rb, line 510
def ORS()
  self.send_message('ORS',{})
end
PIN() click to toggle source

Respond to a ping request

# File lib/libfchat/fchat.rb, line 516
def PIN()
  self.send_message('PIN',{})
end
PRI(recipient,message) click to toggle source

Sends a prive message to another user

# File lib/libfchat/fchat.rb, line 522
def PRI(recipient,message)
  json = {:recipient => recipient,
          :message   => message }
  self.send_message('PRI',json)
end
PRO(character) click to toggle source

Do a profile request

# File lib/libfchat/fchat.rb, line 530
def PRO(character)
  json = {:character => character }
  self.send_message('PRO',json)
end
RAN(channel) click to toggle source

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

# File lib/libfchat/fchat.rb, line 538
def RAN(channel)
  json = {:channel => channel }
  self.send_message('RAN',json)
end
RLL(channel,dice) click to toggle source

Roll dice in a channel

# 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) click to toggle source

Set a private room's status to closed or open

*This command requires channel op or higher*

# File lib/libfchat/fchat.rb, line 555
def RST(channel,status)
  json = {:channel   => channel,
          :status    => status }
  self.send_message('RST',json)
end
RWD(character) click to toggle source

Reward a user, for instance, for finding a bug

*This command is admin only*

# File lib/libfchat/fchat.rb, line 565
def RWD(character)
  json = {:character => character }
  self.send_message('RWD',json)
end
STA(status,statusmsg) click to toggle source

Request a new status to be set for your character

# 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) click to toggle source

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*

# 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
TPN(character,status) click to toggle source

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

Available values for status: clear, paused, typing

# File lib/libfchat/fchat.rb, line 594
def TPN(character,status)
  json = {:character => character,
          :status    => status }
  self.send_message('TPN',json)
end
UBN(character) click to toggle source

Unban a character

*This command requires chat op or higher*

# File lib/libfchat/fchat.rb, line 604
def UBN(character)
  json = {:character => character }
  self.send_message('UBN',json)
end
got_ADL(message) click to toggle source

Store list of ops

# File lib/libfchat/fchat.rb, line 161
def got_ADL(message)
  @ops = message['ops']
end
got_CDS(message) click to toggle source

Store description for newly joined chatroom

# File lib/libfchat/fchat.rb, line 255
def got_CDS(message)
  @rooms[message['channel']]['description'] = message['description']
end
got_CIU(message) click to toggle source

Join chatrooms on invite

# 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) click to toggle source

Store ops list for room

# File lib/libfchat/fchat.rb, line 235
def got_COL(message)
  @rooms[message['channel']]['ops'] = message['oplist']
end
got_FLN(message) click to toggle source

Handle user logging off

# 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) click to toggle source

Store list of friends

# File lib/libfchat/fchat.rb, line 167
def got_FRL(message)
  @friends = message['characters']
end
got_ICH(message) click to toggle source

Store userlist for newly joined chatroom

# 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) click to toggle source

Know thyself

# File lib/libfchat/fchat.rb, line 135
def got_IDN(message)
  @me = message['character']
end
got_IGN(message) click to toggle source

Store list of ignored users

# File lib/libfchat/fchat.rb, line 173
def got_IGN(message)
  @ops = message['characters']
end
got_JCH(message) click to toggle source

Store data about newly joined chatroom

# 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) click to toggle source

Handle user leaving chatroom

# File lib/libfchat/fchat.rb, line 249
def got_LCH(message)
  @rooms[message['channel']]['characters'].delete(message['character'])
end
got_LIS(message) click to toggle source

Store list of online users

# 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) click to toggle source

Handle user logging on

# 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) click to toggle source

Respond to keepalive ping messages

# File lib/libfchat/fchat.rb, line 129
def got_PIN(message)
  self.send('PIN')
end
got_STA(message) click to toggle source

Handle user changing status

# 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) click to toggle source

Store server-side variables

# 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
login(server,account,password,character,timeout=30) click to toggle source

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

# File lib/libfchat/fchat.rb, line 87
def login(server,account,password,character,timeout=30)
  webapi = Libfchat::WebAPI.new
  @ticket = webapi.getApiTicket(account, password)
  @me = character

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

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

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

    @websocket.onmessage = lambda do |event|
      self.parse_message(event.data)
    end
  }
end
method_missing(method_name, *args, &block) click to toggle source

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

Calls superclass method
# 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
parse_message(msg) click to toggle source

Parse message received from server

# 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
send_message(type, json) click to toggle source

Generic message sender

# 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
to_yaml_properties() click to toggle source

Remove useless properties from to_yaml conversion

Calls superclass method
# File lib/libfchat/fchat.rb, line 611
def to_yaml_properties
  super - ["@logger", "@users", "@rooms"]
end