]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
some awesome plugins from Chris Gahan >:)
authorTom Gilbert <tom@linuxbrit.co.uk>
Fri, 20 Jan 2006 09:27:18 +0000 (09:27 +0000)
committerTom Gilbert <tom@linuxbrit.co.uk>
Fri, 20 Jan 2006 09:27:18 +0000 (09:27 +0000)
data/rbot/plugins/chucknorris.rb [new file with mode: 0644]
data/rbot/plugins/digg.rb [new file with mode: 0644]
data/rbot/plugins/theyfightcrime.rb [new file with mode: 0755]

diff --git a/data/rbot/plugins/chucknorris.rb b/data/rbot/plugins/chucknorris.rb
new file mode 100644 (file)
index 0000000..0eee0c1
--- /dev/null
@@ -0,0 +1,39 @@
+require 'rexml/document'
+require 'uri/common'
+
+class ChuckNorrisPlugin < Plugin
+  include REXML
+
+  def help(plugin, topic="")
+    "chucknorris [<howmany>=1] => show a random chuck norris quote, or specify <howmany> quotes you want (maximum is 6)."
+  end
+  
+  def chucknorris(m, params)
+    howmany = params[:howmany].to_i
+    howmany = 6 if howmany > 6
+
+    factdata = @bot.httputil.get(URI.parse('http://www.4q.cc/chuck/rss.php'))
+    unless factdata
+      m.reply "Chuck Norris' facts roundhouse kicked the internet connection and totally wasted it."
+      return
+    end
+
+    begin
+      doc = Document.new factdata
+      doc.get_elements('rss/channel/item')[1..howmany].each do |fact|
+        m.reply fact.elements['description'].text
+      end
+
+    rescue ParseException => e
+      puts "Error parsing chuck norris quote: #{e.inspect}"
+      m.reply "Chuck Norris' facts were so intense that they blew up my XML parser."
+
+    end
+
+  end
+
+end
+
+plugin = ChuckNorrisPlugin.new
+plugin.map 'chucknorris :howmany', :defaults => {:howmany => 1},
+                                   :requirements => {:howmany => /^-?\d+$/} 
diff --git a/data/rbot/plugins/digg.rb b/data/rbot/plugins/digg.rb
new file mode 100644 (file)
index 0000000..e125d3c
--- /dev/null
@@ -0,0 +1,51 @@
+# Hacked up slashdot headlines plugin...
+
+require 'time'
+require 'rexml/document'
+require 'uri/common'
+
+class DiggPlugin < Plugin
+  include REXML
+  def help(plugin, topic="")
+    "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)"
+  end
+  
+  def digg(m, params)
+    max = params[:limit].to_i
+    puts "max is #{max}"
+    xml = @bot.httputil.get(URI.parse("http://digg.com/rss/index.xml"))
+    unless xml
+      m.reply "digg news parse failed"
+      return
+    end
+    doc = Document.new xml
+    unless doc
+      m.reply "digg news parse failed (invalid xml)"
+      return
+    end
+    done = 0
+    oneline = false
+    if max < 0
+      max = (0 - max)
+      oneline = true
+    end
+    max = 8 if max > 8
+    matches = Array.new
+    doc.elements.each("rss/channel/item") {|e|
+      matches << [ e.elements["title"].text, 
+                   Time.parse(e.elements["pubDate"].text).strftime('%a @ %I:%M%p') ]
+      done += 1
+      break if done >= max
+    } 
+    if oneline
+      m.reply matches.collect{|mat| mat[0]}.join(" | ")
+    else
+      matches.each {|mat|
+        m.reply sprintf("%42s | %13s", mat[0][0,42], mat[1])
+      }
+    end
+  end
+end
+plugin = DiggPlugin.new
+plugin.map 'digg :limit', :defaults => {:limit => 5},
+                          :requirements => {:limit => /^-?\d+$/}
diff --git a/data/rbot/plugins/theyfightcrime.rb b/data/rbot/plugins/theyfightcrime.rb
new file mode 100755 (executable)
index 0000000..1d18501
--- /dev/null
@@ -0,0 +1,121 @@
+HE = [
+
+    ['a superhumanly strong','an underprivileged','a globe-trotting','an impetuous','a shy','a suave','a notorious','a one-legged','an all-American','a short-sighted','an otherworldly','a hate-fuelled','a scrappy','an unconventional','a jaded','a leather-clad','a fiendish','a Nobel prize-winning','a suicidal','a maverick','a bookish','an old-fashioned','a witless','a lounge-singing','a war-weary','a scarfaced','a gun-slinging','an obese','a time-tossed','a benighted','an uncontrollable','an immortal','an oversexed','a world-famous','an ungodly','a fast talking','a deeply religious','a lonely','a sword-wielding','a genetically engineered'],
+    
+    ['white trash','zombie','shark-wrestling','playboy','guitar-strumming','Jewish',
+    'sweet-toothed','bohemian','crooked','chivalrous','moralistic','amnesiac','devious','drug-addicted',
+    'voodoo','Catholic','overambitious','coffee-fuelled','pirate','misogynist','skateboarding',
+    'arachnophobic','Amish','small-town','Republican','one-eyed','gay','guerilla','vegetarian',
+    'dishevelled','alcoholic','flyboy','ninja','albino','hunchbacked','neurotic','umbrella-wielding',
+    'native American','soccer-playing','day-dreaming'],
+    
+    ['grifter','stage actor','paramedic','gentleman spy','jungle king','hairdresser',
+    'photographer','ex-con','vagrant','filmmaker','werewolf','senator','romance novelist','shaman','cop',
+    'rock star','farmboy','cat burglar','cowboy','cyborg','inventor','assassin','boxer','dog-catcher',
+    'master criminal','gangster','firefighter','househusband','dwarf','librarian','paranormal investigator',
+    'Green Beret','waffle chef','vampire hunter','messiah','astronaut','sorceror','card sharp','matador',
+    'barbarian'],
+    
+    ['with a robot buddy named Sparky.','whom everyone believes is mad.','gone bad.',
+    'with a mysterious suitcase handcuffed to his arm.','living undercover at Ringling Bros. Circus.',
+    'searching for his wife''s true killer.','who dotes on his loving old ma.','looking for ''the Big One.''',
+    'who knows the secret of the alien invasion.','on the edge.','on a mission from God.','with a secret.',
+    'in drag.','plagued by the memory of his family''s brutal murder.','looking for a cure to the poison coursing through his veins.',
+    'moving from town to town, helping folk in trouble.',
+    'who must take medication to keep him sane.','who hangs with the wrong crowd.',
+    'possessed of the uncanny powers of an insect.','with a winning smile and a way with the ladies.',
+    'fleeing from a secret government programme.','from the ''hood.','haunted by an iconic dead American confidante.',
+    'with a passion for fast cars.','trapped in a world he never made.','in a wheelchair.',
+    'on the hunt for the last specimen of a great and near-mythical creature.','on the run.',
+    'for the 21st century.','who hides his scarred face behind a mask.','on the wrong side of the law.',
+    'with no name.','from the Mississippi delta.','with acid for blood.','with nothing left to lose.',
+    'haunted by memories of ''Nam.','on a search for his missing sister.','on his last day in the job.',
+    'from a doomed world.','who believes he can never love again.']
+
+]
+
+SHE = [
+
+    ['a radical','a green-fingered','a tortured','a time-travelling','a vivacious',
+    'a scantily clad','a mistrustful','a violent','a transdimensional','a strong-willed','a ditzy','a man-hating',
+    'a high-kicking','a blind','an elegant','a supernatural','a foxy','a bloodthirsty','a cynical','a beautiful',
+    'a plucky','a sarcastic','a psychotic','a hard-bitten','a manipulative','an orphaned','a cosmopolitan',
+    'a chain-smoking','a cold-hearted','a warm-hearted','a sharp-shooting','an enchanted','a wealthy','a pregnant',
+    'a mentally unstable','a virginal','a brilliant','a disco-crazy','a provocative','an artistic'],
+    
+    ['tempestuous', 'Buddhist', 'foul-mouthed', 'nymphomaniac', 'green-skinned', 'impetuous', 'African-American','punk','hypochondriac','junkie','blonde','goth','insomniac','gypsy','mutant','renegade', 'tomboy','French-Canadian','motormouth','belly-dancing','communist','hip-hop','thirtysomething',
+    'cigar-chomping','extravagent','out-of-work','Bolivian','mute','cat-loving','snooty','wisecracking',
+    'red-headed','winged','kleptomaniac','antique-collecting','psychic','gold-digging','bisexual','paranoid',
+    'streetsmart'],
+    
+    ['archaeologist','pearl diver','mechanic','detective','hooker','femme fatale',
+    'former first lady','barmaid','fairy princess','magician''s assistant','schoolgirl','college professor',
+    'angel','bounty hunter','opera singer','cab driver','soap star','doctor','politician','lawyer','nun',
+    'snake charmer','journalist','bodyguard','vampire','stripper','Valkyrie','wrestler','mermaid','single mother',
+    'safe cracker','traffic cop','research scientist','queen of the dead','Hell''s Angel','museum curator',
+    'advertising executive','widow','mercenary','socialite'],
+    
+    ['on her way to prison for a murder she didn''t commit.','trying to make a difference in a man''s world.',
+    'with the soul of a mighty warrior.','looking for love in all the wrong places.','with an MBA from Harvard.',
+    'who hides her beauty behind a pair of thick-framed spectacles.','with the power to see death.',
+    'descended from a line of powerful witches.','from a family of eight older brothers.','with a flame-thrower.',
+    'with her own daytime radio talk show.','living on borrowed time.','who can talk to animals.',
+    'prone to fits of savage, blood-crazed rage.','who don''t take no shit from nobody.','with a knack for trouble.',
+    'who believes she is the reincarnation of an ancient Egyptian queen.','fleeing from a Satanic cult.',
+    'on the trail of a serial killer.','with a birthmark shaped like Liberty''s torch.',
+    'in the witness protection scheme.','from out of town.','from aristocratic European stock.',
+    'living homeless in New York''s sewers.','with only herself to blame.','from beyond the grave',
+    'married to the Mob.','from the wrong side of the tracks.','from a secret island of warrior women.',
+    'from Mars.','with someone else''s memories.','from a different time and place.','operating on the wrong side of the law.',
+    'who inherited a spooky stately manor from her late maiden aunt.','who dreams of becoming Elvis.',
+    'with a song in her heart and a spring in her step.','in the wrong place at the wrong time.',
+    'with an incredible destiny.','with the power to bend men''s minds.','with an evil twin sister.']
+
+]
+
+TITLE = [
+
+    ['FATAL', 'PRIMAL', 'BASIC', 'LETHAL',
+    'FINAL', 'CLEAR', 'DIRTY', 'RED', 'FOREIGN', 'PRIMARY', 'EXECUTIVE',
+    'BLOOD', 'HARD', 'STEEL', 'TERMINAL', 'HOT', 'COLD', 'TOTAL', 'PROGNOSIS:',
+    'BURNING', 'FAST', 'PAINFUL', 'MISSION:', 'DEADLY', 'PARTIAL',
+    'RAGING', 'CORDIAL'],
+    
+    ['DECISION', 'INCISION', 'CONCLUSION',
+    'CONCUSSION', 'HEAT', 'FIRE', 'RECOIL', 'INSTINCT', 'DESIRE', 'WEAPON',
+    'BADGE', 'DEED', 'JUSTICE', 'HEAT', 'VENGEANCE', 'RECESSION', 'COMBUSTION',
+    'JUDGEMENT', 'WARNING', 'AWAKENING', 'JURISDICTION', 'BASIS', 'FINDINGS',
+    'INJECTION', 'REJECTION', 'REMISSION', 'DIGESTION', 'IDENTITY',
+    'DISPERSION'],
+    
+    ['II','III','IV','V','VI','VII','VIII','IX','X','XI','XII','XIII','XIV','XV','XVI','XVII','XVIII','XIX']
+
+]
+
+class TheyFightCrime < Plugin
+    def help(plugin, topic="")
+        "movieplot => generate a random movie scenario. movietitle => generate a random movie title."
+    end
+    
+    def get_random_things(thing_array)
+        thing_array.map { |things| things[rand(things.length)] }
+    end
+    
+    def do_movieplot(m, params)
+        he_things = get_random_things(HE)
+        she_things = get_random_things(SHE)
+        m.reply "Summary: He's a #{he_things.join " "} She's a #{she_things.join " "} They fight crime."
+    end
+
+    def do_movietitle(m, params)
+        title_things = get_random_things(TITLE)
+        m.reply "Title: #{title_things.join " "}"
+    end
+end
+
+plugin = TheyFightCrime.new
+plugin.map 'movieplot', :action => 'do_movieplot'
+plugin.map 'movietitle', :action => 'do_movietitle'
+
+
+