Class: Participle::Message
- Inherits:
-
Object
- Object
- Participle::Message
- Defined in:
- lib/message.rb
Overview
Any line said by any user in any room. May be replied to.
Class Attribute Summary (collapse)
-
+ (Object) bot
Returns the value of attribute bot.
Instance Attribute Summary (collapse)
-
- (Bot) bot
readonly
The current bot.
-
- (Array<String>) line
readonly
The message body split by newlines.
-
- (Packet) packet
readonly
The corresponding packet.
-
- (DA::Room) room
The message's room.
- - (String) roomtype writeonly
-
- (DA::User) user
readonly
The sayer of the message.
Instance Method Summary (collapse)
-
- (void) action(line)
Sends an action of line to the current room.
-
- (void) ban(user, reason = nil)
Ban a user with optional reason.
- - (String) body
-
- (void) chat(user)
Open a private chat with a user.
-
- (Message) initialize(pkt, username)
constructor
A new instance of Message.
-
- (void) join(channel)
Join a room.
-
- (void) kick(user, reason = nil)
Kick a user with optional reason.
-
- (Hash<Symbol, OpenStruct>) members
List of members in the current room.
-
- (Object) method_missing(m, *args, &blk)
Defer unmatched method calls to the bot.
-
- (void) part(channel)
Part a room.
-
- (Participle::Bot) participle
The running bot.
-
- (Hash<Symbol, Privclass>) privclasses
List of privclasses in the current room.
-
- (void) reply(line, opts = {})
The quintessential message command.
-
- (Object) utility(methodname, *args)
Call a Utils method by name.
Constructor Details
- (Message) initialize(pkt, username)
A new instance of Message
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
- (Array<String>) line (readonly)
The message body split by newlines
11 12 13 |
# File 'lib/message.rb', line 11 def line @line end |
- (Packet) packet (readonly)
The corresponding packet
13 14 15 |
# File 'lib/message.rb', line 13 def packet @packet end |
- (String) roomtype=(value) (writeonly)
17 18 19 |
# File 'lib/message.rb', line 17 def roomtype=(value) @roomtype = value end |
- (DA::User) user (readonly)
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.
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.
49 50 51 52 53 |
# File 'lib/message.rb', line 49 def reply line, opts = {} return if participle.silent = ({:parsed => true}).merge(opts) participle.say line, @room.name_formatted, [: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 |