Class: Participle::Message

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

Overview

Any line said by any user in any room. May be replied to.

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pkt, username) ⇒ Message

Returns a new instance of Message

Parameters:

  • pkt (Packet)

    the message packet

  • username (String)

    the message's sender name

  • srv (TCPSocket)

    the server connection

  • bot (Bot)

    the current bot

  • admin (String)

    the bot administrator's name



24
25
26
27
28
29
30
31
# File 'lib/message.rb', line 24

def initialize pkt, username
  @packet = pkt
  @server = participle.server
  @user   = DA::User.new(username, participle.configuration.admin)
  @line   = pkt.body
  @roomtype = pkt.room.match(":") ? "pchat" : "chat"
  @room   = participle.rooms[pkt.room]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &blk) ⇒ Object

Defer unmatched method calls to the bot.



119
120
121
# File 'lib/message.rb', line 119

def method_missing m, *args, &blk
  participle.send(m, *args, &blk)
end

Class Attribute Details

.botObject

Returns the value of attribute bot



5
6
7
# File 'lib/message.rb', line 5

def bot
  @bot
end

Instance Attribute Details

#botBot (readonly)

Returns the current bot

Returns:

  • (Bot)

    the current bot



15
16
17
# File 'lib/message.rb', line 15

def bot
  @bot
end

#lineArray<String> (readonly)

Returns the message body split by newlines

Returns:

  • (Array<String>)

    the message body split by newlines



11
12
13
# File 'lib/message.rb', line 11

def line
  @line
end

#packetPacket (readonly)

Returns the corresponding packet

Returns:

  • (Packet)

    the corresponding packet



13
14
15
# File 'lib/message.rb', line 13

def packet
  @packet
end

#roomDA::Room

Returns the message's room

Returns:



7
8
9
# File 'lib/message.rb', line 7

def room
  @room
end

#roomtype=(value) ⇒ String (writeonly)

Returns:

  • (String)


17
18
19
# File 'lib/message.rb', line 17

def roomtype=(value)
  @roomtype = value
end

#userDA::User (readonly)

Returns the sayer of the message

Returns:

  • (DA::User)

    the sayer of the message



9
10
11
# File 'lib/message.rb', line 9

def user
  @user
end

Instance Method Details

#action(line) ⇒ void

This method returns an undefined value.

Sends an action of line to the current room.

Parameters:

  • line (String)

    the line to send



58
59
60
61
# File 'lib/message.rb', line 58

def action line
  return if participle.silent
  participle.action(line, @room.name_formatted)
end

#ban(user, reason = nil) ⇒ void

This method returns an undefined value.

Ban a user with optional reason.

Parameters:

  • user (String)

    the user to ban

  • reason (String) (defaults to: nil)

    why you're banning them



75
76
77
# File 'lib/message.rb', line 75

def ban user, reason = nil
  participle.ban user, @room.name_formatted, reason
end

#bodyString

Returns:

  • (String)


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

def body
  @packet.body
end

#chat(user) ⇒ void

This method returns an undefined value.

Open a private chat with a user.

Parameters:

  • user (String)

    the user to speak to



89
90
91
# File 'lib/message.rb', line 89

def chat user
  participle.command "join", "pchat:%s" % [participle.configuration.nick, user].map(&:downcase).sort.join(":")
end

#join(channel) ⇒ void

This method returns an undefined value.

Join a room.

Parameters:

  • channel (String)

    the room to join



82
83
84
# File 'lib/message.rb', line 82

def join channel
  participle.command "join", "chat:#{channel}"
end

#kick(user, reason = nil) ⇒ void

This method returns an undefined value.

Kick a user with optional reason.

Parameters:

  • user (String)

    the user to kick

  • reason (String) (defaults to: nil)

    why you're kicking them



67
68
69
# File 'lib/message.rb', line 67

def kick user, reason = nil
  participle.kick user, @room.name_formatted, reason
end

#membersHash<Symbol, OpenStruct>

List of members in the current room.

Returns:

  • (Hash<Symbol, OpenStruct>)

    the room's members



102
103
104
# File 'lib/message.rb', line 102

def members
  @room.members
end

#part(channel) ⇒ void

This method returns an undefined value.

Part a room.

Parameters:

  • channel (String)

    the room to leave



96
97
98
# File 'lib/message.rb', line 96

def part channel
  participle.command "part", "chat:#{channel}"
end

#participleParticiple::Bot

The running bot.

Returns:



114
115
116
# File 'lib/message.rb', line 114

def participle
  self.class.bot
end

#privclassesHash<Symbol, Privclass>

List of privclasses in the current room.

Returns:

  • (Hash<Symbol, Privclass>)

    the list of room privclasses



108
109
110
# File 'lib/message.rb', line 108

def privclasses
  @room.privclasses
end

#reply(line, opts = {}) ⇒ void

This method returns an undefined value.

The quintessential message command. Prints out line in the current room.

Parameters:

  • line (String)

    the line to send

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :parsed (Boolean)

    whether to send this message as a parsed message or not



49
50
51
52
53
# File 'lib/message.rb', line 49

def reply line, opts = {}
  return if participle.silent
  options = ({:parsed => true}).merge(opts)
  participle.say line, @room.name_formatted, options[:parsed]
end

#utility(methodname, *args) ⇒ Object

Call a Utils method by name

Parameters:

  • methodname (Symbol)

    the method to call

  • args (Array)

    arguments to pass



41
42
43
# File 'lib/message.rb', line 41

def utility methodname, *args
  Utils.instance_method(methodname.to_sym).bind(self).call(*args)
end