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)



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)



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

def bot
  @bot
end

- (Array<String>) line (readonly)



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

def line
  @line
end

- (Packet) packet (readonly)



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

def packet
  @packet
end

- (DA::Room) room



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

def room
  @room
end

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



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

def roomtype=(value)
  @roomtype = value
end

- (DA::User) user (readonly)



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.



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.



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

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

- (String) body



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.



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.



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.



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.



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.



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

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

- (Participle::Bot) participle

The running bot.



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.



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.

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



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

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