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



71
72
73
# File 'lib/weechat/channel.rb', line 71

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

#get_infolistObject



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

def get_infolist
  list = Weechat::Infolist.parse("irc_channel", "", server.name).select{|channel|
    channel[:buffer] == @ptr
  }

  list.empty? ? [{}] : list
end

#join(password = "") ⇒ Object



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

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

#nicksObject Also known as: users



63
64
65
66
67
68
# File 'lib/weechat/channel.rb', line 63

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



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

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

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



57
58
59
60
# File 'lib/weechat/channel.rb', line 57

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

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



78
79
80
# File 'lib/weechat/channel.rb', line 78

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

#serverObject



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

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