protolink 0.2.8 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. data/Gemfile.lock +0 -10
  2. data/lib/protolink/channel.rb +3 -3
  3. data/lib/protolink/proto_socket.rb +4 -0
  4. data/lib/protolink/protonet.rb +1 -1
  5. data/lib/protolink/version.rb +1 -1
  6. metadata +4 -39
  7. data/example/chatbot.rb +0 -24
  8. data/example/linkbot/base_plugins.rb +0 -71
  9. data/example/linkbot/plugins/awwwyeah.rb +0 -11
  10. data/example/linkbot/plugins/blowhard.rb +0 -40
  11. data/example/linkbot/plugins/comic.rb +0 -40
  12. data/example/linkbot/plugins/dumb.rb +0 -11
  13. data/example/linkbot/plugins/dupe.rb.inactive +0 -64
  14. data/example/linkbot/plugins/face.rb +0 -11
  15. data/example/linkbot/plugins/fuuu.rb +0 -12
  16. data/example/linkbot/plugins/help.rb +0 -26
  17. data/example/linkbot/plugins/image.rb +0 -30
  18. data/example/linkbot/plugins/imgur.rb +0 -31
  19. data/example/linkbot/plugins/jason.rb +0 -73
  20. data/example/linkbot/plugins/karma.rb.inactive +0 -75
  21. data/example/linkbot/plugins/last.rb +0 -40
  22. data/example/linkbot/plugins/links.rb.inactive +0 -41
  23. data/example/linkbot/plugins/log.rb +0 -17
  24. data/example/linkbot/plugins/okay.rb +0 -11
  25. data/example/linkbot/plugins/onion.rb +0 -19
  26. data/example/linkbot/plugins/popcorn.rb +0 -32
  27. data/example/linkbot/plugins/qwantz.rb +0 -29
  28. data/example/linkbot/plugins/search.rb +0 -32
  29. data/example/linkbot/plugins/shutup.rb +0 -11
  30. data/example/linkbot/plugins/slap.rb +0 -15
  31. data/example/linkbot/plugins/snap.rb +0 -18
  32. data/example/linkbot/plugins/stab.rb +0 -12
  33. data/example/linkbot/plugins/store.rb +0 -71
  34. data/example/linkbot/plugins/store_help.rb +0 -22
  35. data/example/linkbot/plugins/swanson.rb +0 -41
  36. data/example/linkbot/plugins/titles.rb +0 -34
  37. data/example/linkbot/plugins/translate.rb +0 -21
  38. data/example/linkbot/plugins/tsa.rb +0 -22
  39. data/example/linkbot/plugins/twss.rb +0 -20
  40. data/example/linkbot/plugins/urban.rb +0 -27
  41. data/example/linkbot/util.rb +0 -28
@@ -1,17 +1,8 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- addressable (2.2.6)
5
4
  crack (0.1.8)
6
- em-http-request (1.0.0)
7
- addressable (>= 2.2.3)
8
- em-socksify
9
- eventmachine (>= 1.0.0.beta.3)
10
- http_parser.rb (>= 0.5.2)
11
- em-socksify (0.1.0)
12
- eventmachine
13
5
  eventmachine (1.0.0.beta.4)
14
- http_parser.rb (0.5.3)
15
6
  httparty (0.7.8)
16
7
  crack (= 0.1.8)
17
8
  rake (0.9.2)
@@ -21,7 +12,6 @@ PLATFORMS
21
12
  ruby
22
13
 
23
14
  DEPENDENCIES
24
- em-http-request
25
15
  eventmachine (= 1.0.0.beta.4)
26
16
  httparty
27
17
  rake
@@ -15,7 +15,7 @@ module Protolink
15
15
 
16
16
  # Post a new message to the chat channel
17
17
  def speak(message, options = {})
18
- send_message(message)
18
+ send_message(message, options)
19
19
  end
20
20
 
21
21
  def delete!
@@ -49,8 +49,8 @@ module Protolink
49
49
  @loaded = true
50
50
  end
51
51
 
52
- def send_message(message)
53
- connection.post("/api/v1/meeps", :body => {:channel_id => self.id, :message => message})
52
+ def send_message(message, option)
53
+ connection.post("/api/v1/meeps", :body => {:channel_id => self.id, :message => message, :text_extension => option[:text_extension]})
54
54
  end
55
55
 
56
56
  def connection
@@ -27,7 +27,11 @@ class ProtoSocket < FlashConnection
27
27
  end
28
28
 
29
29
  def unbind
30
+ puts "DISCONNECTED"
30
31
  EventMachine::cancel_timer @ping
32
+ EventMachine::add_timer(30) {
33
+ EventMachine.connect URI.parse(@connection.class.base_uri).host, 5000, ProtoSocket, @connection, @message_callback
34
+ }
31
35
  end
32
36
 
33
37
  end
@@ -135,7 +135,7 @@ module Protolink
135
135
  end
136
136
 
137
137
  def find_user_by_login(login)
138
- response = get("/api/v1/users/#{login}")
138
+ response = get("/api/v1/users/find_by_login/#{login}")
139
139
  User.new(self, response) if response
140
140
  end
141
141
 
@@ -1,3 +1,3 @@
1
1
  module Protolink
2
- VERSION = '0.2.8' unless defined?(::Protolink::VERSION)
2
+ VERSION = '0.2.9' unless defined?(::Protolink::VERSION)
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protolink
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 8
10
- version: 0.2.8
9
+ - 9
10
+ version: 0.2.9
11
11
  platform: ruby
12
12
  authors:
13
13
  - "Bj\xC3\xB6rn B. Dorra"
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-10-26 00:00:00 +02:00
19
+ date: 2011-12-16 00:00:00 +01:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -64,42 +64,7 @@ files:
64
64
  - Gemfile.lock
65
65
  - README.markdown
66
66
  - Rakefile
67
- - example/chatbot.rb
68
67
  - example/create_and_subscribe.rb
69
- - example/linkbot/base_plugins.rb
70
- - example/linkbot/plugins/awwwyeah.rb
71
- - example/linkbot/plugins/blowhard.rb
72
- - example/linkbot/plugins/comic.rb
73
- - example/linkbot/plugins/dumb.rb
74
- - example/linkbot/plugins/dupe.rb.inactive
75
- - example/linkbot/plugins/face.rb
76
- - example/linkbot/plugins/fuuu.rb
77
- - example/linkbot/plugins/help.rb
78
- - example/linkbot/plugins/image.rb
79
- - example/linkbot/plugins/imgur.rb
80
- - example/linkbot/plugins/jason.rb
81
- - example/linkbot/plugins/karma.rb.inactive
82
- - example/linkbot/plugins/last.rb
83
- - example/linkbot/plugins/links.rb.inactive
84
- - example/linkbot/plugins/log.rb
85
- - example/linkbot/plugins/okay.rb
86
- - example/linkbot/plugins/onion.rb
87
- - example/linkbot/plugins/popcorn.rb
88
- - example/linkbot/plugins/qwantz.rb
89
- - example/linkbot/plugins/search.rb
90
- - example/linkbot/plugins/shutup.rb
91
- - example/linkbot/plugins/slap.rb
92
- - example/linkbot/plugins/snap.rb
93
- - example/linkbot/plugins/stab.rb
94
- - example/linkbot/plugins/store.rb
95
- - example/linkbot/plugins/store_help.rb
96
- - example/linkbot/plugins/swanson.rb
97
- - example/linkbot/plugins/titles.rb
98
- - example/linkbot/plugins/translate.rb
99
- - example/linkbot/plugins/tsa.rb
100
- - example/linkbot/plugins/twss.rb
101
- - example/linkbot/plugins/urban.rb
102
- - example/linkbot/util.rb
103
68
  - lib/protolink.rb
104
69
  - lib/protolink/channel.rb
105
70
  - lib/protolink/flash_connection.rb
@@ -1,24 +0,0 @@
1
- $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
2
-
3
- require 'rubygems'
4
- require 'protolink'
5
- require 'linkbot/base_plugins'
6
-
7
- # require 'ruby-debug'
8
- # Debugger.start
9
-
10
- # from https://github.com/markolson/linkbot
11
- Linkbot::Plugin.collect
12
-
13
- # change this if you need to connect to another server
14
- PTN_SERVER = "http://localhost:3000"
15
- PTN_USER = "admin"
16
- PTN_PASS = "admin"
17
- protonet = Protolink::Protonet.open(PTN_SERVER, PTN_USER, PTN_PASS)
18
- protonet.socket do |json|
19
- response = Linkbot::Plugin.handle_message(Message.new(json["message"], json["user_id"], json["author"], :message)) if json["trigger"] == "meep.receive"
20
- unless response.blank?
21
- c = protonet.find_channel(json["channel_id"])
22
- c.speak(response.first)
23
- end
24
- end
@@ -1,71 +0,0 @@
1
- require 'rubygems'
2
- require 'pp'
3
- require 'hpricot'
4
-
5
- class MessageType
6
- MESSAGE = :message
7
- DIRECTMESSAGE = :"direct-message"
8
- STARRED = :starred
9
- UNSTARRED = :unstarred
10
- end
11
-
12
- #The interface message object between Linkbot::Plugin and the plugins.
13
- #New axiom: the plugins know nothing about the service they're using!
14
- Message = Struct.new(:body, :user_id, :user_name, :type)
15
-
16
- class Linkbot
17
- class Plugin
18
- @@plugins = {}
19
- @@message_log = []
20
-
21
- def self.handle_message(message)
22
- print "handle_message got called with #{message}"
23
-
24
- @@message_log << message
25
-
26
- final_message = []
27
-
28
- Linkbot::Plugin.plugins.each {|k,v|
29
- if v[:handlers][message.type] && v[:handlers][message.type][:handler]
30
-
31
- if ((v[:handlers][message.type][:regex] && v[:handlers][message.type][:regex].match(message.body)) || v[:handlers][message.type][:regex].nil?)
32
-
33
- matches = v[:handlers][message.type][:regex] ? v[:handlers][message.type][:regex].match(message.body).to_a.drop(1) : nil
34
- p "#{k} processing message type #{message.type}"
35
- begin
36
- end_msg = v[:ptr].send(v[:handlers][message.type][:handler], message, matches)
37
- rescue => e
38
- end_msg = "the #{k} plugin threw an exception: #{e.inspect}"
39
- puts e.inspect
40
- puts e.backtrace.join("\n")
41
- end
42
- final_message << end_msg if !end_msg.empty?
43
- end
44
- end
45
- }
46
- print "returning msgs from plugins:"
47
- pp final_message
48
- final_message
49
- end
50
-
51
- def self.message_history
52
- @@message_log
53
- end
54
-
55
- def self.registered_methods
56
- @registered_methods ||= {}
57
- @registered_methods
58
- end
59
-
60
- def self.plugins; @@plugins; end;
61
-
62
- def self.collect
63
- Dir["linkbot/plugins/*.rb"].each {|file| load file }
64
- end
65
-
66
- def self.register(name, s, handlers)
67
- @@plugins[name] = {:ptr => s, :handlers => handlers}
68
- end
69
- end
70
-
71
- end
@@ -1,11 +0,0 @@
1
- class Awwyeah < Linkbot::Plugin
2
- def self.on_message(message, matches)
3
- "http://i.imgur.com/Y3Q0Z.png"
4
- end
5
-
6
- Linkbot::Plugin.register('awwwyeah', self,
7
- {
8
- :message => {:regex => /a+w+ y+e+a+h+/i, :handler => :on_message}
9
- }
10
- )
11
- end
@@ -1,40 +0,0 @@
1
- class Blowhard < Linkbot::Plugin
2
- def self.on_message(message, matches)
3
- quotes = ['I just blue myself.',
4
- "I'll be your wingman. Even if it means I have to take a chubby. I will suck it up.",
5
- "Well, yes, but I'm afraid I prematurely shot my wad on what was supposed to be a dry run, if you will, so now I’m afraid I have something of a mess on my hands.",
6
- "I can already taste those meaty leading man parts.",
7
- "I just can't seem to get one in the can...",
8
- "I will pack your mouth with your sweet, pink mouth with so much ice cream, you'll be the envy of every Jerry and Jane on the block.",
9
- "Well I guess you could say I am buy-curious",
10
- 'I see you wasted no time filling my "seat hole"',
11
- 'Excuse me, do these effectively hide my thunder?',
12
- 'Perhaps I should call the hot cops and tell them to come up with a more nautical theme. Hot sailors. Better yet... Hot sea...',
13
- 'Ah yes, the Bob Loblaw Law Blog. You, sir, are a mouthful.',
14
- "No, no. It's pronounced a-nal-ra-pist.",
15
- "Okay, who'd like a banger in the mouth? Right, I forgot, here in the States, you call it a sausage in the mouth.",
16
- 'Michael, you are quite the cupid. You can stick an arrow in my buttocks any time. ',
17
- 'Oh really? Then have sex with this girl right now. Go on. Have some sex with her.',
18
- 'Let the great experiment begin!',
19
- "Tobias, you blowhard.",
20
- "Michael, you are not quite the ladies man I had pictured. Hopefully, we will remedy that when we are in the spa spreading body chocolate on each other. ",
21
- "Boy, I sure feel like a Mary without a Peter and a Paul. ",
22
- "I'm looking for something that says 'Dad likes leather'. ",
23
- "I need to go take down the buffet and set up the leather pony. "]
24
-
25
- quotes[rand(quotes.length)]
26
- end
27
-
28
-
29
- def self.help
30
- "!blowhard - words of wisdom from Dr. Funke"
31
- end
32
-
33
-
34
- Linkbot::Plugin.register('blowhard', self,
35
- {
36
- :message => {:regex => /!blowhard/, :handler => :on_message, :help => :help},
37
- :"direct-message" => {:regex => /!blowhard/, :handler => :on_message, :help => :help}
38
- }
39
- )
40
- end
@@ -1,40 +0,0 @@
1
- require 'active_support'
2
-
3
- class Comic < Linkbot::Plugin
4
- Linkbot::Plugin.register('comic', self,
5
- {
6
- :message => {:regex => Regexp.new('(?:!comic|!fffffffuuuuuuuuuuuu)(?: (\d+))?'), :handler => :on_message, :help => :help},
7
- }
8
- )
9
-
10
- def self.on_message(message, matches)
11
- times = matches[0] || "1"
12
- times = times.to_i
13
- messages = []
14
-
15
- 1.upto(times) do
16
-
17
- # Brute force this mother
18
- subreddit = "http://reddit.com/r/fffffffuuuuuuuuuuuu.json"
19
-
20
- puts subreddit
21
- doc = ActiveSupport::JSON.decode(open(subreddit, "Cookie" => "reddit_session=8390507%2C2011-03-22T07%3A06%3A44%2C2516dcc69a22ad297b9900cbde147b365203bbbb").read)
22
-
23
- url = doc["data"]["children"][rand(doc["data"]["children"].length)]["data"]["url"]
24
-
25
- # Check if it's an imgur link without an image extension
26
- if url =~ /http:\/\/(www\.)?imgur\.com/ && !['jpg','png','gif'].include?(url.split('.').last)
27
- # Fetch the imgur page and pull out the image
28
- doc = Hpricot(open(url).read)
29
- url = doc.search("img")[1]['src']
30
- end
31
-
32
- messages << url
33
- end
34
- return messages.join("\n")
35
- end
36
-
37
- def self.help
38
- "!comic - return a random fffffffuuuuuuuuuuuu comic"
39
- end
40
- end
@@ -1,11 +0,0 @@
1
- class Dumb < Linkbot::Plugin
2
- def self.on_message(message, matches)
3
- "No, you're dumb"
4
- end
5
-
6
- Linkbot::Plugin.register('dumb', self,
7
- {
8
- :message => {:regex => /dumb|stupid/, :handler => :on_message}
9
- }
10
- )
11
- end
@@ -1,64 +0,0 @@
1
- require 'open-uri'
2
- require 'hpricot'
3
- require 'sqlite3'
4
- require 'time'
5
-
6
- class Dupe < Linkbot::Plugin
7
-
8
- Linkbot::Plugin.register('dupe', self,
9
- {
10
- :message => {:regex => /!stats/, :handler => :on_message, :help => :help}
11
- }
12
- )
13
-
14
- def self.on_message(message, matches)
15
- rows = Linkbot.db.execute("select u.username,s.total,s.dupes,k.karma,u.showname from stats s, users u, karma k where u.user_id = s.user_id AND u.user_id = k.user_id order by k.karma desc")
16
- mess = "Link stats:\n--------------------------\n"
17
-
18
- #find the maximum length karma total
19
- max = rows.collect { |row| row[1].to_s }.map(&:length).max
20
-
21
- rows.each {|row|
22
- username = (row[4].nil? || row[4] == '') ? row[0] : row[4]
23
- dupe = row[2] == 1 ? 'dupe' : 'dupes'
24
- mess = mess + sprintf("%#{max}d: #{username} (%d links, %d %s, %.2f%% new)\n", row[3], row[1], row[2], dupe, (row[1]/(row[1]+row[2]).to_f)*100)
25
- }
26
- mess
27
- end
28
-
29
- def self.on_dupe(message, url, duped_user, duped_timestamp)
30
- total,dupes = self.stats(message.user_id)
31
- Linkbot.db.execute("update stats set dupes = #{dupes+1} where user_id='#{message.user_id}'")
32
- res = Linkbot.db.execute("select username,showname from users where user_id='#{message.user_id}'")[0]
33
- username = (res[1].nil? || res[1] == '') ? res[0] : res[1]
34
- puts duped_timestamp
35
- "DUPE: Previously posted by #{duped_user} #{::Util.ago_in_words(Time.now, Time.parse(duped_timestamp.to_s))}"
36
- end
37
-
38
- def self.on_newlink(message, url)
39
- total,dupes = self.stats(message.user_id)
40
- Linkbot.db.execute("update stats set total = #{total+1} where user_id='#{message.user_id}'")
41
- end
42
-
43
-
44
- def self.stats(user_id)
45
- total = 0
46
- dupes = 0
47
- rows = Linkbot.db.execute("select user_id,total,dupes from stats where user_id = '#{user_id}'")
48
- if rows.empty?
49
- Linkbot.db.execute("insert into stats (user_id,total,dupes) values ('#{user_id}', 0, 0)")
50
- else
51
- total = rows[0][1]
52
- dupes = rows[0][2]
53
- end
54
- return total,dupes
55
- end
56
-
57
- def self.help
58
- "!stats - show all karma and links stats for linkchat participants"
59
- end
60
-
61
- if Linkbot.db.table_info('stats').empty?
62
- Linkbot.db.execute('CREATE TABLE stats (user_id INTEGER, dupes INTEGER, total INTEGER)');
63
- end
64
- end
@@ -1,11 +0,0 @@
1
- class Face < Linkbot::Plugin
2
- def self.on_message(message, matches)
3
- "http://i.imgur.com/ZbfvQ.gif"
4
- end
5
-
6
- Linkbot::Plugin.register('face', self,
7
- {
8
- :message => {:regex => Regexp.new('/face'), :handler => :on_message}
9
- }
10
- )
11
- end
@@ -1,12 +0,0 @@
1
- class Fuu < Linkbot::Plugin
2
- def self.on_message(message, matches)
3
- "http://imgur.com/M4KFN.jpg"
4
- end
5
-
6
- Linkbot::Plugin.register('fuuu', self,
7
- {
8
- :message => {:regex => Regexp.new('FUUU'), :handler => :on_message}
9
- }
10
- )
11
- end
12
-
@@ -1,26 +0,0 @@
1
- class Helper < Linkbot::Plugin
2
-
3
- Linkbot::Plugin.register('help', self,
4
- {
5
- :message => {:regex => /!help/, :handler => :on_message},
6
- :"direct-message" => {:regex => /!help/, :handler => :on_message}
7
- }
8
- )
9
-
10
- def self.on_message(message, matches)
11
- messages = []
12
- Linkbot::Plugin.plugins.each {|k,v|
13
- if(v[:handlers][message.type] && v[:handlers][message.type][:help])
14
- messages << v[:ptr].send(v[:handlers][message.type][:help])
15
- end
16
- }
17
- messages.sort! do |x,y|
18
- x =~ /([A-Za-z]+)/
19
- sort1 = $1
20
- y =~ /([A-Za-z]+)/
21
- sort2 = $1
22
- sort1 <=> sort2
23
- end
24
- messages.join("\n")
25
- end
26
- end