xmppbot 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,8 @@ Manifest.txt
3
3
  PostInstall.txt
4
4
  README.rdoc
5
5
  Rakefile
6
+ Rakefile.save
7
+ Rakefile.save.1
6
8
  lib/xmppbot.rb
7
9
  lib/xmppbot/bot.rb
8
10
  lib/xmppbot/message.rb
@@ -2,73 +2,78 @@
2
2
 
3
3
  == DESCRIPTION:
4
4
 
5
- Simple implementation on top of StropheRuby(http://github.com/flamontagne/strophe_ruby/).
6
- It's for those who want to build simple xmpp bots quickly. It features only the essential :
5
+ This is a simple implementation on top of StropheRuby 'http://github.com/flamontagne/strophe_ruby/'.
6
+ It's for those who want to build xmpp bots quickly. It features only the essential :
7
7
  - auto accept subscriptions
8
8
  - callback for received messages
9
9
  - callback for received presences
10
10
  - a method to send messages and presences
11
11
  - That's it
12
12
 
13
- Warning : StropheRuby is very experimental at the moment. It is definitely NOT ready for production!
13
+ Warning : StropheRuby is quite experimental at the moment. It is definitely NOT ready for production!
14
14
 
15
15
  == FEATURES/PROBLEMS:
16
16
 
17
- - Only tested under Debian
18
- - No TLS support for now. It will work once TLS with OpenSSL is working in Strophe (http://code.stanziq.com/strophe)
19
-
17
+ - Only tested under Debian so far
18
+ - Does not work under windows
19
+ - No TLS support for now. It will work once TLS with OpenSSL is working in Strophe 'http://code.stanziq.com/strophe'
20
+ - Exiting the program can cause segmentation errors (not really problematic)
20
21
 
21
22
  == SYNOPSIS:
22
23
 
23
- How to use it :
24
-
25
24
  require 'xmppbot'
26
- def register_callbacks
27
- @bot.on_presence_received do |pres|
28
- puts "#{pres.from} is now #{pres.to_s}"
25
+
26
+ class Johnny5 < XMPPBot::Bot
27
+ def connect
28
+ super do |status|
29
+ if status == XMPPBot::ConnectionEvents::CONNECT
30
+ announce_presence
31
+ register_callbacks
32
+ else
33
+ disconnect
34
+ end
35
+ end
29
36
  end
30
-
31
- @bot.on_message_received do |msg|
32
- if msg.body == "exit"
33
- @bot.disconnect
34
- else
35
- stanza=XMPPBot::Message.new
36
- stanza.to=msg.from
37
- stanza.body="You said : #{msg.body}"
38
- @bot.send(stanza)
37
+
38
+ def register_callbacks
39
+ on_presence_received do |pres|
40
+ puts "#{pres.from} is now #{pres.to_s}" unless pres.to_s.strip == ""
39
41
  end
42
+
43
+ on_message_received do |msg|
44
+ if msg.body == "exit"
45
+ disconnect
46
+ else
47
+ stanza=XMPPBot::Message.new
48
+ stanza.to=msg.from
49
+ stanza.body="You said : #{msg.body}"
50
+ send(stanza)
51
+ end
52
+ end
40
53
  end
41
54
  end
42
55
 
43
-
44
- @bot=XMPPBot::Bot.new
45
- @bot.jid="bot@example.com"
46
- @bot.password="secret"
47
- @bot.log_level = XMPPBot::Logging::DEBUG
56
+ @bot = Johnny5.new
57
+ @bot.jid = "cripes@jaim.at"
58
+ @bot.password = "cripes"
59
+ @bot.log_level = XMPPBot::Logging::INFO
48
60
  @bot.auto_accept_subscriptions = true
49
61
 
50
- @bot.connect do |status|
51
- if status == XMPPBot::ConnectionEvents::CONNECT
52
- @bot.announce_presence
53
- register_callbacks
54
- else
55
- @bot.disconnect
56
- end
57
- end
62
+ @bot.connect
58
63
 
59
- == REQUIREMENTS:
64
+ #We pause the execution of the current thread to prevent the program from exiting
65
+ Thread.stop
60
66
 
61
- * Compile and install StropheRuby (http://github.com/flamontagne/stropheruby)
67
+ #Once the parsing thread exits, execution resumes here
68
+ puts "Connection terminated"
62
69
 
63
70
  == INSTALL:
64
71
 
65
- * For now you can install the GEM in the pkg directory. Remember that you need StropheRuby to use XMPPBot ()
72
+ gem install xmppbot (it will install stropheruby as well)
66
73
 
67
74
  == LICENSE:
68
75
 
69
- (The MIT License)
70
-
71
- Copyright (c) 2008 FIXME full name
76
+ Copyright (c) 2008 François Lamontagne
72
77
 
73
78
  Permission is hereby granted, free of charge, to any person obtaining
74
79
  a copy of this software and associated documentation files (the
@@ -87,4 +92,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
87
92
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
88
93
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
89
94
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
90
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
95
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -3,10 +3,10 @@
3
3
 
4
4
  # Generate all the Rake tasks
5
5
  # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
- $hoe = Hoe.new('xmppbot', '0.0.1') do |p|
6
+ $hoe = Hoe.new('xmppbot', '0.0.2') do |p|
7
7
  p.developer('François Lamontagne', 'flamontagne@gmail.com')
8
8
  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
- p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
9
+ # p.post_install_message = File.open(File.dirname(__FILE__) + "/PostInstall.txt").read
10
10
  p.rubyforge_name = p.name # TODO this is default value
11
11
  p.extra_deps = [
12
12
  ['strophe_ruby','>= 0.0.1'],
@@ -0,0 +1,29 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ #require File.dirname(__FILE__) + '/lib/xmppbot'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('xmppbot', '0.0.1') do |p|
7
+ p.developer('François Lamontagne', 'flamontagne@gmail.com')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ p.post_install_message = 'PostInstall.txt' # TODO remove if
10
+ post-install message not required
11
+ p.rubyforge_name = p.name # TODO this is default value
12
+ p.extra_deps = [
13
+ ['strophe_ruby','>= 0.0.1'],
14
+ ]
15
+ p.extra_dev_deps = [
16
+ ['newgem', ">= #{::Newgem::VERSION}"]
17
+ ]
18
+
19
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
20
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
21
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
22
+ p.rsync_args = '-av --delete --ignore-errors'
23
+ end
24
+
25
+ require 'newgem/tasks' # load /tasks/*.rake
26
+ Dir['tasks/**/*.rake'].each { |t| load t }
27
+
28
+ # TODO - want other tests/tasks run by default? Add them to the list
29
+ # task :default => [:spec, :features]
@@ -0,0 +1,29 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ #require File.dirname(__FILE__) + '/lib/xmppbot'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('xmppbot', '0.0.1') do |p|
7
+ p.developer('François Lamontagne', 'flamontagne@gmail.com')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ p.post_install_message =
10
+ # TODO remove if post-install message not required
11
+ p.rubyforge_name = p.name # TODO this is default value
12
+ p.extra_deps = [
13
+ ['strophe_ruby','>= 0.0.1'],
14
+ ]
15
+ p.extra_dev_deps = [
16
+ ['newgem', ">= #{::Newgem::VERSION}"]
17
+ ]
18
+
19
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
20
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
21
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
22
+ p.rsync_args = '-av --delete --ignore-errors'
23
+ end
24
+
25
+ require 'newgem/tasks' # load /tasks/*.rake
26
+ Dir['tasks/**/*.rake'].each { |t| load t }
27
+
28
+ # TODO - want other tests/tasks run by default? Add them to the list
29
+ # task :default => [:spec, :features]
@@ -103,7 +103,6 @@ module XMPPBot
103
103
  def announce_presence
104
104
  presence = StropheRuby::Stanza.new
105
105
  presence.name="presence"
106
- presence.set_attribute("show", "available")
107
106
  send_stanza(presence)
108
107
  end
109
108
 
@@ -39,7 +39,11 @@ module XMPPBot
39
39
 
40
40
  def body=(str)
41
41
  children = self.stanza.children
42
-
42
+
43
+ #Strangely enough, sending a "<" character to our stream will terminate it.
44
+ #I guess expat (the xml parser) should take care of encoding the
45
+ #special characters to ensure that the xml remains valid... but it doesn't do it.
46
+ str.gsub!(/[<>]/) {|s| s == "<" ? '&lt;' : '&gt;'}
43
47
  if children
44
48
  children.children.text = str
45
49
  else
@@ -46,7 +46,7 @@ module XMPPBot
46
46
  #subscribe,subscribed,unsubscribe,unsubscribed,probe or error.
47
47
  def to_s
48
48
  res = self.show
49
- res ? res : self.type.to_s
49
+ res ? res : self.type ? self.type : "available"
50
50
  end
51
51
  end
52
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmppbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Fran\xC3\xA7ois Lamontagne"
@@ -42,7 +42,7 @@ dependencies:
42
42
  - !ruby/object:Gem::Version
43
43
  version: 1.8.0
44
44
  version:
45
- description: "Simple implementation on top of StropheRuby(http://github.com/flamontagne/strophe_ruby/). It's for those who want to build simple xmpp bots quickly. It features only the essential : - auto accept subscriptions - callback for received messages - callback for received presences - a method to send messages and presences - That's it Warning : StropheRuby is very experimental at the moment. It is definitely NOT ready for production!"
45
+ description: "This is a simple implementation on top of StropheRuby 'http://github.com/flamontagne/strophe_ruby/'. It's for those who want to build xmpp bots quickly. It features only the essential : - auto accept subscriptions - callback for received messages - callback for received presences - a method to send messages and presences - That's it Warning : StropheRuby is quite experimental at the moment. It is definitely NOT ready for production!"
46
46
  email:
47
47
  - flamontagne@gmail.com
48
48
  executables: []
@@ -60,6 +60,8 @@ files:
60
60
  - PostInstall.txt
61
61
  - README.rdoc
62
62
  - Rakefile
63
+ - Rakefile.save
64
+ - Rakefile.save.1
63
65
  - lib/xmppbot.rb
64
66
  - lib/xmppbot/bot.rb
65
67
  - lib/xmppbot/message.rb
@@ -72,7 +74,7 @@ files:
72
74
  - test/test_xmppbot.rb
73
75
  has_rdoc: true
74
76
  homepage:
75
- post_install_message: PostInstall.txt
77
+ post_install_message:
76
78
  rdoc_options:
77
79
  - --main
78
80
  - README.rdoc
@@ -96,7 +98,7 @@ rubyforge_project: xmppbot
96
98
  rubygems_version: 1.3.1
97
99
  signing_key:
98
100
  specification_version: 2
99
- summary: Simple implementation on top of StropheRuby(http://github.com/flamontagne/strophe_ruby/)
101
+ summary: This is a simple implementation on top of StropheRuby 'http://github.com/flamontagne/strophe_ruby/'
100
102
  test_files:
101
103
  - test/test_helper.rb
102
104
  - test/test_xmppbot.rb