Class: Coffeemaker::Bot::Irc::Message

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(msg = nil) ⇒ Message

Returns a new instance of Message.



9
10
11
12
# File 'lib/coffeemaker/bot/irc/message.rb', line 9

def initialize(msg = nil)
  @raw = msg
  parse if msg
end

Instance Attribute Details

#paramsObject

Returns the value of attribute params.



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

def params
  @params
end

#prefixObject

Returns the value of attribute prefix.



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

def prefix
  @prefix
end

#rawObject

Returns the value of attribute raw.



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

def raw
  @raw
end

Instance Method Details

#channelObject



56
57
58
59
60
61
# File 'lib/coffeemaker/bot/irc/message.rb', line 56

def channel
  return @channel if @channel
  if regular_command? and params.first.start_with?("#")
    @channel = params.first
  end
end

#channel?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/coffeemaker/bot/irc/message.rb', line 52

def channel?
  !!channel
end

#commandObject



72
73
74
# File 'lib/coffeemaker/bot/irc/message.rb', line 72

def command
  @command.downcase.to_sym
end

#errorObject



47
48
49
50
# File 'lib/coffeemaker/bot/irc/message.rb', line 47

def error
  return @error if @error
  @error = @command.to_i if numeric_reply? && @command[/[45]\d\d/]
end

#error?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/coffeemaker/bot/irc/message.rb', line 43

def error?
  !!error
end

#hostObject



32
33
34
35
# File 'lib/coffeemaker/bot/irc/message.rb', line 32

def host
  return unless @prefix
  @host ||= @prefix[/@(\S+)$/, 1]
end

#messageObject



63
64
65
66
67
68
69
70
# File 'lib/coffeemaker/bot/irc/message.rb', line 63

def message
  return @message if @message
  if error?
    @message = error.to_s
  elsif regular_command?
    @message = params.last
  end
end

#nickObject



22
23
24
25
# File 'lib/coffeemaker/bot/irc/message.rb', line 22

def nick
  return unless @prefix
  @nick ||= @prefix[/^(\S+)!/, 1]
end

#numeric_replyObject



18
19
20
# File 'lib/coffeemaker/bot/irc/message.rb', line 18

def numeric_reply
  @numeric_reply ||= @command.match(/^\d\d\d$/)
end

#numeric_reply?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/coffeemaker/bot/irc/message.rb', line 14

def numeric_reply?
  !!numeric_reply
end

#serverObject



37
38
39
40
41
# File 'lib/coffeemaker/bot/irc/message.rb', line 37

def server
  return unless @prefix
  return if @prefix.match(/[@!]/)
  @server ||= @prefix[/^(\S+)/, 1]
end

#userObject



27
28
29
30
# File 'lib/coffeemaker/bot/irc/message.rb', line 27

def user
  return unless @prefix
  @user ||= @prefix[/^\S+!(\S+)@/, 1]
end