Class: TeamSpeak3::Channel

Inherits:
Object
  • Object
show all
Defined in:
lib/channel.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(virtual_server, params) ⇒ Channel

Returns a new instance of Channel.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/channel.rb', line 26

def initialize(virtual_server, params)
  @virtual_server = virtual_server

  @id = params[:cid].to_i
  @pid = params[:pid].to_i
  @name = params[:channel_name]
  @order = params[:order].to_i
  @total_clients = params[:total_clients].to_i
  @needed_subscribe_power = params[:channel_needed_subscribe_power].to_i

  # option: :topic
  @topic = params[:channel_topic]

  # option: :flags
  @flags = []
  @flags << :default if params[:channel_flag_default].to_i == 1
  @flags << :password if params[:channel_flag_password].to_i == 1
  @flags << :permanent if params[:channel_flag_permanent].to_i == 1
  @flags << :semi_permanent if params[:channel_flag_semi_permanent].to_i == 1

  # option: :voice
  @codec = params[:channel_codec].to_i
  @codec_quality = params[:channel_codec_quality].to_i
  @needed_talk_power = params[:channel_needed_talk_power].to_i

  # option: :icon
  @icon_id = params[:channel_icon_id].to_i

  # option: :limits
  @total_clients_family = params[:total_clients_family].to_i
  @max_clients = params[:channel_maxclients].to_i
  @max_family_clients = params[:channel_maxfamilyclients].to_i
end

Instance Attribute Details

#codecObject (readonly)

Returns the value of attribute codec.



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

def codec
  @codec
end

#codec_qualityObject (readonly)

Returns the value of attribute codec_quality.



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

def codec_quality
  @codec_quality
end

#flagsObject (readonly)

Returns the value of attribute flags.



14
15
16
# File 'lib/channel.rb', line 14

def flags
  @flags
end

#icon_idObject (readonly)

Returns the value of attribute icon_id.



20
21
22
# File 'lib/channel.rb', line 20

def icon_id
  @icon_id
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/channel.rb', line 5

def id
  @id
end

#max_clientsObject (readonly)

Returns the value of attribute max_clients.



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

def max_clients
  @max_clients
end

#max_family_clientsObject (readonly)

Returns the value of attribute max_family_clients.



24
25
26
# File 'lib/channel.rb', line 24

def max_family_clients
  @max_family_clients
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/channel.rb', line 7

def name
  @name
end

#needed_subscribe_powerObject (readonly)

Returns the value of attribute needed_subscribe_power.



10
11
12
# File 'lib/channel.rb', line 10

def needed_subscribe_power
  @needed_subscribe_power
end

#needed_talk_powerObject (readonly)

Returns the value of attribute needed_talk_power.



18
19
20
# File 'lib/channel.rb', line 18

def needed_talk_power
  @needed_talk_power
end

#orderObject (readonly)

Returns the value of attribute order.



8
9
10
# File 'lib/channel.rb', line 8

def order
  @order
end

#pidObject (readonly)

Returns the value of attribute pid.



6
7
8
# File 'lib/channel.rb', line 6

def pid
  @pid
end

#topicObject (readonly)

Returns the value of attribute topic.



12
13
14
# File 'lib/channel.rb', line 12

def topic
  @topic
end

#total_clientsObject (readonly)

Returns the value of attribute total_clients.



9
10
11
# File 'lib/channel.rb', line 9

def total_clients
  @total_clients
end

#total_clients_familyObject (readonly)

Returns the value of attribute total_clients_family.



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

def total_clients_family
  @total_clients_family
end

#virtual_serverObject (readonly)

Returns the value of attribute virtual_server.



3
4
5
# File 'lib/channel.rb', line 3

def virtual_server
  @virtual_server
end

Class Method Details

.create(virtual_server, name, opts = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/channel.rb', line 60

def self.create(virtual_server, name, opts = {})
  command_parameters = { channel_name: name }

  command_parameters[:channel_topic] = opts[:topic] if opts[:topic]
  command_parameters[:channel_description] = opts[:description] if opts[:description]
  command_parameters[:channel_password] = opts[:password] if opts[:password]
  command_parameters[:channel_codec] = opts[:codec] if opts[:codec]
  command_parameters[:channel_codec_quality] = opts[:codec_quality] if opts[:codec_quality]
  command_parameters[:channel_maxclients] = opts[:max_clients] if opts[:max_clients]
  command_parameters[:channel_maxfamilyclients] = opts[:max_family_clients] if opts[:max_family_clients]
  command_parameters[:channel_order] = opts[:order] if opts[:order]
  command_parameters[:channel_needed_talk_power] = opts[:needed_talk_power] if opts[:needed_talk_power]
  command_parameters[:channel_name_phonetic] = opts[:name_phonetic] if opts[:name_phonetic]
  command_parameters[:channel_icon_id] = opts[:icon_id] if opts[:icon_id]
  command_parameters[:channel_codec_is_unencrypted] = opts[:codec_is_unencrypted] if opts[:codec_is_unencrypted]
  command_parameters[:cpid] = opts[:parent_id] if opts[:parent_id]

  response = virtual_server.execute :channelcreate, command_parameters
  virtual_server.channels.find(response[:data].first[:cid])
end

Instance Method Details

#==(target) ⇒ Object



114
115
116
# File 'lib/channel.rb', line 114

def ==(target)
  @id == target
end

#codec_nameObject



81
82
83
84
85
86
87
88
# File 'lib/channel.rb', line 81

def codec_name
  return "Speex Narrowband" if @codec == 0
  return "Speex Wideband" if @codec == 1
  return "Speex Ultra-Wideband" if @codec == 2
  return "CELT Mono" if @codec == 3
  return "Opus Voice" if @codec == 4
  return "Opus Music" if @codec == 5
end

#default?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/channel.rb', line 102

def default?
  flag?(:default)
end

#flag?(flag) ⇒ Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/channel.rb', line 106

def flag?(flag)
  @flags.include?(flag.to_sym)
end

#password?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/channel.rb', line 98

def password?
  flag?(:password)
end

#permanent?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/channel.rb', line 90

def permanent?
  flag?(:permanent)
end

#semi_permanent?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/channel.rb', line 94

def semi_permanent?
  flag?(:semi_permanent)
end

#send_message(message) ⇒ Object



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

def send_message(message)
  virtual_server.server.send_message_to(self, message)
end