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

- (Message) initialize(pkt, username)

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

- (Object) method_missing(m, *args, &blk)

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

+ (Object) bot

Returns the value of attribute bot



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

def bot
  @bot
end

Instance Attribute Details

- (Bot) bot (readonly)

Returns the current bot

Returns:

  • (Bot)

    the current bot



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

def bot
  @bot
end

- (Array<String>) line (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

- (Packet) packet (readonly)

Returns the corresponding packet

Returns:

  • (Packet)

    the corresponding packet



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

def packet
  @packet
end

- (DA::Room) room

Returns the message's room

Returns:



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

def room
  @room
end

- (String) roomtype=(value) (writeonly)

Returns:

  • (String)


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

def roomtype=(value)
  @roomtype = value
end

- (DA::User) 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

- (void) action(line)

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

- (void) ban(user, reason = nil)

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

- (String) body

Returns:

  • (String)


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

def body
  @packet.body
end

- (void) chat(user)

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

- (void) join(channel)

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

- (void) kick(user, reason = nil)

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

- (Hash<Symbol, OpenStruct>) members

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

- (void) part(channel)

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

- (Participle::Bot) participle

The running bot.

Returns:



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

def participle
  self.class.bot
end

- (Hash<Symbol, Privclass>) privclasses

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

- (void) reply(line, opts = {})

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

- (Object) utility(methodname, *args)

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