Class: Weechat::IRC::Channel

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

Direct Known Subclasses

Query

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Properties::ClassMethods

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

Methods included from Pointer

#hash, included, #inspect, #to_s

Constructor Details

#initialize(*args) ⇒ Channel

Returns a new instance of Channel



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/weechat/irc/channel.rb', line 42

def initialize(*args)
  if args.size == 1
    # assume buffer
    @buffer = args.first
    @ptr    = @buffer.ptr

    if not ["channel", "private"].include?(@buffer.localvar_type)
      raise Exception::NotAChannel, buffer.ptr
    end

    @server = IRC::Server.from_name(@buffer.localvar_server)
    @name   = self.to_h[:name]
  elsif args.size == 2
    # assume server(name) and channelname
    @server = args.first
    @server = IRC::Server.from_name(@server) unless @server.is_a?(IRC::Server)
    @name = args.last
  else
    raise
  end
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name



31
32
33
# File 'lib/weechat/irc/channel.rb', line 31

def name
  @name
end

#serverObject (readonly)

Returns the value of attribute server



30
31
32
# File 'lib/weechat/irc/channel.rb', line 30

def server
  @server
end

Class Method Details

.allObject



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

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

.find(server, channel) ⇒ Object



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

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

Instance Method Details

#==(other) ⇒ Object Also known as: eql?, equal?



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

def ==(other)
  other.is_a?(Channel) &&
    @server == other.server &&
    @name   == other.name
end

#bufferObject



33
34
35
# File 'lib/weechat/irc/channel.rb', line 33

def buffer
  @buffer || Weechat::Buffer.from_ptr(super) rescue nil
end

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



110
111
112
113
# File 'lib/weechat/irc/channel.rb', line 110

def command(*parts)
  raise Exception::NotJoined unless joined?
  @buffer.command(*parts)
end

#get_infolist(*fields) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/weechat/irc/channel.rb', line 72

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

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

#join(password = "") ⇒ Object



91
92
93
# File 'lib/weechat/irc/channel.rb', line 91

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

#joined?Boolean

Returns:



82
83
84
# File 'lib/weechat/irc/channel.rb', line 82

def joined?
  !!self.buffer
end

#nicksObject Also known as: users



101
102
103
104
105
106
107
# File 'lib/weechat/irc/channel.rb', line 101

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

#part(reason = "") ⇒ Object



86
87
88
89
# File 'lib/weechat/irc/channel.rb', line 86

def part(reason="")
  raise Exception::NotJoined unless joined?
  @server.command("/part #{self.name} #{reason}")
end

#ptrObject Also known as: pointer



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

def ptr
  @ptr || buffer.ptr rescue nil
end

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



95
96
97
98
# File 'lib/weechat/irc/channel.rb', line 95

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

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



118
119
120
121
122
# File 'lib/weechat/irc/channel.rb', line 118

def send(*text)
  # FIXME allow sending to not joined channels
  raise Exception::NotJoined unless joined?
  @buffer.send(*text)
end