weechat 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,137 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'date'
3
+
4
+ module Weechat
5
+ module IRC
6
+ class Server
7
+ attr_reader :name
8
+ PROCESSORS = {
9
+ [:buffer] => lambda {|b|
10
+ if b.empty?
11
+ nil
12
+ else
13
+ Weechat::Buffer.new(b)
14
+ end
15
+ },
16
+ [:ipv6, :ssl, :ssl_verify,
17
+ :autoconnect, :autoreconnect,
18
+ :autorejoin, :temp_server,
19
+ :is_connected, :ssl_connected,
20
+ :reconnect_join, :disable_autojoin,
21
+ :is_away] => lambda {|i| i == 0 ? false : true },
22
+ [:reconnect_start, :command_time,
23
+ :away_time, :lag_next_check,
24
+ :last_user_message] => lambda {|v| DateTime.parse(v)},
25
+ }
26
+
27
+ MAPPINGS = {
28
+ :autoconnect? => :autoconnect,
29
+ :autoreconnect? => :autoreconnect,
30
+ :autorejoin? => :autorejoin,
31
+ :temp_server? => :temp_server,
32
+ :connected? => :is_connected,
33
+ :ssl_connected? => :ssl_connected,
34
+ :reconnect_join? => :reconnect_join,
35
+ }
36
+
37
+ def autojoin?
38
+ !disable_autojoin
39
+ end
40
+
41
+ def initialize(name)
42
+ @name = name
43
+ end
44
+
45
+ class << self
46
+ alias_method :from_name, :new
47
+ end
48
+
49
+ def self.buffers
50
+ servers = []
51
+ Weechat::Infolist.parse("irc_server").each do |server|
52
+ servers << Server.new(server[:name])
53
+ end
54
+ servers
55
+ end
56
+ class << self
57
+ alias_method :all, :buffers
58
+ end
59
+
60
+ # TODO method for creating a new server
61
+
62
+ def data
63
+ Weechat::Infolist.parse("irc_server", "", @name).first
64
+ end
65
+
66
+ def respond_to?(m)
67
+ if data.has_key?(m.to_sym)
68
+ true
69
+ else
70
+ super
71
+ end
72
+ end
73
+
74
+ def method_missing(m, *args)
75
+ m = MAPPINGS[m] || m
76
+ properties = data
77
+ if properties.has_key?(m) and args.size == 0
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
89
+ end
90
+ end
91
+ end
92
+ end
93
+ __END__
94
+ name..........................: str 'quakenet'
95
+ │ buffer........................: ptr 0x9bb2438
96
+ │ buffer_name...................: str 'server.quakenet'
97
+ │ buffer_short_name.............: str 'quakenet'
98
+ │ addresses.....................: str 'irc.quakenet.org/6667'
99
+ │ proxy.........................: str ''
100
+ │ ipv6..........................: int 0
101
+ │ ssl...........................: int 0
102
+ │ ssl_cert......................: str ''
103
+ │ ssl_dhkey_size................: int 2048
104
+ │ ssl_verify....................: int 1
105
+ │ password......................: str ''
106
+ │ autoconnect...................: int 0
107
+ │ autoreconnect.................: int 1
108
+ │ autoreconnect_delay...........: int 30
109
+ │ nicks.........................: str 'dominikh,dominikh1,dominikh2,dominikh3,dominikh4'
110
+ │ username......................: str 'dominikh'
111
+ │ realname......................: str 'Dominik Honnef'
112
+ │ local_hostname................: str ''
113
+ │ command.......................: str ''
114
+ │ command_delay.................: int 0
115
+ │ autojoin......................: str ''
116
+ │ autorejoin....................: int 0
117
+ │ temp_server...................: int 0
118
+ │ index_current_address.........: int 0
119
+ │ current_ip....................: str '85.236.110.226'
120
+ │ sock..........................: int 8
121
+ │ is_connected..................: int 1
122
+ │ ssl_connected.................: int 0
123
+ │ unterminated_message..........: str ''
124
+ │ nick..........................: str 'dominikh1'
125
+ │ nick_modes....................: str 'i'
126
+ │ prefix........................: str '@+'
127
+ │ reconnect_start...............: tim 1970-01-01 01:00:00
128
+ │ command_time..................: tim 1970-01-01 01:00:00
129
+ │ reconnect_join................: int 0
130
+ │ disable_autojoin..............: int 0
131
+ │ is_away.......................: int 0
132
+ │ away_message..................: str ''
133
+ │ away_time.....................: tim 1970-01-01 01:00:00
134
+ │ lag...........................: int 43
135
+ │ lag_check_time................: buf
136
+ │ lag_next_check................: tim 2009-12-12 16:56:28
137
+ │ last_user_message.............: tim 2009-12-12 16:48:21
@@ -0,0 +1,8 @@
1
+ module Weechat
2
+ class Terminal
3
+ # Sets the terminal's title
4
+ def self.title=(value)
5
+ Weechat.window_set_title(value.to_s)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,56 @@
1
+ module Weechat
2
+ class Timer < Hook
3
+ attr_reader :interval
4
+ attr_reader :align
5
+ attr_reader :max
6
+ def initialize(interval, max=0, align=0, &block)
7
+ super
8
+ @remaining= nil
9
+ @callback = Callback.new(block)
10
+ @interval = interval
11
+ @align = align
12
+ @max = max
13
+ @ptr = _init(interval, align, max)
14
+ self.class.register(self)
15
+ end
16
+
17
+ def _init(interval, align, max)
18
+ Weechat.hook_timer(interval, align, max, "timer_callback", @id.to_s)
19
+ end
20
+
21
+ def call(remaining)
22
+ @remaining = remaining.to_i
23
+ ret = super
24
+
25
+ if @remaining == 0
26
+ self.unhook
27
+ end
28
+
29
+ return ret
30
+ end
31
+
32
+ def stop
33
+ unhook
34
+ end
35
+
36
+ def start
37
+ unless @hooked
38
+ if @remaining == 0 || @remaining.nil?
39
+ # the timer never ran or finished already. restart it
40
+ max = @max
41
+ else
42
+ # continue running hook
43
+ max = @remaining
44
+ end
45
+
46
+ @ptr = _init(@interval, @align, max)
47
+ end
48
+ end
49
+
50
+ def restart
51
+ stop
52
+ @remaining = nil
53
+ start
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,47 @@
1
+ module Weechat
2
+ module Utilities
3
+ def self.evaluate_call
4
+ begin
5
+ yield
6
+ rescue Weechat::Exception::WEECHAT_RC_OK
7
+ return Weechat::WEECHAT_RC_OK
8
+ rescue Weechat::Exception::WEECHAT_RC_OK_EAT
9
+ return Weechat::WEECHAT_RC_OK_EAT
10
+ rescue Weechat::Exception::WEECHAT_RC_ERROR
11
+ return Weechat::WEECHAT_RC_ERROR
12
+ rescue => e
13
+ prefix = Weechat.prefix("error")
14
+
15
+ line1 = e.backtrace[0] + ": " + e.message + " (" + e.class.name + ")"
16
+ backtrace = " " + e.backtrace[1..-1].join("\n ")
17
+
18
+ Weechat.puts("#{prefix}error in evaluated call: #{line1}")
19
+ Weechat.puts("#{prefix}#{backtrace}")
20
+ return Weechat::WEECHAT_RC_ERROR
21
+ end
22
+
23
+ return Weechat::WEECHAT_RC_OK
24
+ end
25
+
26
+ def self.apply_transformation(property, value, transformations)
27
+ transformation = transformations.find {|properties, transformations|
28
+ properties.any? {|prop|
29
+ case prop
30
+ when Regexp
31
+ prop =~ property.to_s
32
+ when String, Symbol
33
+ prop.to_sym == property.to_sym
34
+ else
35
+ false
36
+ end
37
+ }
38
+ }
39
+
40
+ if transformation
41
+ transformation[1].call(value)
42
+ else
43
+ value
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,103 @@
1
+ module Weechat
2
+ # == Gettable properties
3
+ #
4
+ # [buffer] The buffer currently shown in the window
5
+ # [x] X position of the window in the terminal
6
+ # [y] Y position of the window in the terminal
7
+ # [width] Width of the window
8
+ # [height] Height of the window
9
+ # [width_pct] Width relative to the one of the parent window (0..100%)
10
+ # [height_pct] Height relative to the one of the parent window (0..100%)
11
+ # [first_line_displayed?] True if the first line of the displayed buffer is displayed on the screen
12
+ # [scrolling?] True if the window is currently being scrolled
13
+ # [scrolling_lines] Number of lines that are not being displayed (in the bottom direction)
14
+ #
15
+ # == The chat area
16
+ #
17
+ # See {Window::Chat}
18
+ class Window
19
+ # == Gettable properties
20
+ #
21
+ # [x] X position of the chat area
22
+ # [y] Y position of the chat area
23
+ # [width] Width of the chat area
24
+ # [height] Height of the chat area
25
+ class Chat
26
+ %w(x y width height).each do |prop|
27
+ define_method(prop) do
28
+ @window.get_property("win_chat_#{prop}")
29
+ end
30
+ end
31
+
32
+ attr_reader :window
33
+ protected :window
34
+
35
+ def initialize(window)
36
+ @window = window
37
+ end
38
+
39
+ def ==(other)
40
+ @window == other.window
41
+ end
42
+ alias_method :eql?, "=="
43
+ alias_method :equal?, "=="
44
+ end
45
+ include Weechat::Pointer
46
+ extend Weechat::Properties
47
+
48
+ # A list of all properties that can be retrieved using {#get_integer_property}.
49
+ #
50
+ # @private
51
+ @known_integer_properties = %w(win_x win_y win_width win_height win_width_pct
52
+ win_height_pct first_line_displayed
53
+ scroll scroll_lines_after).freeze
54
+
55
+ # The transformation procedures that get applied to values after
56
+ # they've been received using {#get_property}.
57
+ #
58
+ # @private
59
+ @transformations = {
60
+ [:first_line_displayed, :scroll] => lambda {|v| Weechat.integer_to_bool(v) },
61
+ [:buffer] => lambda {|v| Buffer.new(v) },
62
+ }.freeze
63
+
64
+ # @private
65
+ # @known_integer_properties = %w(win_x win_y win_width win_height win_width_pct
66
+ # win_height_pct win_chat_x win_chat_y win_chat_width win_chat_height first_line_displayed scroll scroll_lines_after).freeze
67
+ @mappings = {
68
+ :x => :win_x,
69
+ :y => :win_y,
70
+ :width => :win_width,
71
+ :height => :win_height,
72
+ :width_pct => :win_width_pct,
73
+ :height_pct => :win_height_pct,
74
+ :first_line_displayed? => :first_line_displayed,
75
+ :scrolling? => :scroll,
76
+ :scrolling_lines => :scroll_lines_after
77
+ }.freeze
78
+
79
+ class << self
80
+ def current
81
+ Window.new(Weechat.current_window)
82
+ end
83
+
84
+ # @todo TODO move into own module
85
+ def windows
86
+ windows = []
87
+ Weechat::Infolist.parse("window").each do |window|
88
+ windows << Window.new(window[:pointer])
89
+ end
90
+ windows
91
+ end
92
+ alias_method :all, :windows
93
+ end
94
+
95
+ init_properties
96
+
97
+ attr_reader :chat
98
+ def initialize(*args)
99
+ super
100
+ @chat = Chat.new(self)
101
+ end
102
+ end
103
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weechat
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dominik Honnef
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-14 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: An abstraction layer on top of the WeeChat API, allowing a cleaner and more intuitive way of writing Ruby scripts for WeeChat.
17
+ email: dominikho@gmx.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/weechat/terminal.rb
26
+ - lib/weechat/option.rb
27
+ - lib/weechat/infolist.rb
28
+ - lib/weechat/script.rb
29
+ - lib/weechat/properties.rb
30
+ - lib/weechat/window.rb
31
+ - lib/weechat/callback.rb
32
+ - lib/weechat/utilities.rb
33
+ - lib/weechat/plugin.rb
34
+ - lib/weechat/modifier.rb
35
+ - lib/weechat/blankslate.rb
36
+ - lib/weechat/pointer.rb
37
+ - lib/weechat/buffer.rb
38
+ - lib/weechat/color.rb
39
+ - lib/weechat/rubyext/object.rb
40
+ - lib/weechat/rubyext/float.rb
41
+ - lib/weechat/rubyext/array.rb
42
+ - lib/weechat/rubyext/integer.rb
43
+ - lib/weechat/rubyext/string.rb
44
+ - lib/weechat/rubyext/boolean.rb
45
+ - lib/weechat/hook.rb
46
+ - lib/weechat/script/config.rb
47
+ - lib/weechat/hooks/print.rb
48
+ - lib/weechat/hooks/config.rb
49
+ - lib/weechat/hooks/command_run.rb
50
+ - lib/weechat/line.rb
51
+ - lib/weechat/exceptions.rb
52
+ - lib/weechat/command.rb
53
+ - lib/weechat/info.rb
54
+ - lib/weechat/process.rb
55
+ - lib/weechat/property.rb
56
+ - lib/weechat/server.rb
57
+ - lib/weechat/input.rb
58
+ - lib/weechat/hooks.rb
59
+ - lib/weechat/timer.rb
60
+ - lib/weechat.rb
61
+ - COPYING
62
+ - TODO
63
+ - AUTHORS.md
64
+ - README.md
65
+ - Rakefile
66
+ - ChangeLog
67
+ has_rdoc: yard
68
+ homepage: http://dominikh.fork-bomb.de
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options: []
73
+
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ requirements: []
89
+
90
+ rubyforge_project: ""
91
+ rubygems_version: 1.3.5
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: An abstraction layer on top of the WeeChat API.
95
+ test_files: []
96
+