zoe 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +18 -0
- data/README.md +19 -0
- data/Rakefile +8 -0
- data/lib/zoe.rb +77 -0
- data/lib/zoe/jabber.rb +13 -0
- data/lib/zoe/rexml_patches.rb +26 -0
- data/zoe.gemspec +23 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b988b2f87d957cf3462b4817a8f9141b043443dc
|
4
|
+
data.tar.gz: e53f30ffcfec1fc9c9effca0b95dc02ed74d2e91
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 196ebc587400cb8222063c012687b4cd0a94d236e51036161826a59bb19298587c32abde3a6bbcbd91bb4a9c1fd6eee5af87c4f731fa518f927df1117e80327a
|
7
|
+
data.tar.gz: 2867848cbd854d035ef3066a4925b9d0d68f3824f8ee963b3ad3a6e7ed793482704ff2216f352af84c1dae898c9727e56c0964cc344e2d1a152ab83a3a7ba2b3
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Usage
|
2
|
+
=====
|
3
|
+
|
4
|
+
```ruby
|
5
|
+
require 'zoe'
|
6
|
+
|
7
|
+
Zoe.connect(:jid => 'account@domain',
|
8
|
+
:password => 'password',
|
9
|
+
:rooms => ['room_jid'])
|
10
|
+
|
11
|
+
|
12
|
+
Zoe.on_message do |m|
|
13
|
+
puts m.to_me?
|
14
|
+
puts m.from
|
15
|
+
puts m.reply_to
|
16
|
+
puts m.to
|
17
|
+
puts m.body
|
18
|
+
end
|
19
|
+
``ruby
|
data/Rakefile
ADDED
data/lib/zoe.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'xmpp4r'
|
2
|
+
require 'xmpp4r/muc'
|
3
|
+
require 'xmpp4r/roster'
|
4
|
+
|
5
|
+
require 'singleton'
|
6
|
+
require 'zoe/jabber'
|
7
|
+
require 'zoe/rexml_patches'
|
8
|
+
|
9
|
+
class Zoe
|
10
|
+
include Singleton
|
11
|
+
|
12
|
+
attr_reader :client, :roster, :rooms, :callbacks
|
13
|
+
|
14
|
+
def initialize
|
15
|
+
@callbacks = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def connect(jid: nil, password: nil, rooms: [])
|
19
|
+
@jid = jid
|
20
|
+
@client = Jabber::Client.new(jid + '/bot')
|
21
|
+
|
22
|
+
@client.connect
|
23
|
+
@client.auth(password)
|
24
|
+
@client.send(Jabber::Presence.new.set_type(:available))
|
25
|
+
|
26
|
+
@roster = Jabber::Roster::Helper.new(@client)
|
27
|
+
@roster.wait_for_roster
|
28
|
+
|
29
|
+
@rooms = rooms.map do |room_name|
|
30
|
+
room = Jabber::MUC::MUCClient.new(@client)
|
31
|
+
room.join(room_name + '/' + self.jid.iname)
|
32
|
+
room
|
33
|
+
end
|
34
|
+
|
35
|
+
@client.add_message_callback(200) do |m|
|
36
|
+
if m.type == :chat # if PM
|
37
|
+
m.reply_to = m.from
|
38
|
+
elsif m.type == :groupchat && m.from.resource # if GM
|
39
|
+
m.reply_to = m.from
|
40
|
+
m.from = get_jid_by_name(m.from.resource)
|
41
|
+
end
|
42
|
+
|
43
|
+
if m.body
|
44
|
+
@callbacks.each{ |c| c.call(m) }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def jid
|
50
|
+
@roster[@jid]
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_jid_by_name(name)
|
54
|
+
@roster.items.values.find{ |v| v.iname == name }
|
55
|
+
end
|
56
|
+
|
57
|
+
def send(to, message)
|
58
|
+
to = to.is_a?(Jabber::JID) ? to : Jabber::JID.new(to.to_s)
|
59
|
+
message = Jabber::Message.new(to, message)
|
60
|
+
message.type = (to.domain == "conf.hipchat.com" ? :groupchat : :chat)
|
61
|
+
|
62
|
+
@client.send(message)
|
63
|
+
end
|
64
|
+
|
65
|
+
def on_message(&block)
|
66
|
+
@callbacks << block
|
67
|
+
end
|
68
|
+
|
69
|
+
def debug!
|
70
|
+
Jabber.logger = Logger.new(STDOUT)
|
71
|
+
Jabber.debug = true
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.method_missing(method, *args, &block)
|
75
|
+
instance.__send__(method, *args, &block)
|
76
|
+
end
|
77
|
+
end
|
data/lib/zoe/jabber.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class Jabber::Message
|
2
|
+
attr_accessor :reply_to
|
3
|
+
|
4
|
+
def to_me?
|
5
|
+
!!( body =~ /(^|\s)@#{Zoe.jid.nick}(\s|$)/i || from.strip.to_s == reply_to.strip.to_s)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
class Jabber::Roster::Helper::RosterItem
|
10
|
+
def nick
|
11
|
+
attributes['mention_name']
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# Encoding patch, stolen from https://github.com/ln/xmpp4r/issues/3#issuecomment-1739952
|
2
|
+
require 'socket'
|
3
|
+
class TCPSocket
|
4
|
+
def external_encoding
|
5
|
+
Encoding::BINARY
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
require 'rexml/source'
|
10
|
+
class REXML::IOSource
|
11
|
+
alias_method :encoding_assign, :encoding=
|
12
|
+
def encoding=(value)
|
13
|
+
encoding_assign(value) if value
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
begin
|
18
|
+
# OpenSSL is optional and can be missing
|
19
|
+
require 'openssl'
|
20
|
+
class OpenSSL::SSL::SSLSocket
|
21
|
+
def external_encoding
|
22
|
+
Encoding::BINARY
|
23
|
+
end
|
24
|
+
end
|
25
|
+
rescue
|
26
|
+
end
|
data/zoe.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'zoe'
|
3
|
+
s.version = '0.1.0'
|
4
|
+
s.authors = ['Jon Bracy']
|
5
|
+
s.email = ['jon@42floors.com']
|
6
|
+
s.homepage = 'http://github.com/42floors/zoe'
|
7
|
+
s.summary = 'A HipChat Bot'
|
8
|
+
s.description = 'A simple chat bot for HipChat'
|
9
|
+
s.license = 'MIT'
|
10
|
+
|
11
|
+
s.rubyforge_project = 'zoe'
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
|
18
|
+
# Developoment
|
19
|
+
s.add_development_dependency 'rake'
|
20
|
+
|
21
|
+
# Runtime
|
22
|
+
s.add_runtime_dependency 'xmpp4r', '~> 0.5.0'
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zoe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jon Bracy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-06-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: xmpp4r
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.5.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.5.0
|
41
|
+
description: A simple chat bot for HipChat
|
42
|
+
email:
|
43
|
+
- jon@42floors.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- Gemfile
|
49
|
+
- Gemfile.lock
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- lib/zoe.rb
|
53
|
+
- lib/zoe/jabber.rb
|
54
|
+
- lib/zoe/rexml_patches.rb
|
55
|
+
- zoe.gemspec
|
56
|
+
homepage: http://github.com/42floors/zoe
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project: zoe
|
76
|
+
rubygems_version: 2.0.3
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: A HipChat Bot
|
80
|
+
test_files: []
|