easy-gtalk-bot 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ nbproject
2
+ pkg
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ group :runtime do
2
+ gem "xmpp4r", ">=0.5"
3
+ end
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Daniel Vartanov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,54 @@
1
+ h1. easy-gtalk-bot
2
+
3
+ A very easy tool for creating Google Talk bots
4
+
5
+ h2. It's really easy!
6
+
7
+ h3. Installation
8
+
9
+ <code>sudo gem install easy-gtalk-bot</code>
10
+
11
+ h3. Usage
12
+
13
+ <pre>
14
+ require 'easy-gtalk-bot'
15
+
16
+ bot = GTalk::Bot.new(:email => "easy.bot@gmail.com", :password => 'sekrit')
17
+ bot.get_online
18
+
19
+ bot.on_invitation do |inviter|
20
+ puts "I have been invited by #{inviter}. Yay!"
21
+
22
+ # do something useful
23
+
24
+ bot.accept_invitation(inviter)
25
+ bot.message(inviter, "Hello there! Thanks for invitation!")
26
+ end
27
+
28
+ bot.on_message do |from, text|
29
+ puts "I got message from #{from}: '#{text}'"
30
+
31
+ # do something useful
32
+
33
+ bot.message from, "I heard that!"
34
+ end
35
+
36
+ # Don't be confused with the name of this method.
37
+ # We actually keep the current (main) thread alive while letting listener thread to do its job.
38
+ # So we have no need to set up an any infinite loop.
39
+ Thread.stop</pre>
40
+
41
+ h2. To-do
42
+
43
+ <code>bot.get_online :invisible => true </code>
44
+
45
+ <code>bot.set_status :away</code>
46
+
47
+ <code>GTalk::Account('john.smith@gmail.com').available?</code>
48
+
49
+ <code>bot.contact_list # => Array</code>
50
+
51
+ <code>bot.in_contact_list?('john.smith@gmail.com')</code>
52
+
53
+
54
+ Copyright © 2010 Daniel Vartanov, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ begin
2
+ require 'jeweler'
3
+ Jeweler::Tasks.new do |gemspec|
4
+ gemspec.name = "easy-gtalk-bot"
5
+ gemspec.summary = "A very easy tool for creating Google Talk bots"
6
+ gemspec.description = "easy-gtalk-bot lets you create and run GTalk bot in 5 minutes"
7
+ gemspec.email = "dan@vartanov.net"
8
+ gemspec.homepage = "http://github.com/DanielVartanov/easy-gtalk-bot"
9
+ gemspec.authors = ["Daniel Vartanov"]
10
+ end
11
+
12
+ Jeweler::GemcutterTasks.new
13
+ rescue LoadError
14
+ puts "Jeweler not available. Install it with: gem install jeweler"
15
+ end
data/VERSION.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ :patch: 1
3
+ :major: 1
4
+ :minor: 0
5
+ :build:
@@ -0,0 +1,48 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{easy-gtalk-bot}
8
+ s.version = "1.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Daniel Vartanov"]
12
+ s.date = %q{2010-06-28}
13
+ s.description = %q{easy-gtalk-bot lets you create and run GTalk bot in 5 minutes}
14
+ s.email = %q{dan@vartanov.net}
15
+ s.extra_rdoc_files = [
16
+ "README.textile"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "Gemfile",
21
+ "MIT-LICENSE",
22
+ "README.textile",
23
+ "Rakefile",
24
+ "VERSION.yml",
25
+ "easy-gtalk-bot.gemspec",
26
+ "examples/the_simplest_bot.rb",
27
+ "lib/easy-gtalk-bot.rb"
28
+ ]
29
+ s.homepage = %q{http://github.com/DanielVartanov/easy-gtalk-bot}
30
+ s.rdoc_options = ["--charset=UTF-8"]
31
+ s.require_paths = ["lib"]
32
+ s.rubygems_version = %q{1.3.6}
33
+ s.summary = %q{A very easy tool for creating Google Talk bots}
34
+ s.test_files = [
35
+ "examples/the_simplest_bot.rb"
36
+ ]
37
+
38
+ if s.respond_to? :specification_version then
39
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
40
+ s.specification_version = 3
41
+
42
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
43
+ else
44
+ end
45
+ else
46
+ end
47
+ end
48
+
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'easy-gtalk-bot'
4
+
5
+ bot = GTalk::Bot.new(:email => "easy.bot@gmail.com", :password => 'sekrit')
6
+ bot.get_online
7
+
8
+ bot.on_invitation do |inviter|
9
+ puts "I have been invited by #{inviter}. Yay!"
10
+
11
+ # do something useful
12
+
13
+ bot.accept_invitation(inviter)
14
+ bot.message(inviter, "Hello there! Thanks for invitation!")
15
+ end
16
+
17
+ bot.on_message do |from, text|
18
+ puts "I got message from #{from}: '#{text}'"
19
+
20
+ # do something useful
21
+
22
+ bot.message from, "I heard that!"
23
+ end
24
+
25
+ # Don't be confused with the name of this method.
26
+ # We actually keep the current (main) thread alive while letting listener thread to do its job.
27
+ # So we have no need to set up an any infinite loop.
28
+ Thread.stop
@@ -0,0 +1,71 @@
1
+ require 'openssl'
2
+
3
+ require "xmpp4r"
4
+ require 'xmpp4r/roster'
5
+
6
+ module JabberExtensions
7
+ module JIDExtensions
8
+ def to_email
9
+ "#{self.node}@#{self.domain}"
10
+ end
11
+ end
12
+
13
+ Jabber::JID.__send__ :include, JIDExtensions
14
+ end
15
+
16
+ module GTalk
17
+ class Bot
18
+ include Jabber
19
+ attr_reader :email, :password
20
+ attr_reader :jabber_client, :jid
21
+
22
+ def initialize(account_data)
23
+ @email = account_data[:email]
24
+ @password = account_data[:password]
25
+
26
+ @jid = JID::new(self.email)
27
+ @jabber_client = Client.new(self.jid)
28
+ end
29
+
30
+ def get_online
31
+ self.jabber_client.connect
32
+ self.jabber_client.auth(self.password)
33
+ self.jabber_client.send(Presence.new.set_type(:available))
34
+ end
35
+
36
+ def invite(invitee)
37
+ subscription_request = Presence.new.set_type(:subscribe).set_to(JID::new(invitee))
38
+ self.jabber_client.send(subscription_request)
39
+ end
40
+
41
+ def accept_invitation(inviter)
42
+ inviter = JID::new(inviter)
43
+ self.roster.accept_subscription(inviter)
44
+ invite(JID::new(inviter))
45
+ end
46
+
47
+ def message(to, text)
48
+ message = Message::new(JID::new(to), text)
49
+ message.type = :chat
50
+ self.jabber_client.send(message)
51
+ end
52
+
53
+ def on_invitation(&block)
54
+ self.roster.add_subscription_request_callback do |_, presence|
55
+ block.call(presence.from.to_email)
56
+ end
57
+ end
58
+
59
+ def on_message(&block)
60
+ self.jabber_client.add_message_callback do |message|
61
+ block.call(message.from.to_email, message.body)
62
+ end
63
+ end
64
+
65
+ protected
66
+
67
+ def roster
68
+ @roster ||= Roster::Helper.new(self.jabber_client)
69
+ end
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy-gtalk-bot
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 1
9
+ version: 1.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Daniel Vartanov
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-06-28 00:00:00 +06:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: easy-gtalk-bot lets you create and run GTalk bot in 5 minutes
22
+ email: dan@vartanov.net
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.textile
29
+ files:
30
+ - .gitignore
31
+ - Gemfile
32
+ - MIT-LICENSE
33
+ - README.textile
34
+ - Rakefile
35
+ - VERSION.yml
36
+ - easy-gtalk-bot.gemspec
37
+ - examples/the_simplest_bot.rb
38
+ - lib/easy-gtalk-bot.rb
39
+ has_rdoc: true
40
+ homepage: http://github.com/DanielVartanov/easy-gtalk-bot
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options:
45
+ - --charset=UTF-8
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.6
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: A very easy tool for creating Google Talk bots
69
+ test_files:
70
+ - examples/the_simplest_bot.rb