Class: Weechat::IRC::Channel

Inherits:
Object
  • Object
show all
Extended by:
Properties
Includes:
Pointer
Defined in:
lib/weechat/channel.rb

Instance Attribute Summary collapse

Attributes included from Pointer

#ptr

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Properties::ClassMethods

#apply_transformation, #init_properties, #known_integer_properties, #known_properties, #known_string_properties, #mappings, #rtransformations, #settable_properties, #transformations, #type

Methods included from Pointer

#==, #hash, #inspect, #to_s

Constructor Details

#initialize(buffer) ⇒ Channel

Returns a new instance of Channel.



29
30
31
32
33
34
35
# File 'lib/weechat/channel.rb', line 29

def initialize(buffer)
  @buffer = Buffer.new(buffer.to_s)
  @ptr    = @buffer.ptr
  if not ["channel"].include?(@buffer.localvar_type)
    raise Exception::NotAChannel, buffer.ptr
  end
end

Instance Attribute Details

#bufferObject (readonly)

Returns the value of attribute buffer.



28
29
30
# File 'lib/weechat/channel.rb', line 28

def buffer
  @buffer
end

Class Method Details

.channelsObject Also known as: all



16
17
18
# File 'lib/weechat/channel.rb', line 16

def channels
  Weechat::Buffer.all.select {|b| b.channel?}.map{|b| b.channel}
end

.find(server, channel) ⇒ Object



21
22
23
24
25
# File 'lib/weechat/channel.rb', line 21

def find(server, channel)
  server  = server.name if server.respond_to?(:name)
  channel = channel.name if channel.respond_to?(:name)
  Weechat::Buffer.find("irc", "#{server}.#{channel}")
end

Instance Method Details

#command(*parts) ⇒ Object Also known as: send_command, exec, execute



68
69
70
# File 'lib/weechat/channel.rb', line 68

def command(*parts)
  @buffer.command(*parts)
end

#get_infolist(*fields) ⇒ Object



37
38
39
40
# File 'lib/weechat/channel.rb', line 37

def get_infolist(*fields)
  list = Weechat::Infolist.parse("irc_channel", "", server.name, {:buffer => [:pointer, @ptr]}, *fields)
  list.empty? ? [{}] : list
end

#join(password = "") ⇒ Object



50
51
52
# File 'lib/weechat/channel.rb', line 50

def join(password = "")
  @buffer.command("/join #{self.name} #{password}")
end

#nicksObject Also known as: users



60
61
62
63
64
65
# File 'lib/weechat/channel.rb', line 60

def nicks
  Weechat::Infolist.parse("irc_nick", "",
                          "#{self.server.name},#{self.name}").map {|user|
    IRC::User.new(user.merge({:channel => self}))
  }
end

#part(reason = "") ⇒ Object



46
47
48
# File 'lib/weechat/channel.rb', line 46

def part(reason="")
  @buffer.command("/part #{self.name} #{reason}")
end

#rejoin(password = "") ⇒ Object Also known as: cycle



54
55
56
57
# File 'lib/weechat/channel.rb', line 54

def rejoin(password = "")
  part(reason)
  join(password)
end

#send(*text) ⇒ Object Also known as: privmsg, say



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

def send(*text)
  @buffer.send(*text)
end

#serverObject



42
43
44
# File 'lib/weechat/channel.rb', line 42

def server
  IRC::Server.new(@buffer.localvar_server)
end