shout-bot-portertech 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/shout-bot.rb +93 -0
  2. metadata +67 -0
data/lib/shout-bot.rb ADDED
@@ -0,0 +1,93 @@
1
+ =begin
2
+ ShoutBot
3
+ Ridiculously simple library to quickly say something on IRC
4
+ <http://github.com/sr/shout-bot>
5
+
6
+ EXAMPLE
7
+
8
+ ShoutBot.shout('irc://shoutbot:password@irc.freenode.net:6667/#github') do |channel|
9
+ channel.say "check me out! http://github.com/sr/shout-bot"
10
+ end
11
+
12
+ LICENSE
13
+
14
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
15
+ Version 2, December 2004
16
+
17
+ Copyright (C) 2008, 2009 Simon Rozet <http://purl.org/net/sr/>
18
+ Copyright (C) 2008, 2009 Harry Vangberg <http://trueaffection.net>
19
+
20
+ Everyone is permitted to copy and distribute verbatim or modified
21
+ copies of this license document, and changing it is allowed as long
22
+ as the name is changed.
23
+
24
+ DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
25
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
26
+
27
+ 0. You just DO WHAT THE FUCK YOU WANT TO.
28
+ =end
29
+
30
+ require "addressable/uri"
31
+ require "socket"
32
+ require "openssl"
33
+
34
+ class ShoutBot
35
+ def self.shout(uri, password = nil, ssl = false, &block)
36
+ raise ArgumentError unless block_given?
37
+
38
+ uri = Addressable::URI.parse(uri)
39
+ irc = new(uri.host, uri.port, uri.user, uri.password, ssl) do |irc|
40
+ if channel = uri.fragment
41
+ irc.join(channel, password, &block)
42
+ else
43
+ irc.channel = uri.path[1..-1]
44
+ yield irc
45
+ end
46
+ end
47
+ end
48
+
49
+ attr_accessor :channel
50
+
51
+ def sendln(cmd)
52
+ puts "Send: #{cmd}"
53
+ @socket.write("#{cmd}\r\n")
54
+ STDOUT.flush
55
+ end
56
+
57
+ def initialize(server, port, nick, password = nil, ssl)
58
+ raise ArgumentError unless block_given?
59
+
60
+ tcp_socket = TCPSocket.new(server, port || 6667)
61
+ if ssl
62
+ ssl_context = OpenSSL::SSL::SSLContext.new
63
+ ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE
64
+ @socket = OpenSSL::SSL::SSLSocket.new(tcp_socket, ssl_context)
65
+ @socket.sync = true
66
+ @socket.connect
67
+ else
68
+ @socket = tcp_socket
69
+ end
70
+ sendln "PASS #{password}" if password
71
+ sendln "NICK #{nick}"
72
+ sendln "USER #{nick} 0 * :#{nick}"
73
+ sleep 1
74
+ yield self
75
+ sendln "QUIT :quit"
76
+ @socket.gets until @socket.eof?
77
+ end
78
+
79
+ def join(channel, password)
80
+ raise ArgumentError unless block_given?
81
+
82
+ @channel = "##{channel}"
83
+ password = password && " #{password}" || ""
84
+ sendln "JOIN #{@channel}#{password}"
85
+ yield self
86
+ sendln "PART #{@channel}"
87
+ end
88
+
89
+ def say(message)
90
+ return unless @channel
91
+ sendln "PRIVMSG #{@channel} :#{message}"
92
+ end
93
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shout-bot-portertech
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.6
6
+ platform: ruby
7
+ authors:
8
+ - Simon Rozet
9
+ - Harry Vangberg
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2009-10-17 00:00:00 +09:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: addressable
19
+ prerelease: false
20
+ requirement: &id001 !ruby/object:Gem::Requirement
21
+ none: false
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: "0"
26
+ type: :runtime
27
+ version_requirements: *id001
28
+ description: Ridiculously simple library to quickly say something on IRC
29
+ email: simon@rozet.name
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files: []
35
+
36
+ files:
37
+ - lib/shout-bot.rb
38
+ has_rdoc: true
39
+ homepage: http://github.com/sr/shout-bot
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.6.2
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Ridiculously simple library to quickly say something on IRC
66
+ test_files: []
67
+