weechat 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +62 -0
- data/Rakefile +1 -1
- data/TODO +7 -7
- data/lib/weechat.rb +22 -9
- data/lib/weechat/blankslate.rb +1 -11
- data/lib/weechat/buffer.rb +12 -6
- data/lib/weechat/channel.rb +72 -0
- data/lib/weechat/exceptions.rb +6 -0
- data/lib/weechat/host.rb +16 -0
- data/lib/weechat/infolist.rb +37 -0
- data/lib/weechat/option.rb +10 -7
- data/lib/weechat/pointer.rb +1 -1
- data/lib/weechat/properties.rb +12 -12
- data/lib/weechat/property.rb +9 -6
- data/lib/weechat/rubyext/object.rb +2 -0
- data/lib/weechat/script/config.rb +3 -3
- data/lib/weechat/server.rb +47 -48
- data/lib/weechat/user.rb +64 -0
- metadata +5 -2
data/ChangeLog
CHANGED
@@ -0,0 +1,62 @@
|
|
1
|
+
2009-12-21 Dominik Honnef <dominikho@gmx.net>
|
2
|
+
|
3
|
+
* Rakefile: bumped version to 0.0.2
|
4
|
+
* lib/weechat.rb (Weechat): bumped version to 0.0.2
|
5
|
+
|
6
|
+
* lib/weechat/channel.rb (Weechat::IRC::Channel#nicks): added support for users
|
7
|
+
* lib/weechat/host.rb (Weechat::IRC::Host): added support for users
|
8
|
+
* lib/weechat/user.rb (Weechat::IRC::User): added support for users
|
9
|
+
|
10
|
+
* lib/weechat/channel.rb (Weechat::IRC::Channel#join)
|
11
|
+
(Weechat::IRC::Channel#rejoin): added support for channel
|
12
|
+
passwords
|
13
|
+
(Weechat::IRC::Channel#command, Weechat::IRC::Channel#send): added
|
14
|
+
support for sending commands/messages to channels
|
15
|
+
|
16
|
+
* lib/weechat/pointer.rb (Weechat::Pointer#initialize): fixed
|
17
|
+
pointer comparison
|
18
|
+
|
19
|
+
* lib/weechat/script/config.rb (Weechat::Script::Config#set):
|
20
|
+
fixed memory leak
|
21
|
+
* lib/weechat/properties.rb (Weechat::Properties::InstanceMethods#set_property):
|
22
|
+
fixed memory leak
|
23
|
+
* lib/weechat/option.rb (Weechat::Option): fixed memory leak
|
24
|
+
* lib/weechat/property.rb (Weechat::Property): fixed memory leak
|
25
|
+
|
26
|
+
2009-12-18 Dominik Honnef <dominikho@gmx.net>
|
27
|
+
|
28
|
+
* lib/weechat/channel.rb (Weechat::IRC::Channel): added support
|
29
|
+
for channels
|
30
|
+
* lib/weechat/buffer.rb (Weechat::Buffer#channel)
|
31
|
+
(Weechat::Buffer#channel?): added support for channels
|
32
|
+
|
33
|
+
* lib/weechat.rb (Weechat::Helper#get_buffer): put logic of
|
34
|
+
determining buffer into own method, changed methods accordingly
|
35
|
+
(Weechat::Helper#puts_y): added support for print_y
|
36
|
+
|
37
|
+
* lib/weechat/server.rb (Weechat::IRC::Server#initialize): use a
|
38
|
+
proper exception use existing properties architecture
|
39
|
+
|
40
|
+
* lib/weechat/buffer.rb: style changes wrt exceptions
|
41
|
+
* lib/weechat/properties.rb: style changes wrt exceptions
|
42
|
+
(Weechat::Properties::InstanceMethods#valid_property): fixed check
|
43
|
+
for values that are false
|
44
|
+
(Weechat::Properties::InstanceMethods#to_h): tweak performance by
|
45
|
+
reusing infolist
|
46
|
+
|
47
|
+
* lib/weechat/rubyext/object.rb (Object#__class__): added
|
48
|
+
__class__ as an alias for class
|
49
|
+
* lib/weechat/blankslate.rb (Blankslate): use Object#__class__
|
50
|
+
|
51
|
+
* lib/weechat/blankslate.rb (Blankslate): don't undef object_id
|
52
|
+
anymore
|
53
|
+
|
54
|
+
2009-12-14 Dominik Honnef <dominikho@gmx.net>
|
55
|
+
|
56
|
+
* lib/weechat/server.rb (Weechat::IRC::Server.servers): renamed
|
57
|
+
Server.buffers to Server.servers
|
58
|
+
|
59
|
+
2009-12-14 Dominik Honnef <dominikho@gmx.net>
|
60
|
+
* *: initial release
|
61
|
+
* lib/weechat.rb (Weechat): bumped version to 0.0.1
|
62
|
+
|
data/Rakefile
CHANGED
data/TODO
CHANGED
@@ -79,7 +79,7 @@ display:
|
|
79
79
|
[x] color
|
80
80
|
[x] print
|
81
81
|
[ ] print_date_tags
|
82
|
-
[
|
82
|
+
[x] print_y
|
83
83
|
[x] log_print
|
84
84
|
|
85
85
|
hooks:
|
@@ -163,11 +163,11 @@ info_get
|
|
163
163
|
[x] weechat_sharedir
|
164
164
|
|
165
165
|
infolists:
|
166
|
-
[
|
167
|
-
[
|
168
|
-
[
|
169
|
-
[
|
170
|
-
[
|
166
|
+
[/] infolist_new
|
167
|
+
[/] infolist_new_var_integer
|
168
|
+
[/] infolist_new_var_string
|
169
|
+
[/] infolist_new_var_pointer
|
170
|
+
[/] infolist_new_var_time
|
171
171
|
[x] infolist_get
|
172
172
|
[x] infolist_next
|
173
173
|
[-] infolist_prev
|
@@ -185,4 +185,4 @@ upgrade:
|
|
185
185
|
[ ] upgrade_close
|
186
186
|
|
187
187
|
Functionality:
|
188
|
-
[
|
188
|
+
[x] if a buffer is a channel, get nicks, usercount, topic, etc
|
data/lib/weechat.rb
CHANGED
@@ -6,7 +6,7 @@ end
|
|
6
6
|
require 'pp'
|
7
7
|
|
8
8
|
module Weechat
|
9
|
-
VERSION = "0.0.
|
9
|
+
VERSION = "0.0.2"
|
10
10
|
module Helper
|
11
11
|
def command_callback(id, buffer, args)
|
12
12
|
Weechat::Command.find_by_id(id).call(Weechat::Buffer.new(buffer), args)
|
@@ -97,6 +97,17 @@ module Weechat
|
|
97
97
|
end
|
98
98
|
|
99
99
|
class << self
|
100
|
+
def get_buffer(buffer = nil)
|
101
|
+
case buffer
|
102
|
+
when nil
|
103
|
+
""
|
104
|
+
when :current
|
105
|
+
Weechat::Buffer.current
|
106
|
+
else
|
107
|
+
buffer
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
100
111
|
def exec(command, buffer=nil)
|
101
112
|
Weechat.command(buffer.to_s, command)
|
102
113
|
end
|
@@ -104,18 +115,17 @@ module Weechat
|
|
104
115
|
alias_method :execute, :exec
|
105
116
|
|
106
117
|
def puts(text, buffer = nil)
|
107
|
-
buffer =
|
108
|
-
when nil
|
109
|
-
""
|
110
|
-
when :current
|
111
|
-
Weechat::Buffer.current
|
112
|
-
else
|
113
|
-
buffer
|
114
|
-
end
|
118
|
+
buffer = get_buffer(buffer)
|
115
119
|
Weechat.print(buffer.to_s, text.to_s)
|
116
120
|
nil # to mimic Kernel::puts
|
117
121
|
end
|
118
122
|
|
123
|
+
def puts_y(text, line, buffer = nil)
|
124
|
+
buffer = get_buffer(buffer)
|
125
|
+
Weechat.print_y(text.to_s, line, buffer.to_s)
|
126
|
+
nil # to mimic Kernel::puts
|
127
|
+
end
|
128
|
+
|
119
129
|
def p(object, buffer = nil)
|
120
130
|
self.puts(object.inspect, buffer)
|
121
131
|
end
|
@@ -212,6 +222,9 @@ require 'weechat/input.rb'
|
|
212
222
|
require 'weechat/buffer.rb'
|
213
223
|
require 'weechat/window.rb'
|
214
224
|
require 'weechat/server.rb'
|
225
|
+
require 'weechat/channel.rb'
|
226
|
+
require 'weechat/user.rb'
|
227
|
+
require 'weechat/host.rb'
|
215
228
|
require 'weechat/infolist.rb'
|
216
229
|
require 'weechat/color.rb'
|
217
230
|
require 'weechat/plugin.rb'
|
data/lib/weechat/blankslate.rb
CHANGED
@@ -1,13 +1,3 @@
|
|
1
|
-
class NullOutput
|
2
|
-
def write(*args)
|
3
|
-
end
|
4
|
-
end
|
5
|
-
|
6
1
|
class Blankslate
|
7
|
-
|
8
|
-
|
9
|
-
old_stderr = $stderr.dup
|
10
|
-
$stderr = NullOutput.new
|
11
|
-
instance_methods.each { |m| undef_method m unless m =~ /^__/ }
|
12
|
-
$stderr = old_stderr
|
2
|
+
instance_methods.each { |m| undef_method m unless m =~ /^__/ || m.to_s == 'object_id' }
|
13
3
|
end
|
data/lib/weechat/buffer.rb
CHANGED
@@ -159,11 +159,11 @@ module Weechat
|
|
159
159
|
},
|
160
160
|
[:notify] => lambda {|v|
|
161
161
|
i = NOTIFY_LEVELS.index(v)
|
162
|
-
i or raise Exception::InvalidPropertyValue
|
162
|
+
i or raise Exception::InvalidPropertyValue, v.to_s
|
163
163
|
},
|
164
164
|
[:type] => lambda {|v|
|
165
165
|
v = v.to_s
|
166
|
-
raise Exception::InvalidPropertyValue
|
166
|
+
raise Exception::InvalidPropertyValue, v if !["formatted", "free"].include?(v)
|
167
167
|
v
|
168
168
|
},
|
169
169
|
}.freeze
|
@@ -316,7 +316,7 @@ module Weechat
|
|
316
316
|
id = @callbacks.size - 1
|
317
317
|
ptr = Weechat.buffer_new(name.to_s, "input_callback", id.to_s, "close_callback", id.to_s)
|
318
318
|
if ptr.empty?
|
319
|
-
raise Exception::DuplicateBufferName
|
319
|
+
raise Exception::DuplicateBufferName, name.to_s
|
320
320
|
else
|
321
321
|
@callbacks[-1][:ptr] = ptr
|
322
322
|
Buffer.new(ptr)
|
@@ -357,9 +357,15 @@ module Weechat
|
|
357
357
|
#
|
358
358
|
# @return [Boolean]
|
359
359
|
def channel?
|
360
|
-
|
361
|
-
|
362
|
-
|
360
|
+
self.localvar_type == "channel"
|
361
|
+
end
|
362
|
+
|
363
|
+
# Returns the channel associated with the buffer.
|
364
|
+
#
|
365
|
+
# @raise [Exception::NotAChannel]
|
366
|
+
# @return [IRC::Channel]
|
367
|
+
def channel
|
368
|
+
IRC::Channel.new(self)
|
363
369
|
end
|
364
370
|
|
365
371
|
# Send a command to the current buffer.
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Weechat
|
2
|
+
module IRC
|
3
|
+
class Channel
|
4
|
+
include Weechat::Pointer
|
5
|
+
extend Weechat::Properties
|
6
|
+
|
7
|
+
@transformations = {
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
@mappings = {
|
11
|
+
}.freeze
|
12
|
+
|
13
|
+
init_properties
|
14
|
+
|
15
|
+
attr_reader :buffer
|
16
|
+
def initialize(buffer)
|
17
|
+
@buffer = Buffer.new(buffer.to_s)
|
18
|
+
@ptr = @buffer.ptr
|
19
|
+
if not ["channel"].include?(@buffer.localvar_type)
|
20
|
+
raise Exception::NotAChannel, buffer.ptr
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def get_infolist
|
25
|
+
Weechat::IRC::Server.all.map{|server|
|
26
|
+
Weechat::Infolist.parse("irc_channel", "", server.name).find{|channel|
|
27
|
+
channel[:buffer] == @ptr
|
28
|
+
}
|
29
|
+
}.compact
|
30
|
+
end
|
31
|
+
|
32
|
+
def server
|
33
|
+
IRC::Server.new(@buffer.localvar_server)
|
34
|
+
end
|
35
|
+
|
36
|
+
def part(reason="")
|
37
|
+
@buffer.command("/part #{self.name} #{reason}")
|
38
|
+
end
|
39
|
+
|
40
|
+
def join(password = "")
|
41
|
+
@buffer.command("/join #{self.name} #{password}")
|
42
|
+
end
|
43
|
+
|
44
|
+
def rejoin(password = "")
|
45
|
+
part(reason)
|
46
|
+
join(password)
|
47
|
+
end
|
48
|
+
alias_method :cycle, :rejoin
|
49
|
+
|
50
|
+
def nicks
|
51
|
+
Weechat::Infolist.parse("irc_nick", "",
|
52
|
+
"#{self.server.name},#{self.name}").map {|user|
|
53
|
+
IRC::User.new(user.merge({:channel => self}))
|
54
|
+
}
|
55
|
+
end
|
56
|
+
alias_method :users, :nicks
|
57
|
+
|
58
|
+
def command(*parts)
|
59
|
+
@buffer.command(*parts)
|
60
|
+
end
|
61
|
+
alias_method :send_command, :command
|
62
|
+
alias_method :exec, :command
|
63
|
+
alias_method :execute, :command
|
64
|
+
|
65
|
+
def send(*text)
|
66
|
+
@buffer.send(*text)
|
67
|
+
end
|
68
|
+
alias_method :privmsg, :send
|
69
|
+
alias_method :say, :send
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/weechat/exceptions.rb
CHANGED
@@ -27,5 +27,11 @@ module Weechat
|
|
27
27
|
class WEECHAT_RC_OK < ::Exception; end
|
28
28
|
class WEECHAT_RC_ERROR < ::Exception; end
|
29
29
|
class WEECHAT_RC_OK_EAT < ::Exception; end
|
30
|
+
|
31
|
+
# This exception gets raised when one tries to receive the channel
|
32
|
+
# of a buffer which does not represent one.
|
33
|
+
class NotAChannel < RuntimeError; end
|
34
|
+
|
35
|
+
class UnknownServer < RuntimeError; end
|
30
36
|
end
|
31
37
|
end
|
data/lib/weechat/host.rb
ADDED
data/lib/weechat/infolist.rb
CHANGED
@@ -1,5 +1,42 @@
|
|
1
1
|
module Weechat
|
2
2
|
class Infolist
|
3
|
+
# class Item
|
4
|
+
# def initialize(infolist)
|
5
|
+
# @ptr = Weechat.infolist_new_item(infolist.ptr)
|
6
|
+
# end
|
7
|
+
|
8
|
+
# def []=(name, value)
|
9
|
+
# type = case value
|
10
|
+
# when String
|
11
|
+
# value = value.to_s
|
12
|
+
# 'string'
|
13
|
+
# when Numeric
|
14
|
+
# 'integer'
|
15
|
+
# when Weechat::Pointer
|
16
|
+
# value = value.ptr
|
17
|
+
# 'pointer'
|
18
|
+
# when Date, Time, DateTime
|
19
|
+
# # TODO implement time
|
20
|
+
# else
|
21
|
+
# value= value.to_s
|
22
|
+
# 'string'
|
23
|
+
# end
|
24
|
+
|
25
|
+
# m = "infolist_new_var_#{type}"
|
26
|
+
# Weechat.__send__(m, name.to_s, value)
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
|
30
|
+
# attr_reader :ptr
|
31
|
+
# def initialize
|
32
|
+
# @ptr = Weechat.infolist_new
|
33
|
+
# @items = Hash.new {|hash, key| hash[key] = Infolist::Item.new(self)}
|
34
|
+
# end
|
35
|
+
|
36
|
+
# def [](item)
|
37
|
+
# @items[item]
|
38
|
+
# end
|
39
|
+
|
3
40
|
def self.parse(type, ptr="", arguments="")
|
4
41
|
infolist_ptr = Weechat.infolist_get(type, ptr, arguments)
|
5
42
|
ret = []
|
data/lib/weechat/option.rb
CHANGED
@@ -4,18 +4,21 @@ module Weechat
|
|
4
4
|
# blankslate... breaks things
|
5
5
|
|
6
6
|
|
7
|
-
def self.options
|
8
|
-
@options
|
9
|
-
end
|
10
|
-
|
11
7
|
def initialize(config, option)
|
12
|
-
self.__class__.options << [config, option, self]
|
13
8
|
@old_obj = config.__get(option)
|
14
|
-
@config
|
15
|
-
@option
|
9
|
+
@config = config
|
10
|
+
@option = option
|
16
11
|
@frozen = false
|
17
12
|
end
|
18
13
|
|
14
|
+
def __config__
|
15
|
+
@config
|
16
|
+
end
|
17
|
+
|
18
|
+
def __option__
|
19
|
+
@option
|
20
|
+
end
|
21
|
+
|
19
22
|
def __freeze__
|
20
23
|
@frozen = true
|
21
24
|
end
|
data/lib/weechat/pointer.rb
CHANGED
data/lib/weechat/properties.rb
CHANGED
@@ -90,7 +90,7 @@ module Weechat
|
|
90
90
|
# @see #get_infolist_property
|
91
91
|
# @see #set_property
|
92
92
|
def get_property(property)
|
93
|
-
raise Exception::UnknownProperty
|
93
|
+
raise Exception::UnknownProperty, property unless valid_property?(property)
|
94
94
|
case ret = __get_property(property)
|
95
95
|
when true, false, nil
|
96
96
|
ret
|
@@ -109,7 +109,7 @@ module Weechat
|
|
109
109
|
elsif valid_property?(property, :infolist)
|
110
110
|
v = get_infolist_property(property)
|
111
111
|
else
|
112
|
-
raise Exception::UnknownProperty
|
112
|
+
raise Exception::UnknownProperty, property
|
113
113
|
end
|
114
114
|
|
115
115
|
return self.class.apply_transformation(property, v)
|
@@ -125,7 +125,7 @@ module Weechat
|
|
125
125
|
# @see #get_infolist_property
|
126
126
|
def get_integer_property(property)
|
127
127
|
property = property.to_s
|
128
|
-
raise Exception::UnknownProperty
|
128
|
+
raise Exception::UnknownProperty, property unless valid_property?(property, :integer)
|
129
129
|
get_integer(property)
|
130
130
|
end
|
131
131
|
|
@@ -149,7 +149,7 @@ module Weechat
|
|
149
149
|
# @see #set_string_property
|
150
150
|
def get_string_property(property)
|
151
151
|
property = property.to_s
|
152
|
-
raise Exception::UnknownProperty
|
152
|
+
raise Exception::UnknownProperty, property unless valid_property?(property, :string)
|
153
153
|
get_string(property)
|
154
154
|
end
|
155
155
|
|
@@ -181,7 +181,7 @@ module Weechat
|
|
181
181
|
def get_infolist_property(property)
|
182
182
|
property = property.to_sym
|
183
183
|
values = get_infolist.first
|
184
|
-
raise Exception::UnknownProperty
|
184
|
+
raise Exception::UnknownProperty, property.to_s unless values.has_key?(property)
|
185
185
|
values[property]
|
186
186
|
end
|
187
187
|
|
@@ -207,14 +207,14 @@ module Weechat
|
|
207
207
|
# @see #set
|
208
208
|
def set_property(property, v, freeze = false)
|
209
209
|
property = property.to_s
|
210
|
-
raise Exception::UnsettableProperty
|
210
|
+
raise Exception::UnsettableProperty, property unless settable_property?(property)
|
211
211
|
v = Utilities.apply_transformation(property, v, self.class.rtransformations)
|
212
212
|
|
213
213
|
set(property, v)
|
214
214
|
if freeze
|
215
|
-
Property.
|
216
|
-
if prop
|
217
|
-
prop
|
215
|
+
ObjectSpace.each_object(Weechat::Property).each do |prop|
|
216
|
+
if prop.__weechat_obj__.ptr == @ptr and prop.__property__ == property
|
217
|
+
prop.__freeze__
|
218
218
|
end
|
219
219
|
end
|
220
220
|
end
|
@@ -228,7 +228,7 @@ module Weechat
|
|
228
228
|
# @see #set
|
229
229
|
def set_string_property(property, v)
|
230
230
|
property = property.to_s
|
231
|
-
raise Exception::UnsettableProperty
|
231
|
+
raise Exception::UnsettableProperty, property unless settable_property?(property)
|
232
232
|
set(property, v)
|
233
233
|
end
|
234
234
|
|
@@ -268,7 +268,7 @@ module Weechat
|
|
268
268
|
when :localvar
|
269
269
|
property =~ /^localvar_.+$/
|
270
270
|
when :infolist
|
271
|
-
get_infolist.first
|
271
|
+
get_infolist.first.has_key?(property.to_sym)
|
272
272
|
end
|
273
273
|
end
|
274
274
|
|
@@ -294,7 +294,7 @@ module Weechat
|
|
294
294
|
end
|
295
295
|
|
296
296
|
get_infolist.first.each do |property, value|
|
297
|
-
prop =
|
297
|
+
prop = self.class.apply_transformation(property, value)
|
298
298
|
h[property] = prop
|
299
299
|
end
|
300
300
|
|
data/lib/weechat/property.rb
CHANGED
@@ -3,13 +3,8 @@ module Weechat
|
|
3
3
|
@properties = [] # we can't use a Hash because hashing
|
4
4
|
# blankslate... breaks things
|
5
5
|
|
6
|
-
|
7
|
-
def self.properties
|
8
|
-
@properties
|
9
|
-
end
|
10
6
|
|
11
7
|
def initialize(weechat_obj, property)
|
12
|
-
self.__class__.properties << [weechat_obj.ptr, property, self]
|
13
8
|
@old_obj = weechat_obj.__get_property(property)
|
14
9
|
@weechat_obj = weechat_obj
|
15
10
|
@property = property
|
@@ -17,6 +12,14 @@ module Weechat
|
|
17
12
|
@frozen = false
|
18
13
|
end
|
19
14
|
|
15
|
+
def __weechat_obj__
|
16
|
+
@weechat_obj
|
17
|
+
end
|
18
|
+
|
19
|
+
def __property__
|
20
|
+
@property
|
21
|
+
end
|
22
|
+
|
20
23
|
def __freeze__
|
21
24
|
@frozen = true
|
22
25
|
end
|
@@ -40,7 +43,7 @@ module Weechat
|
|
40
43
|
@old_obj = obj
|
41
44
|
end
|
42
45
|
end
|
43
|
-
|
46
|
+
|
44
47
|
ret
|
45
48
|
end
|
46
49
|
end
|
@@ -119,9 +119,9 @@ module Weechat
|
|
119
119
|
value = value.to_weechat_config
|
120
120
|
Weechat.config_set_plugin(option.to_s, value)
|
121
121
|
if freeze
|
122
|
-
Option.
|
123
|
-
if opt
|
124
|
-
opt
|
122
|
+
ObjectSpace.each_object(Weechat::Option).each do |opt|
|
123
|
+
if opt.__config__ == self and opt.__option__ == option
|
124
|
+
opt.__freeze__
|
125
125
|
end
|
126
126
|
end
|
127
127
|
end
|
data/lib/weechat/server.rb
CHANGED
@@ -4,8 +4,10 @@ require 'date'
|
|
4
4
|
module Weechat
|
5
5
|
module IRC
|
6
6
|
class Server
|
7
|
+
extend Weechat::Properties
|
8
|
+
|
7
9
|
attr_reader :name
|
8
|
-
|
10
|
+
@transformations = {
|
9
11
|
[:buffer] => lambda {|b|
|
10
12
|
if b.empty?
|
11
13
|
nil
|
@@ -13,79 +15,76 @@ module Weechat
|
|
13
15
|
Weechat::Buffer.new(b)
|
14
16
|
end
|
15
17
|
},
|
16
|
-
[:ipv6, :ssl, :ssl_verify,
|
17
|
-
:
|
18
|
-
:
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
}
|
18
|
+
[:ipv6, :ssl, :ssl_verify, :autoconnect, :autoreconnect,
|
19
|
+
:autorejoin, :temp_server, :is_connected, :ssl_connected,
|
20
|
+
:reconnect_join, :disable_autojoin, :is_away] => lambda {|v|
|
21
|
+
Weechat.integer_to_bool(v)
|
22
|
+
},
|
23
|
+
[:reconnect_start, :command_time, :away_time, :lag_next_check,
|
24
|
+
:last_user_message] => lambda {|v| Date.parse(v) },
|
25
|
+
[:nicks] => lambda {|v| v.split(",") }
|
26
|
+
}.freeze
|
26
27
|
|
27
|
-
|
28
|
+
@mappings = {
|
29
|
+
:ipv6? => :ipv6,
|
30
|
+
:ssl? => :ssl,
|
28
31
|
:autoconnect? => :autoconnect,
|
29
32
|
:autoreconnect? => :autoreconnect,
|
30
33
|
:autorejoin? => :autorejoin,
|
31
34
|
:temp_server? => :temp_server,
|
32
35
|
:connected? => :is_connected,
|
33
36
|
:ssl_connected? => :ssl_connected,
|
34
|
-
:
|
35
|
-
|
37
|
+
:join_on_reconnect? => :reconnect_join,
|
38
|
+
:away? => :is_away,
|
39
|
+
}.freeze
|
40
|
+
|
41
|
+
init_properties
|
36
42
|
|
37
43
|
def autojoin?
|
38
44
|
!disable_autojoin
|
39
45
|
end
|
40
46
|
|
47
|
+
attr_reader :ptr
|
41
48
|
def initialize(name)
|
42
|
-
@name = name
|
49
|
+
@ptr = @name = name.to_s
|
50
|
+
raise Exception::UnknownServer, name if get_infolist.empty?
|
43
51
|
end
|
44
52
|
|
45
53
|
class << self
|
46
54
|
alias_method :from_name, :new
|
47
|
-
end
|
48
55
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
56
|
+
def servers
|
57
|
+
servers = []
|
58
|
+
Weechat::Infolist.parse("irc_server").each do |server|
|
59
|
+
servers << Server.new(server[:name])
|
60
|
+
end
|
61
|
+
servers
|
53
62
|
end
|
54
|
-
servers
|
55
|
-
end
|
56
|
-
class << self
|
57
|
-
alias_method :all, :buffers
|
63
|
+
alias_method :all, :servers
|
58
64
|
end
|
59
65
|
|
60
|
-
|
66
|
+
def channels
|
67
|
+
channels = []
|
68
|
+
Weechat::Infolist.parse("irc_channel", "", @name).each do |channel|
|
69
|
+
channels << IRC::Channel.new(channel[:buffer])
|
70
|
+
end
|
71
|
+
channels
|
72
|
+
end
|
61
73
|
|
62
|
-
def
|
63
|
-
|
74
|
+
def connect
|
75
|
+
return false if connected?
|
76
|
+
Weechat.exec("/connect #{@name}")
|
64
77
|
end
|
65
78
|
|
66
|
-
def
|
67
|
-
if
|
68
|
-
|
69
|
-
else
|
70
|
-
super
|
71
|
-
end
|
79
|
+
def disconnect
|
80
|
+
return false if not connected?
|
81
|
+
self.buffer.exec("/disconnect #{@name}")
|
72
82
|
end
|
73
83
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
v = properties[m]
|
79
|
-
PROCESSORS.each do |key, value|
|
80
|
-
if key.include?(m)
|
81
|
-
v = value.call(v)
|
82
|
-
break
|
83
|
-
end
|
84
|
-
end
|
85
|
-
return v
|
86
|
-
else
|
87
|
-
super
|
88
|
-
end
|
84
|
+
# TODO method for creating a new server
|
85
|
+
|
86
|
+
def get_infolist
|
87
|
+
Weechat::Infolist.parse("irc_server", "", @name)
|
89
88
|
end
|
90
89
|
end
|
91
90
|
end
|
data/lib/weechat/user.rb
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
module Weechat
|
2
|
+
module IRC
|
3
|
+
class User
|
4
|
+
attr_reader :name
|
5
|
+
attr_reader :host
|
6
|
+
attr_reader :flags
|
7
|
+
attr_reader :color
|
8
|
+
attr_reader :channel
|
9
|
+
def initialize(args = {})
|
10
|
+
@name = args[:name]
|
11
|
+
@host = IRC::Host.new(args[:host])
|
12
|
+
@flags, @color, @channel = args.values_at(:flags, :color, :channel)
|
13
|
+
end
|
14
|
+
|
15
|
+
%w(chanowner? chanadmin? chanadmin2? op?
|
16
|
+
halfop? voice? away? chanuser?).each_with_index do |method, bit|
|
17
|
+
define_method(method) {(@flags & (2 ** bit)) > 0}
|
18
|
+
end
|
19
|
+
alias_method :opped?, :op?
|
20
|
+
alias_method :voiced?, :voice?
|
21
|
+
|
22
|
+
def op
|
23
|
+
@channel.exec("/op #@name")
|
24
|
+
end
|
25
|
+
|
26
|
+
def halfop
|
27
|
+
@channel.exec("/halfop #@name")
|
28
|
+
end
|
29
|
+
|
30
|
+
def voice
|
31
|
+
@channel.exec("/voice #@name")
|
32
|
+
end
|
33
|
+
|
34
|
+
def deop
|
35
|
+
@channel.exec("/deop #@name")
|
36
|
+
end
|
37
|
+
|
38
|
+
def dehalfop
|
39
|
+
@channel.exec("/dehalfop #@name")
|
40
|
+
end
|
41
|
+
|
42
|
+
def devoice
|
43
|
+
@channel.exec("/devoice #@name")
|
44
|
+
end
|
45
|
+
|
46
|
+
def kick(reason="")
|
47
|
+
@channel.exec("/kick #@name #{reason}")
|
48
|
+
end
|
49
|
+
|
50
|
+
def ban
|
51
|
+
@channel.exec("/ban #@name")
|
52
|
+
end
|
53
|
+
|
54
|
+
def unban
|
55
|
+
@channel.exec("/unban #@name")
|
56
|
+
end
|
57
|
+
|
58
|
+
def kickban(reason="")
|
59
|
+
kick(reason)
|
60
|
+
ban
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weechat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominik Honnef
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-12-
|
12
|
+
date: 2009-12-21 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -50,13 +50,16 @@ files:
|
|
50
50
|
- lib/weechat/line.rb
|
51
51
|
- lib/weechat/exceptions.rb
|
52
52
|
- lib/weechat/command.rb
|
53
|
+
- lib/weechat/channel.rb
|
53
54
|
- lib/weechat/info.rb
|
54
55
|
- lib/weechat/process.rb
|
55
56
|
- lib/weechat/property.rb
|
56
57
|
- lib/weechat/server.rb
|
57
58
|
- lib/weechat/input.rb
|
58
59
|
- lib/weechat/hooks.rb
|
60
|
+
- lib/weechat/host.rb
|
59
61
|
- lib/weechat/timer.rb
|
62
|
+
- lib/weechat/user.rb
|
60
63
|
- lib/weechat.rb
|
61
64
|
- COPYING
|
62
65
|
- TODO
|