rbot 0.9.9 → 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. data/AUTHORS +8 -0
  2. data/ChangeLog +51 -0
  3. data/INSTALL +4 -0
  4. data/README +1 -0
  5. data/REQUIREMENTS +11 -0
  6. data/TODO +2 -0
  7. data/bin/rbot +21 -2
  8. data/data/rbot/languages/german.lang +4 -1
  9. data/data/rbot/languages/russian.lang +75 -0
  10. data/data/rbot/plugins/autoop.rb +42 -51
  11. data/data/rbot/plugins/bans.rb +205 -0
  12. data/data/rbot/plugins/bash.rb +56 -0
  13. data/data/rbot/plugins/chucknorris.rb +74 -0
  14. data/data/rbot/plugins/chucknorris.yml.gz +0 -0
  15. data/data/rbot/plugins/deepthoughts.rb +95 -0
  16. data/data/rbot/plugins/demauro.rb +95 -0
  17. data/data/rbot/plugins/digg.rb +51 -0
  18. data/data/rbot/plugins/figlet.rb +24 -0
  19. data/data/rbot/plugins/forecast.rb +133 -0
  20. data/data/rbot/plugins/freshmeat.rb +13 -7
  21. data/data/rbot/plugins/google.rb +2 -0
  22. data/data/rbot/plugins/grouphug.rb +36 -0
  23. data/data/rbot/plugins/imdb.rb +92 -0
  24. data/data/rbot/plugins/insult.rb +8 -1
  25. data/data/rbot/plugins/iplookup.rb +227 -0
  26. data/data/rbot/plugins/karma.rb +2 -2
  27. data/data/rbot/plugins/keywords.rb +470 -0
  28. data/data/rbot/plugins/lart.rb +132 -146
  29. data/data/rbot/plugins/lastfm.rb +25 -0
  30. data/data/rbot/plugins/markov.rb +204 -0
  31. data/data/rbot/plugins/math.rb +5 -1
  32. data/data/rbot/plugins/nickserv.rb +71 -11
  33. data/data/rbot/plugins/opme.rb +19 -19
  34. data/data/rbot/plugins/quakeauth.rb +2 -2
  35. data/data/rbot/plugins/quotes.rb +40 -25
  36. data/data/rbot/plugins/remind.rb +1 -1
  37. data/data/rbot/plugins/rot13.rb +2 -2
  38. data/data/rbot/plugins/roulette.rb +49 -15
  39. data/data/rbot/plugins/rss.rb +585 -0
  40. data/data/rbot/plugins/rubyurl.rb +39 -0
  41. data/data/rbot/plugins/seen.rb +2 -1
  42. data/data/rbot/plugins/slashdot.rb +5 -5
  43. data/data/rbot/plugins/spell.rb +5 -0
  44. data/data/rbot/plugins/theyfightcrime.rb +121 -0
  45. data/data/rbot/plugins/threat.rb +55 -0
  46. data/data/rbot/plugins/tinyurl.rb +39 -0
  47. data/data/rbot/plugins/topic.rb +204 -0
  48. data/data/rbot/plugins/urban.rb +71 -0
  49. data/data/rbot/plugins/url.rb +399 -4
  50. data/data/rbot/plugins/wow.rb +123 -0
  51. data/data/rbot/plugins/wserver.rb +1 -1
  52. data/data/rbot/templates/levels.rbot +2 -0
  53. data/lib/rbot/auth.rb +207 -96
  54. data/lib/rbot/channel.rb +5 -5
  55. data/lib/rbot/config.rb +125 -24
  56. data/lib/rbot/dbhash.rb +87 -21
  57. data/lib/rbot/httputil.rb +181 -13
  58. data/lib/rbot/ircbot.rb +525 -179
  59. data/lib/rbot/ircsocket.rb +330 -54
  60. data/lib/rbot/message.rb +66 -23
  61. data/lib/rbot/messagemapper.rb +25 -17
  62. data/lib/rbot/plugins.rb +244 -115
  63. data/lib/rbot/post-clean.rb +1 -0
  64. data/lib/rbot/{post-install.rb → post-config.rb} +1 -1
  65. data/lib/rbot/rbotconfig.rb +29 -14
  66. data/lib/rbot/registry.rb +111 -72
  67. data/lib/rbot/rfc2812.rb +208 -197
  68. data/lib/rbot/timer.rb +4 -0
  69. data/lib/rbot/utils.rb +2 -2
  70. metadata +127 -104
  71. data/data/rbot/plugins/rss.rb.disabled +0 -414
  72. data/lib/rbot/keywords.rb +0 -433
@@ -0,0 +1,56 @@
1
+ # bash.org xml plugin for rbot
2
+ # by Robin Kearney (robin@riviera.org.uk)
3
+ #
4
+ # its a bit of a quick hack, but it works for us :)
5
+ #
6
+ require 'rexml/document'
7
+ require 'uri/common'
8
+
9
+ class BashPlugin < Plugin
10
+ include REXML
11
+ def help(plugin, topic="")
12
+ "bash => print a random quote from bash.org, bash quote_id => print that quote id from bash.org, bash latest => print the latest quote from bash.org (currently broken, need to get josh@bash.org to fix the xml)"
13
+ end
14
+ def privmsg(m)
15
+ if m.params && m.params =~ /^([-\d]+)$/
16
+ id = $1
17
+ bash m, id
18
+ elsif(m.params == "latest")
19
+ bash m, id
20
+ else
21
+ bash m
22
+ end
23
+ end
24
+
25
+ def bash(m, id=0)
26
+
27
+ if(id != 0)
28
+ xml = @bot.httputil.get URI.parse("http://bash.org/xml/?" + id + "&num=1")
29
+ elsif(id == "latest")
30
+ xml = @bot.httputil.get URI.parse("http://bash.org/xml/?latest&num=1")
31
+ else
32
+ xml = @bot.httputil.get URI.parse("http://bash.org/xml/?random&num=1")
33
+ end
34
+ unless xml
35
+ m.reply "bash.org rss parse failed"
36
+ return
37
+ end
38
+ doc = Document.new xml
39
+ unless doc
40
+ m.reply "bash.org rss parse failed"
41
+ return
42
+ end
43
+ doc.elements.each("*/item") {|e|
44
+ if(id != 0)
45
+ reply = e.elements["title"].text.gsub(/QDB: /,"") + " " + e.elements["link"].text.gsub(/QDB: /,"") + "\n"
46
+ reply = reply + e.elements["description"].text.gsub(/\<br \/\>/, "\n")
47
+ else
48
+ reply = e.elements["title"].text.gsub(/QDB: /,"") + " " + e.elements["link"].text.gsub(/QDB: /,"") + "\n"
49
+ reply = reply + e.elements["description"].text.gsub(/\<br \/\>/, "\n")
50
+ end
51
+ m.reply reply
52
+ }
53
+ end
54
+ end
55
+ plugin = BashPlugin.new
56
+ plugin.register("bash")
@@ -0,0 +1,74 @@
1
+ require 'yaml'
2
+ require 'zlib'
3
+
4
+ MIN_RATING = 6.0
5
+ MIN_VOTES = 25
6
+
7
+ # the plugin
8
+ class ChuckNorrisPlugin < Plugin
9
+
10
+ # Loadez les factes
11
+ def initialize
12
+ if path = find_facts_file('chucknorris.yml.gz')
13
+ fyml = Zlib::GzipReader.open(path)
14
+ elsif path = find_facts_File('chucknorris.yml')
15
+ fyml = open(path)
16
+ else
17
+ raise "Error: Couldn't find chucknorris.yml[.gz]"
18
+ end
19
+
20
+ debug "+ [chucknorris] Loading #{path}..."
21
+
22
+ @@facts = YAML.load(fyml).map{|fact,(score,votes)| votes >= MIN_VOTES ? [score,fact] : nil}.compact
23
+ debug "+ [chucknorris] #{@@facts.length} Chuck Norris facts loaded..."
24
+ debug " Random fact: #{@@facts[rand(@@facts.size)].inspect}"
25
+
26
+ super
27
+ end
28
+
29
+ def name
30
+ "chucknorris"
31
+ end
32
+
33
+ # Just a little helper for the initialize method...
34
+ def find_facts_file(name)
35
+ full_path = File.join Config::datadir, "plugins", name
36
+ found_files = Dir[full_path]
37
+ if found_files.empty?
38
+ nil
39
+ else
40
+ found_files[0]
41
+ end
42
+ end
43
+
44
+ # HELP!
45
+ def help(plugin, topic="chuck")
46
+ "fact|chuck|norris|chucknorris [min_rating] => \"fact\" shows a random Chuck Norris fact (optional minimum rating from 1-10, default=6.0)."
47
+ #\"fact [person]\" shows a fact about someone in the channel.
48
+ end
49
+
50
+ # The meat.
51
+ def fact(m, params)
52
+ min = params[:minrating].to_f
53
+ debug "+ Getting Chuck Norris fact (rating > #{min})..."
54
+
55
+ viable_facts = @@facts.select {|rating, fact| rating >= min}
56
+ if viable_facts.empty?
57
+ debug " - no facts found with rating >= #{min}"
58
+ m.reply "Are you nuts?!? There are no facts better than #{min}!!!"
59
+ return
60
+ end
61
+
62
+ rating, fact = viable_facts[rand(viable_facts.length)]
63
+ m.reply "#{fact} [score=#{rating}]"
64
+ end
65
+
66
+ end
67
+
68
+ plugin = ChuckNorrisPlugin.new
69
+
70
+ plugin.map 'fact :minrating', :action => 'fact', :defaults => {:minrating=>MIN_RATING}
71
+ plugin.map 'chucknorris :minrating', :action => 'fact', :defaults => {:minrating=>MIN_RATING}
72
+ plugin.map 'chuck :minrating', :action => 'fact', :defaults => {:minrating=>MIN_RATING}
73
+ plugin.map 'norris :minrating', :action => 'fact', :defaults => {:minrating=>MIN_RATING}
74
+
@@ -0,0 +1,95 @@
1
+ THOUGHTS = [
2
+ 'It takes a big man to cry, but it takes a bigger man to laugh at that man.',
3
+ "If I ever get real rich, I hope I'm not real mean to poor people, like I am now.",
4
+ 'To me, it\'s always a good idea to always carry two sacks of something when you walk around. That way, if anybody says, "Hey, can you give me a hand?," you can say, "Sorry, got these sacks."',
5
+ 'Maybe in order to understand mankind we have to look at that word itself. MANKIND. Basically, it\'s made up of two separate words "mank" and "ind." What do these words mean? It\'s a mystery and that\'s why so is mankind.',
6
+ "Anytime I see something screech across a room and latch onto someone's neck, and the guy screams and tries to get it off, I have to laugh, because what is that thing.",
7
+ "If you're in a war, instead of throwing a hand grenade at the enemy, throw one of those small pumpkins. Maybe it'll make everyone think how stupid war is, and while they are thinking, you can throw a real grenade at them.",
8
+ 'One thing kids like is to be tricked. For instance, I was going to take my nephew to Disneyland, but instead I drove him to an old burned-out warehouse. "Oh no," I said, "Disneyland burned down." He cried and cried, but I think that deep down he thought it was a pretty good joke. I started to drive over to the real Disneyland, but it was getting pretty late.',
9
+ "To me, clowns aren't funny. In fact, they're kinda scary. I've wondered where this started and I think it goes back to the time I went to the circus and a clown killed my dad.",
10
+ "I can picture in my mind a world without war, a world without hate. And I can picture us attacking that world, because they'd never expect it.",
11
+ "When I was a kid my favorite relative was Uncle Caveman. After school we'd all go play in his cave, and every once in a while he would eat one of us. It wasn't until later that I found out that Uncle Caveman was a bear.",
12
+ 'Instead of trying to build newer and bigger weapons of destruction, we should be thinking about getting more use out of the ones we already have.',
13
+ 'If a kid asks where rain comes from, I think a cute thing to tell him is, "God is crying." And if he asks why God is crying, another cute thing to tell him is, "Probably because of something you did."',
14
+ 'When I found the skull in the woods, the first thing I did was call the police. But then I got curious about it. I picked it up, and started wondering who this person was, and why he had deer horns.',
15
+ "Instead of a trap door, what about a trap window? The guy looks out it, and if he leans too far, he falls out. Wait. I guess that's like a regular window.",
16
+ 'Laurie got offended that I used the word "puke." But to me, that\'s what her dinner tasted like.',
17
+ 'If you want to be the popular one at a party, here\'s a good thing to do: Go up to some people who are talking and laughing and say, "Well, technically that\'s illegal." It might fit in with what somebody just said. And even if it doesn\'t, so what, I hate this stupid party.',
18
+ "If you ever drop your keys into a river of molten lava, let'em go, because, man, they're gone.",
19
+ "I bet a funny thing about driving a car off a cliff is, while you're in midair, you still hit those brakes! Hey, better try the emergency brake!",
20
+ "When you die, if you get a choice between going to regular heaven or pie heaven, choose pie heaven. It might be a trick, but if it's not, mmmmmmm, boy.",
21
+ 'Dad always thought laughter was the best medicine, which I guess is why several of us died of tuberculosis.',
22
+ "If you ever fall off the Sears Tower, just go real limp, because maybe you'll look like a dummy and people will try to catch you because, hey, free dummy.",
23
+ 'I think a good product would be "Baby Duck Hat." It\'s a fake baby duck, which you strap on top of your head. Then you go swimming underwater until you find a mommy duck and her babies, and you join them. Then all of the sudden, you stand up out of the water and roar like Godzilla. Man those ducks really take off! Also Baby Duck Hat is good for parties.',
24
+ "Sometimes I think I'd be better off dead. No, wait, not me, you.",
25
+ 'I hope that someday we will be able to put away our fears and prejudices and just laugh at people.',
26
+ "I believe in making the world safe for our children, but not our children's children, because I don't think children should be having sex.",
27
+ 'I hope that after I die, people will say of me: "That guy sure owed me a lot of money."',
28
+ "One thing vampire children have to be taught early on is, don't run with a wooden stake.",
29
+ 'It makes me mad when people say I turned and ran like a scared rabbit. Maybe it was like an angry rabbit, who was going to fight in another fight, away from the first fight.',
30
+ "Broken promises don't upset me. I just think, why did they believe me?",
31
+ "How come the dove gets to be the peace symbol? How about the pillow? It has more feathers than the dove, and it doesn't have that dangerous beak.",
32
+ "If you define cowardice as running away at the first sign of danger, screaming and tripping and begging for mercy, then yes, Mr. Brave man, I guess I'm a coward.",
33
+ 'During the Middle Ages, probably one of the biggest mistakes was not putting on your armor because you were "just going down to the corner."',
34
+ 'If I lived back in the wild west days, instead of carrying a six-gun in my holster, I\'d carry a soldering iron. That way, if some smart-aleck cowboy said something like "Hey, look. He\'s carrying a soldering iron!" and started laughing, and everybody else started laughing, I could just say, "That\'s right, it\'s a soldering iron. The soldering iron of justice." Then everybody would get real quiet and ashamed, because they had made fun of the soldering iron of justice, and I could probably hit them up for a free drink.',
35
+ "I hope if dogs ever take over the world and they choose a king, they don't just go by size, because I bet there are some Chihuahuas with some good ideas.",
36
+ "Sometimes I think you have to march right in and demand your rights, even if you don't know what your rights are, or who the person is you're talking to. Then on the way out, slam the door.",
37
+ "Is there anything more beautiful than a beautiful, beautiful flamingo, flying across in front of a beautiful sunset? And he's carrying a beautiful rose in his beak, and also he's carrying a very beautiful painting with his feet. And also, you're drunk.",
38
+ "I wish I had a dollar for every time I spent a dollar, because then, yahoo!, I'd have all my money back.",
39
+ 'If I was the head of a country that lost a war, and I had to sign a peace treaty, just as I was signing, I\'d glance over the treaty and then suddenly act surprised. "Wait a minute! I thought we won!"',
40
+ "Once while walking through the mall a guy came up to me and said, 'Hey, how's it going?' So I grabbed his arm and twisted it up behind his head and said 'Now who's asking the questions?'",
41
+ 'The face of a child can say it all, especially the mouth part of the face.',
42
+ 'Why do the caterpillar and the ant have to be enemies? One eats leaves, and the other eats caterpillars. Oh, I see now.',
43
+ "We used to laugh at Grandpa when he'd head off and go fishing. But we wouldn't be laughing that evening when he'd come back with some whore he picked up in town.",
44
+ 'I can\'t stand cheap people. It makes me real mad when someone says something like, "Hey, when are you going to pay me that $100 you owe me?" or "Do you have that $50 you borrowed?" Man, quit being so cheap!',
45
+ "If you think a weakness can be turned into a strength, I hate to tell you this, but that's another weakness.",
46
+ "I'd like to see a nature film where an eagle swoops down and pulls a fish out of a lake, and then maybe he's flying along, low to the ground, and the fish pulls a worm out of the ground. Now that's a documentary!",
47
+ 'I hope they never find out that lightning has a lot of vitamins in it, because do you hide from it or not?',
48
+ 'Many people never stop to realize that a tree is a living thing, not that different from a tall, leafy dog that has roots and is very quiet.',
49
+ 'If you get invited to your first orgy, don\'t just show up nude. That\'s a common mistake. You have to let nudity "happen."',
50
+ "To me, boxing is like a ballet, except there's no music, no choreography and the dancers hit each other.",
51
+ "One thing a computer can do that most humans can't is be sealed up in a cardboard box and sit in a warehouse.",
52
+ "Whenever you read a good book, it's like the author is right there, in the room talking to you, which is why I don't like to read good books.",
53
+ "Contrary to what most people say, the most dangerous animal in the world is not the lion or the tiger or even the elephant. It's a shark riding on an elephant's back, just trampling and eating everything they see.",
54
+ 'Somebody told me how frightening it was how much topsoil we are losing each year, but I told that story around the campfire and nobody got scared.',
55
+ "If you go parachuting, and your parachute doesn't open, and you friends are all watching you fall, I think a funny gag would be to pretend you were swimming.",
56
+ "Whenever I see an old lady slip and fall on a wet sidewalk, my first instinct is to laugh. But then I think, what if I was an ant and she fell on me. Then it wouldn't seem quite so funny.",
57
+ "Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.",
58
+ 'I think there should be something in science called the "reindeer effect." I don\'t know what it would be, but I think it\'d be good to hear someone say, "Gentlemen, what we have here is a terrifying example of the reindeer effect."',
59
+ "If you go through a lot of hammers each month, I don't think it necessarily means you're a hard worker. It may just mean that you have a lot to learn about proper hammer maintenance.",
60
+ "You know what would make a good story? Something about a clown who make people happy, but inside he's real sad. Also, he has severe diarrhea.",
61
+ 'I wish I had a Kryptonite cross, because then you could keep both Dracula AND Superman away.',
62
+ 'Once when I was in Hawaii, on the island of Kauai, I met a mysterious old stranger. He said he was about to die and wanted to tell someone about the treasure. I said, "Okay, as long as it\'s not a long story. Some of us have a plane to catch, you know." He told us about his life and all, and I thought: "This story isn\'t too long." But then, he kept going, and I started thinking, "Uh-oh, this story is getting long." But then the story was over, and I said to myself: "You know, that story wasn\'t too long after all." I forget what the story was about, but there was a good movie on the plane. It was a little long, though.',
63
+ "A man doesn't automatically get my respect. He has to get down in the dirt and beg for it.",
64
+ "Love can sweep you off your feet and carry you along in a way you've never known before. But the ride always ends, and you end up feeling lonely and bitter. Wait. It's not love I'm describing. I'm thinking of a monorail.",
65
+ "For mad scientists who keep brains in jars, here's a tip: Why not add a slice of lemon to each jar, for freshness.",
66
+ 'Probably the earliest fly swatters were nothing more than some sort of striking surface attached to the end of a long stick.',
67
+ 'You know something that would really make me applaud? A guy gets stuck in quicksand, then sinks, then suddenly comes shooting out, riding on water skis! How do they do that?!',
68
+ 'I think somebody should come up with a way to breed a very large shrimp. That way, you could ride him, then after you camped at night, you could eat him. How about it, science?',
69
+ "I wouldn't be surprised if someday some fishermen caught a big shark and cut it open, and there inside was a whole person. Then they cut the person open, and in him is a little baby shark. And in the baby shark there isn't a person, because it would be too small. But there's a little doll or something, like a Johnny Combat little toy guy---something like that.",
70
+ 'We like to praise birds for flying. But how much of it is actually flying, and how much of it is just sort of coasting from the previous flap?',
71
+ 'Something tells me that the first mousetrap wasn\'t designed to catch mice at all, but to protect little cheese "gems" from burglars.',
72
+ 'I guess we were all guilty, in a way. We all shot him, we all skinned him, and we all got a complimentary bumper sticker that said, "I helped skin Bob."',
73
+ "If you ever reach total enlightenment while you're drinking a beer, I bet it makes beer shoot out your nose.",
74
+ "I guess I kinda lost control, because in the middle of the play I ran up and lit the evil puppet villain on fire. No, I didn't. Just kidding. I just said that to help illustrate one of the human emotions, which is freaking out. Another emotion is greed, as when you kill someone for money, or something like that. Another emotion is generosity, as when you pay someone double what he paid for his stupid puppet.",
75
+ 'Of all the tall tales, I think my favorite is the one about Eli Whitney and the interchangeable parts.',
76
+ ]
77
+
78
+ class DeepThoughts < Plugin
79
+ def help(plugin, topic="")
80
+ "deepthought => think a deep thought."
81
+ end
82
+
83
+ def deepthought(m, params)
84
+ thought = THOUGHTS[rand(THOUGHTS.length)]
85
+ m.reply thought
86
+ end
87
+ end
88
+
89
+ plugin = DeepThoughts.new
90
+ plugin.map 'deepthought'
91
+ #plugin.map 'movieplot', :action => 'do_movieplot'
92
+ #plugin.map 'movietitle', :action => 'do_movietitle'
93
+
94
+
95
+
@@ -0,0 +1,95 @@
1
+ require 'erb'
2
+
3
+ class DeMauroPlugin < Plugin
4
+ include ERB::Util
5
+
6
+ def initialize
7
+ super
8
+ @dmurl = "http://www.demauroparavia.it/"
9
+ end
10
+
11
+
12
+ def help(plugin, topic="")
13
+ return "demauro <parola> => fornisce il link della definizione della parola dal dizionario De Mauro/Paravia"
14
+ end
15
+
16
+ def demauro(m, params)
17
+ parola = params[:parola]
18
+ url = @dmurl + "cerca?stringa=#{url_encode(parola)}"
19
+ uri = URI.parse(url)
20
+ http = @bot.httputil.get_proxy(uri)
21
+ xml = nil
22
+ defurls = Array.new
23
+ begin
24
+ http.start() { |http|
25
+ resp = http.get(uri.request_uri())
26
+ case resp.code
27
+ when "200"
28
+ xml = resp.body
29
+ when "302"
30
+ loc = resp['location']
31
+ if loc =~ /#{@dmurl}\d+/
32
+ defurls << loc
33
+ end
34
+ else
35
+ debug resp.to_a
36
+ end
37
+ }
38
+ rescue => e
39
+ debug "HttpUtil.get exception: #{e.inspect}, while trying to get #{uri}"
40
+ debug e.backtrace.join("\n")
41
+ m.reply "C'è stato un errore nella ricerca"
42
+ return
43
+ end
44
+ if xml
45
+ if xml=~ /Non ho trovato occorrenze per/
46
+ m.reply "Parola non trovata"
47
+ return
48
+ else
49
+ xml.gsub(/href="(\d+)"/) { |match|
50
+ debug match.to_a.join(" || ")
51
+ defurls << "#{@dmurl}#{$1}"
52
+ }
53
+ end
54
+ end
55
+ lemmas = Array.new
56
+ defurls.each { |url|
57
+ uri = URI.parse(url)
58
+ http = @bot.httputil.get_proxy(uri)
59
+ begin
60
+ debug "Scanning #{url}"
61
+ http.start() { |http|
62
+ resp = http.get(uri.request_uri())
63
+ case resp.code
64
+ when "200"
65
+ debug "Got data"
66
+ matched = /<span class="lemma">(.*)<\/span><br\/><span class="qualifica".*?>(.*?)<\/span><br\/>/.match(resp.body)
67
+ dirtylemma = matched[1]
68
+ qual = matched[2]
69
+ lemma = dirtylemma.gsub(/<\/?span(?: class="pipelemma")?>/,"")
70
+ debug lemma
71
+ lemma = lemma.gsub(/<sup>1<\/sup>/,'¹').gsub(/<sup>2<\/sup>/,'²').gsub(/<sup>3<\/sup>/,'³')
72
+ lemma = lemma.gsub(/<sup>4<\/sup>/,'⁴').gsub(/<sup>5<\/sup>/,'⁵').gsub(/<sup>6<\/sup>/,'⁶')
73
+ lemma = lemma.gsub(/<sup>7<\/sup>/,'⁷').gsub(/<sup>8<\/sup>/,'⁸').gsub(/<sup>9<\/sup>/,'⁹')
74
+ debug lemma
75
+ lemma += " #{qual} (#{uri})"
76
+ lemmas << lemma
77
+ else
78
+ debug resp.to_a.join("\r")
79
+ end
80
+ }
81
+ rescue => e
82
+ debug "Exception '#{e.inspect}' while trying to get and parse #{uri}"
83
+ debug e.backtrace.join("\n")
84
+ m.reply "C'è stato un errore nell'elaborazione del risultato"
85
+ return
86
+ end
87
+ }
88
+ pre = lemmas.length > 1 ? "Lemmi trovati" : "Lemma trovato"
89
+ m.reply "#{pre}: #{lemmas.join(' ; ')}"
90
+ end
91
+ end
92
+
93
+ plugin = DeMauroPlugin.new
94
+ plugin.map 'demauro :parola', :action => 'demauro'
95
+
@@ -0,0 +1,51 @@
1
+ # Hacked up slashdot headlines plugin...
2
+
3
+ require 'time'
4
+ require 'rexml/document'
5
+ require 'uri/common'
6
+
7
+ class DiggPlugin < Plugin
8
+ include REXML
9
+ def help(plugin, topic="")
10
+ "digg [<max>=5] => show digg headlines, [<max>=5] => return up to <max> headlines (use a negative number to show all the headlines on one line)"
11
+ end
12
+
13
+ def digg(m, params)
14
+ max = params[:limit].to_i
15
+ debug "max is #{max}"
16
+ xml = @bot.httputil.get(URI.parse("http://digg.com/rss/index.xml"))
17
+ unless xml
18
+ m.reply "digg news parse failed"
19
+ return
20
+ end
21
+ doc = Document.new xml
22
+ unless doc
23
+ m.reply "digg news parse failed (invalid xml)"
24
+ return
25
+ end
26
+ done = 0
27
+ oneline = false
28
+ if max < 0
29
+ max = (0 - max)
30
+ oneline = true
31
+ end
32
+ max = 8 if max > 8
33
+ matches = Array.new
34
+ doc.elements.each("rss/channel/item") {|e|
35
+ matches << [ e.elements["title"].text,
36
+ Time.parse(e.elements["pubDate"].text).strftime('%a @ %I:%M%p') ]
37
+ done += 1
38
+ break if done >= max
39
+ }
40
+ if oneline
41
+ m.reply matches.collect{|mat| mat[0]}.join(" | ")
42
+ else
43
+ matches.each {|mat|
44
+ m.reply sprintf("%42s | %13s", mat[0][0,42], mat[1])
45
+ }
46
+ end
47
+ end
48
+ end
49
+ plugin = DiggPlugin.new
50
+ plugin.map 'digg :limit', :defaults => {:limit => 5},
51
+ :requirements => {:limit => /^-?\d+$/}
@@ -0,0 +1,24 @@
1
+ #DEFAULT_FONT="smslant"
2
+ DEFAULT_FONT="rectangles"
3
+ MAX_WIDTH=68
4
+
5
+ class FigletPlugin < Plugin
6
+ def help(plugin, topic="")
7
+ "figlet [<message>] => print using figlet"
8
+ end
9
+ def privmsg(m)
10
+ case m.params
11
+ when nil
12
+ m.reply "incorrect usage: " + help(m.plugin)
13
+ return
14
+ when (/^-/)
15
+ m.reply "incorrect usage: " + help(m.plugin)
16
+ return
17
+ else
18
+ m.reply Utils.safe_exec("/usr/bin/figlet", "-k", "-w", "#{MAX_WIDTH}", "-f", DEFAULT_FONT, m.params)
19
+ return
20
+ end
21
+ end
22
+ end
23
+ plugin = FigletPlugin.new
24
+ plugin.register("figlet")
@@ -0,0 +1,133 @@
1
+ #
2
+ # Forecast plugin for rbot
3
+ # by MrChucho (mrchucho@mrchucho.net)
4
+ # Copyright (C) 2006 Ralph M. Churchill
5
+ #
6
+ require 'soap/wsdlDriver'
7
+ require 'open-uri'
8
+ require 'rexml/document'
9
+ require 'erb'
10
+
11
+
12
+ class LatLong
13
+ include ERB::Util
14
+ # Determine the latitude and longitude of a location. City, State and/or ZIP
15
+ # are all valid.
16
+ # [+return+] latitude,longitude
17
+ def get_lat_long(loc)
18
+ loc = url_encode(loc)
19
+ url="http://api.local.yahoo.com/MapsService/V1/geocode?appid=mrchucho_rbot_weather&location=#{loc}"
20
+ lat,long = 0,0
21
+ begin
22
+ open(url) do |xmldoc|
23
+ results = (REXML::Document.new xmldoc).root
24
+ lat = results.elements["//Latitude/text()"].to_s
25
+ long = results.elements["//Longitude/text()"].to_s
26
+ end
27
+ rescue => err
28
+ raise err #?
29
+ end
30
+ return lat.to_f,long.to_f
31
+ end
32
+ end
33
+
34
+ class Forecast
35
+ WSDL_URI="http://www.nws.noaa.gov/forecasts/xml/SOAP_server/ndfdXMLserver.php?wsdl"
36
+ def initialize(lat,long)
37
+ @lat,@long=lat,long
38
+ # this extra step is for backward/forward compatibility
39
+ factory = SOAP::WSDLDriverFactory.new(WSDL_URI)
40
+ @forecaster=factory.respond_to?(:create_rpc_driver) ?
41
+ factory.create_rpc_driver : factory.create_driver
42
+ end
43
+ def forecast
44
+ return parse(retrieve),Time.new
45
+ end
46
+ private
47
+ def retrieve
48
+ forecast = @forecaster.NDFDgenByDay(
49
+ @lat,@long,Time.now.strftime("%Y-%m-%d"),2,"24 hourly")
50
+ (REXML::Document.new(forecast)).root
51
+ end
52
+ def parse(xml)
53
+ msg = String.new
54
+ (1..2).each do |day|
55
+ d = (day==1) ? 'Today' : 'Tomorrow'
56
+ hi = xml.elements["//temperature[@type='maximum']/value[#{day}]/text()"]
57
+ lo = xml.elements["//temperature[@type='minimum']/value[#{day}]/text()"]
58
+ w = xml.elements["//weather/weather-conditions[#{day}]/@weather-summary"]
59
+ precip_am = xml.elements["//probability-of-precipitation/value[#{day*2-1}]/text()"]
60
+ precip_pm = xml.elements["//probability-of-precipitation/value[#{day*2}]/text()"]
61
+ msg += "#{d}: Hi #{hi} Lo #{lo}, #{w}. Precip: AM #{precip_am}% PM #{precip_pm}%\n"
62
+ end
63
+ msg
64
+ end
65
+ end
66
+
67
+ class ForecastPlugin < Plugin
68
+ USAGE='forecast <location> => show the 2-day forecast for a location. Location can be any combination of City, State, Country and ZIP'
69
+ def help(plugin,topic="")
70
+ USAGE
71
+ end
72
+ def usage(m,params={})
73
+ m.reply USAGE
74
+ end
75
+ def initialize
76
+ super
77
+ # this plugin only wants to store strings
78
+ class << @registry
79
+ def store(val)
80
+ val
81
+ end
82
+ def restore(val)
83
+ val
84
+ end
85
+ end
86
+ @forecast_cache = Hash.new
87
+ end
88
+
89
+ def forecast(m,params)
90
+ if params[:location] and params[:location].any?
91
+ loc = params[:location].join
92
+ @registry[m.sourcenick] = loc
93
+ get_forecast(m,loc)
94
+ else
95
+ if @registry.has_key?(m.sourcenick) then
96
+ loc = @registry[m.sourcenick]
97
+ get_forecast(m,loc)
98
+ else
99
+ m.reply "Please specifiy the City, State or ZIP"
100
+ end
101
+ end
102
+ end
103
+
104
+ def get_forecast(m,loc)
105
+ begin
106
+ if @forecast_cache.has_key?(loc) and
107
+ Time.new - @forecast_cache[loc][:date] < 3600
108
+ forecast = @forecast_cache[loc][:forecast]
109
+ forecast_date = @forecast_cache[loc][:date]
110
+ else
111
+ begin
112
+ l = LatLong.new
113
+ f = Forecast.new(*l.get_lat_long(loc))
114
+ forecast,forecast_date = f.forecast
115
+ rescue => err
116
+ m.reply err
117
+ end
118
+ end
119
+ if forecast
120
+ m.reply forecast
121
+ @forecast_cache[loc] = {}
122
+ @forecast_cache[loc][:forecast] = forecast
123
+ @forecast_cache[loc][:date] = forecast_date
124
+ else
125
+ m.reply "Couldn't find forecast for #{loc}"
126
+ end
127
+ rescue => e
128
+ m.reply "ERROR: #{e}"
129
+ end
130
+ end
131
+ end
132
+ plugin = ForecastPlugin.new
133
+ plugin.map 'forecast *location', :defaults => {:location => false}