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,11 +0,0 @@
1
- class Shutup < Linkbot::Plugin
2
- def self.on_message(message, matches)
3
- "No, YOU #{matches[0]}"
4
- end
5
-
6
- Linkbot::Plugin.register('shutup', self,
7
- {
8
- :message => {:regex => /(.*), linkbot/, :handler => :on_message}
9
- }
10
- )
11
- end
@@ -1,15 +0,0 @@
1
- class Slap < Linkbot::Plugin
2
- Linkbot::Plugin.register('slapper', self,
3
- {
4
- :message => {:regex => /\/slap(?: (@[\w\s]+))?/, :handler => :on_message, :help => :help}
5
- }
6
- )
7
-
8
- def self.on_message(message, matches)
9
- "#{message.user_name} slaps #{matches[0]} around a bit with a large trout"
10
- end
11
-
12
- def self.help
13
- "/slap [username] - Flashback to the halcyon days of the 1990s when hammer pants were all the rage"
14
- end
15
- end
@@ -1,18 +0,0 @@
1
- class Snap < Linkbot::Plugin
2
- def self.on_message(message, matches)
3
- snaps = [ "http://i52.tinypic.com/302melk.gif",
4
- "http://www.youtube.com/watch?v=qL3TWooBGrI",
5
- "http://i51.tinypic.com/2roj8k0.jpg",
6
- "http://i3.photobucket.com/albums/y79/IJG/oh_snap.gif",
7
- "http://webimages.stephen-wright.net/house-ohsnap.gif",
8
- "http://www.gifsoup.com/webroot/animatedgifs/108696_o.gif"
9
- ]
10
- snaps[rand(snaps.length)]
11
- end
12
-
13
- Linkbot::Plugin.register('snap', self,
14
- {
15
- :message => {:regex => /SNAP\!/, :handler => :on_message}
16
- }
17
- )
18
- end
@@ -1,12 +0,0 @@
1
- class Stab < Linkbot::Plugin
2
- Linkbot::Plugin.register('stab', self,
3
- {
4
- :message => {:regex => /\/stab(?: ([\w\s]+))?/, :handler => :on_message}
5
- }
6
- )
7
-
8
- def self.on_message(message, matches)
9
- name = matches[0] || "everyone in the face"
10
- "#{message.user_name} stabs #{name}"
11
- end
12
- end
@@ -1,71 +0,0 @@
1
- class Store < Linkbot::Plugin
2
- def self.on_message(message, matches)
3
- mymsg = nil
4
-
5
- if matches[0] && matches[0].length > 0
6
- args = matches[0].split(" ")
7
- command = args.shift
8
-
9
- Linkbot::Plugin.plugins.each {|k,v|
10
- if v[:handlers][:"linkbot-store"] && v[:handlers][:"linkbot-store"][:regex] && v[:handlers][:"linkbot-store"][:regex].match(command)
11
- cost = v[:ptr].respond_to?(:cost) ? v[:ptr].send(:cost).to_i : 0
12
- if check_karma(user, cost)
13
- begin
14
- mymsg = v[:ptr].send(v[:handlers][:"linkbot-store"][:handler], user, args).join("\n")
15
- deduct_karma(user, cost)
16
- rescue StoreError
17
- mymsg = $!.message
18
- end
19
- else
20
- mymsg = "Not enough karma"
21
- end
22
- end
23
- }
24
- end
25
-
26
-
27
- if mymsg.nil?
28
- # Build out the menu
29
- mymsg = [
30
- "Karma Store",
31
- "-----------",
32
- "Buy some stuff with karma. To buy, just use the !store command, followed by the appropriate stuff.",
33
- ""
34
- ]
35
-
36
- num = 1
37
- Linkbot::Plugin.plugins.each {|k,v|
38
- if v[:handlers][:"linkbot-store"] && v[:ptr].respond_to?(:cost) && v[:ptr].respond_to?(:advertisement)
39
- mymsg << "#{num}. [COST #{v[:ptr].send(:cost)}] #{v[:ptr].send(:advertisement)}"
40
- num += 1
41
- end
42
- }
43
-
44
- mymsg = mymsg.join("\n")
45
- end
46
- mymsg
47
- end
48
-
49
- def self.check_karma(user, cost)
50
- karma = Linkbot.db.execute("select karma from karma where user_id=#{user['id']}")[0][0]
51
- karma > cost
52
- end
53
-
54
- def self.deduct_karma(user, cost)
55
- karma = Linkbot.db.execute("select karma from karma where user_id=#{user['id']}")[0][0] - cost
56
- Linkbot.db.execute("update karma set karma=#{karma} where user_id=#{user['id']}")
57
- end
58
-
59
- def self.help
60
- "!store - Buy some shit"
61
- end
62
-
63
- Linkbot::Plugin.register('store', self,
64
- {
65
- :"direct-message" => {:regex => /!store(.*)/, :handler => :on_message, :help => :help},
66
- }
67
- )
68
- end
69
-
70
- class StoreError < StandardError
71
- end
@@ -1,22 +0,0 @@
1
- class StoreHelp < Linkbot::Plugin
2
- def self.on_store(args)
3
- mymsg = nil
4
-
5
- if args.length > 0
6
- Linkbot::Plugin.plugins.each {|k,v|
7
- if v[:handlers][:"linkbot-store"] && v[:handlers][:"linkbot-store"][:help] && v[:handlers][:"linkbot-store"][:regex].match(args[0])
8
- mymsg = v[:ptr].send(v[:handlers][:"linkbot-store"][:help])
9
- end
10
- }
11
- end
12
-
13
- mymsg
14
- end
15
-
16
-
17
- Linkbot::Plugin.register('store_help', self,
18
- {
19
- :"linkbot-store" => {:regex => /^help$/, :handler => :on_store},
20
- }
21
- )
22
- end
@@ -1,41 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- class Swanson < Linkbot::Plugin
4
- def self.on_message(message, matches)
5
- quotes = [
6
- "http://www.pajiba.com/image/ron-dancing-animated.gif",
7
- "http://28.media.tumblr.com/tumblr_lgl0ieJ0Z01qzkiy8o1_400.jpg",
8
- "http://www.randomblog.org/wp-content/uploads/2011/02/Ron-Swanson-Pyramid-e1297006038780.jpg",
9
- "I have been developing the Swanson Pyramid of Greatness for years. It's a perfectly calibrated recipe for maximum personal achievement. Categories include: Capitalism, God's way of determining who is smart, and who is poor. Crying, acceptable at funerals and the Grand Canyon. Rage. Poise. Property rights. Fish, for sport only, not for meat. Fish meat is practically a vegetable.",
10
- "The less I know about other people's affairs, the happier I am. I'm not interested in caring about people. I once worked with a guy for three years and never learned his name. Best friend I ever had. We still never talk sometimes.",
11
- "Now, I know I'm not going to find somebody that's both aggressively mean and apathetic. April really is the whole package.",
12
- "You had me at meat tornado.",
13
- "I'm surrounded by a lot of women in this department. And that includes the men.",
14
- "When I walked in this morning I saw that the flag was at half mast, I though, 'All right, another bureaucrat ate it!' And then I saw it was Lil' Sebastian. Half mast is too high. Show some damn respect.",
15
- "I am submitting this menu from a Pawnee institution, J.J.'s Diner. Home of the world's best breakfast dish: The Four Horsemeals of the Eggporkalypse.",
16
- "You may have thought you heard me say I wanted a lot of bacon and eggs, but what I said was: Give me all the bacon and eggs you have.",
17
- "(On fishing) It's like yoga, except I still get to kill something.",
18
- "Encapsulate the spirit of melancholy. Easy. Boom, a sad desk. Boom, sad wall. It's art. Anything is anything.",
19
- "I am off to have a mid-morning pre-lunch with my lady friend, but I will be back in time for lunch.",
20
- "The key to burning an ex-wife effigy is to dip it in paraffin wax and then toss the flaming bottle of isopropyl alcohol from a safe distance. Do not stand too close when you light an ex-wife effigy.",
21
- "It's never too early to learn that the government is a greedy piglet that suckles on a taxpayer's teet until they have sore, chapped nipples. I'm gonna need a different metaphor to give this nine year old.",
22
- "Leslie, you need to understand that we are headed to the most special place on earth. When I'm done eating a Mulligan's meal, for weeks afterwards there are flecks of meat in my mustache and I refuse to clean it because every now and then a piece of meat will fall into my mouth.",
23
- "(His museum speech) Shut up. And look at me. Welcome to Visions of Nature. This room has several paintings in it. Some are big and some are small. People did them and they are here now. I believe after this is over they will be hung in government buildings. Why the government is involved in an art show is beyond me. I also think it's pointless for a human to paint scenes of nature when they can go outside and stand in it.",
24
- "The whole thing is a scam. Birthdays were invented by Hallmark to sell cards.",
25
- "I won't publicly endorse a product unless I use it exclusively. My only official recommendations are U.S. Army issued mustache trimmers, Morton's salt, and the C.R. Lawrence Fein two inch axe-style scraper oscillating knife blade."
26
- ]
27
- quotes[rand(quotes.length)]
28
- end
29
-
30
- def self.help
31
- "!swanson - The one and only, Ron Swanson"
32
- end
33
-
34
-
35
- Linkbot::Plugin.register('swanson', self,
36
- {
37
- :message => {:regex => /!swanson/, :handler => :on_message, :help => :help},
38
- :"direct-message" => {:regex => /!swanson/, :handler => :on_message, :help => :help}
39
- }
40
- )
41
- end
@@ -1,34 +0,0 @@
1
- class Titles < Linkbot::Plugin
2
- def self.on_store(args)
3
- mymsg = nil
4
-
5
- if args.length > 1
6
- target_user = args.shift
7
- rows = Linkbot.db.execute("select username,showname from users where username='#{target_user}'")
8
- if rows.length == 0
9
- raise StoreError.new("Unknown user")
10
- else
11
- old_username = (rows[0][1].nil? || rows[0][1] == '') ? rows[0][0] : rows[0][1]
12
- new_username = args.join(" ")
13
- Linkbot.db.execute("update users set showname='#{new_username}' where username='#{target_user}'")
14
- mymsg = "'#{old_username}' is now known as '#{new_username}'"
15
- end
16
- end
17
-
18
- mymsg
19
- end
20
-
21
- def self.cost
22
- 50
23
- end
24
-
25
- def self.advertisement
26
- "name (username) (new name): Change how a user's name appears in any linkbot command."
27
- end
28
-
29
- Linkbot::Plugin.register('titles', self,
30
- {
31
- :"linkbot-store" => {:regex => /^name$/, :handler => :on_store},
32
- }
33
- )
34
- end
@@ -1,21 +0,0 @@
1
- require 'net/http'
2
- require 'uri'
3
- require 'cgi'
4
-
5
- class Translate < Linkbot::Plugin
6
- def self.on_message(message, matches)
7
- res = Net::HTTP.post_form(URI.parse('http://www.cs.utexas.edu/users/jbc/bork/bork.cgi'),
8
- {'input'=> CGI.unescapeHTML(message_history[1]['body']), 'type'=>'chef'})
9
- CGI::unescape(res.body.to_s.gsub("&epus;","'"))
10
- end
11
-
12
- def self.help
13
- "!translate - Trunslete-a zee lest messege-a"
14
- end
15
-
16
- Linkbot::Plugin.register('translate', self,
17
- {
18
- :message => {:regex => /!translate/, :handler => :on_message, :help => :help}
19
- }
20
- )
21
- end
@@ -1,22 +0,0 @@
1
- class Tsa < Linkbot::Plugin
2
- Linkbot::Plugin.register('tsa', self,
3
- {
4
- :message => {:regex => Regexp.new('tsa', 'g'), :handler => :on_message}
5
- }
6
- )
7
-
8
- def self.on_message(message, matches)
9
- messages = [
10
- "I'm going to touch your balls with the back of my hand",
11
- "We have an opt-out!",
12
- "TSA: the McDonalds workers of the government",
13
- "Security Theater Professionals",
14
- "Sir, you've been added to the \"domestic extremists\" list",
15
- "Not all parts of the government are accountable to the public, especially the TSA",
16
- "Your junk is safe in our hands",
17
- "It's not a grope, it's a freedom pat",
18
- "We handle more packages than UPS",
19
- ]
20
- messages[rand(messages.length)]
21
- end
22
- end
@@ -1,20 +0,0 @@
1
- require 'twss'
2
-
3
- class Twss < Linkbot::Plugin
4
- def self.on_message(message, matches)
5
- TWSS.threshold = 2.0 #lower = 'better'
6
- if TWSS(message.body) and 1 < 0
7
- "That's what she said"
8
- else
9
- ""
10
- end
11
- end
12
-
13
- Linkbot::Plugin.register('twss', self,
14
- {
15
- :message => {:handler => :on_message}
16
- }
17
- )
18
- end
19
-
20
-
@@ -1,27 +0,0 @@
1
- class Define < Linkbot::Plugin
2
- def self.on_message(message, match)
3
- word = URI.escape(match[0])
4
- doc = Hpricot(open("http://www.urbandictionary.com/define.php?term=#{word}").read)
5
- definition = doc.search("#entries td div[@class=definition]")
6
- if definition.empty?
7
- message = "No definition for '#{match[0]}' found"
8
- else
9
- definition = definition[0].inner_html.gsub("<br />", "\n")
10
- definition = Sanitize.clean(definition)
11
- message = "#{match[0]}: #{definition}"
12
- end
13
-
14
- message
15
- end
16
-
17
- def self.help
18
- "!define (word) - use a dictionary, foo"
19
- end
20
-
21
- Linkbot::Plugin.register('urban', self,
22
- {
23
- :message => {:regex => /!define (.*)/, :handler => :on_message, :help => :help},
24
- :"direct-message" => {:regex => /!define (.*)/, :handler => :on_message, :help => :help}
25
- }
26
- )
27
- end
@@ -1,28 +0,0 @@
1
- module Util
2
- def self.ago_in_words(time1, time2)
3
- diff = time1.to_i - time2.to_i
4
- ago = ''
5
- if diff == 1
6
- ago = "#{diff} second ago"
7
- elsif diff < 60
8
- ago = "#{diff} seconds ago"
9
- elsif diff < 120
10
- ago = "a minute ago"
11
- elsif diff < 3600
12
- ago = "#{diff.to_i / 60} minutes ago"
13
- elsif diff < 7200
14
- ago = "an hour ago"
15
- elsif diff < 86400
16
- ago = "#{diff.to_i / 3600} hours ago"
17
- elsif diff < 172800
18
- ago = "yesterday"
19
- elsif diff < 604800
20
- ago = "#{diff.to_i / 86400} days ago"
21
- elsif diff < 1209600
22
- ago = "last week"
23
- else
24
- ago = "#{diff.to_i / 604800} weeks ago"
25
- end
26
- ago
27
- end
28
- end