diff options
Diffstat (limited to 'data/rbot')
-rw-r--r-- | data/rbot/plugins/dictclient.rb | 4 | ||||
-rw-r--r-- | data/rbot/plugins/factoids.rb | 2 | ||||
-rw-r--r-- | data/rbot/plugins/games/quiz.rb | 44 | ||||
-rw-r--r-- | data/rbot/plugins/games/uno.rb | 12 | ||||
-rwxr-xr-x | data/rbot/plugins/geoip.rb | 18 | ||||
-rw-r--r-- | data/rbot/plugins/imdb.rb | 4 | ||||
-rw-r--r-- | data/rbot/plugins/iplookup.rb | 10 | ||||
-rw-r--r-- | data/rbot/plugins/lastfm.rb | 18 | ||||
-rw-r--r-- | data/rbot/plugins/rss.rb | 4 | ||||
-rw-r--r-- | data/rbot/plugins/slashdot.rb | 6 | ||||
-rw-r--r-- | data/rbot/plugins/urban.rb | 2 |
11 files changed, 61 insertions, 63 deletions
diff --git a/data/rbot/plugins/dictclient.rb b/data/rbot/plugins/dictclient.rb index 34276dad..f55defa4 100644 --- a/data/rbot/plugins/dictclient.rb +++ b/data/rbot/plugins/dictclient.rb @@ -91,7 +91,7 @@ class DictClientPlugin < Plugin # the DICT object is automatically disconnected. the return value of the block # is returned from this method. # if an IRC message argument is passed, the error message will be replied - def with_dict(m=nil &block) + def with_dict(m=nil, &block) server, port = @bot.config['dictclient.server'].split ':' if @bot.config['dictclient.server'] server ||= 'dict.org' port ||= DICT::DEFAULT_PORT @@ -159,7 +159,7 @@ class DictClientPlugin < Plugin if results results.collect {|database, matches| @bot.config['dictclient.match_format'].gsub( - '<matches>', matches.collect {|m| format_headword m}.join(', ') + '<matches>', matches.collect {|hit| format_headword hit}.join(', ') ).gsub( '<database>', format_database(database) ) diff --git a/data/rbot/plugins/factoids.rb b/data/rbot/plugins/factoids.rb index 3ca19017..452efb98 100644 --- a/data/rbot/plugins/factoids.rb +++ b/data/rbot/plugins/factoids.rb @@ -65,7 +65,7 @@ class FactoidsPlugin < Plugin def index(f) fact = f.to_s return if fact.empty? - self.map { |f| f[:fact] }.index(fact) + self.map { |fs| fs[:fact] }.index(fact) end def delete(f) diff --git a/data/rbot/plugins/games/quiz.rb b/data/rbot/plugins/games/quiz.rb index 63a5dde4..d2e4ab97 100644 --- a/data/rbot/plugins/games/quiz.rb +++ b/data/rbot/plugins/games/quiz.rb @@ -285,8 +285,10 @@ class QuizPlugin < Plugin jokers = q.registry[nick].jokers rank = 0 - q.rank_table.each_index { |rank| break if nick.downcase == q.rank_table[rank][0].downcase } - rank += 1 + q.rank_table.each do |place| + rank += 1 + break if nick.downcase == place[0].downcase + end m.reply "#{nick}'s score is: #{score} Rank: #{rank} Jokers: #{jokers}" else @@ -313,45 +315,41 @@ class QuizPlugin < Plugin stats = q.registry[nick] # Find player in table - found_player = false - i = 0 - q.rank_table.each_index do |i| - if nick.downcase == q.rank_table[i][0].downcase - found_player = true + old_rank = nil + q.rank_table.each_with_index do |place, i| + if nick.downcase == place[0].downcase + old_rank = i break end end # Remove player from old position - if found_player - old_rank = i - q.rank_table.delete_at( i ) - else - old_rank = nil + if old_rank + q.rank_table.delete_at( old_rank ) end # Insert player at new position - inserted = false - q.rank_table.each_index do |i| - if stats.score > q.rank_table[i][1].score + new_rank = nil + q.rank_table.each_with_index do |place, i| + if stats.score > place[1].score q.rank_table[i,0] = [[nick, stats]] - inserted = true + new_rank = i break end end # If less than all other players' scores, append to table - unless inserted - i += 1 unless q.rank_table.empty? + unless new_rank + new_rank = q.rank_table.length q.rank_table << [nick, stats] end # Print congratulations/condolences if the player's rank has changed - unless old_rank.nil? - if i < old_rank - m.reply "#{nick} ascends to rank #{i + 1}. Congratulations :)" - elsif i > old_rank - m.reply "#{nick} slides down to rank #{i + 1}. So Sorry! NOT. :p" + if old_rank + if new_rank < old_rank + m.reply "#{nick} ascends to rank #{new_rank + 1}. Congratulations :)" + elsif new_rank > old_rank + m.reply "#{nick} slides down to rank #{new_rank + 1}. So Sorry! NOT. :p" end end else diff --git a/data/rbot/plugins/games/uno.rb b/data/rbot/plugins/games/uno.rb index 75154362..ab0ea161 100644 --- a/data/rbot/plugins/games/uno.rb +++ b/data/rbot/plugins/games/uno.rb @@ -772,9 +772,9 @@ class UnoGame } return false end - if p = get_player(user) + if pl = get_player(user) announce _("%{p} is already playing %{uno} here") % { - :p => p, :uno => UNO + :p => pl, :uno => UNO } return false end @@ -831,12 +831,12 @@ class UnoGame deal(p, @picker) @picker = 0 end - score = @players.inject(0) do |sum, p| - if p.cards.length > 0 + score = @players.inject(0) do |sum, pl| + if pl.cards.length > 0 announce _("%{p} still had %{cards}") % { - :p => p, :cards => p.cards.join(' ') + :p => pl, :cards => pl.cards.join(' ') } - sum += p.cards.inject(0) do |cs, c| + sum += pl.cards.inject(0) do |cs, c| cs += c.score end end diff --git a/data/rbot/plugins/geoip.rb b/data/rbot/plugins/geoip.rb index c67f1095..c76310d5 100755 --- a/data/rbot/plugins/geoip.rb +++ b/data/rbot/plugins/geoip.rb @@ -70,6 +70,12 @@ module ::GeoIP end end + JUMP_TABLE = { + "ipinfodb" => Proc.new { |ip| ipinfodb(ip) }, + "kapsi" => Proc.new { |ip| kapsi(ip) }, + "geoiptool" => Proc.new { |ip| geoiptool(ip) }, + } + def self.resolve(hostname, api) raise InvalidHostError unless valid_host?(hostname) @@ -79,15 +85,9 @@ module ::GeoIP raise InvalidHostError end - jump_table = { - "ipinfodb" => Proc.new { |ip| ipinfodb(ip) }, - "kapsi" => Proc.new { |ip| kapsi(ip) }, - "geoiptool" => Proc.new { |ip| geoiptool(ip) }, - } - - raise BadAPIError unless jump_table.key?(api) + raise BadAPIError unless JUMP_TABLE.key?(api) - return jump_table[api].call(ip) + return JUMP_TABLE[api].call(ip) end end @@ -153,7 +153,7 @@ class GeoIpPlugin < Plugin if m.replyto.class == Channel # check if there is an user on the channel with nick same as input given - user = m.replyto.users.find { |user| user.nick == params[:input] } + user = m.replyto.users.find { |usr| usr.nick == params[:input] } if user m.reply host2output(user.host, user.nick) diff --git a/data/rbot/plugins/imdb.rb b/data/rbot/plugins/imdb.rb index a12b7784..e1209124 100644 --- a/data/rbot/plugins/imdb.rb +++ b/data/rbot/plugins/imdb.rb @@ -309,8 +309,8 @@ class Imdb } end - urls.map { |url| - info = info_name(url, :movies_by_year => true) + urls.map { |u| + info = info_name(u, :movies_by_year => true) debug info.inspect diff --git a/data/rbot/plugins/iplookup.rb b/data/rbot/plugins/iplookup.rb index 495aa614..65867a50 100644 --- a/data/rbot/plugins/iplookup.rb +++ b/data/rbot/plugins/iplookup.rb @@ -116,12 +116,12 @@ module ArinWhois def get_parsed_data return unless chunks = parse_chunks - results = split_array_at(parse_chunks) {|chunk|chunk.customer?} - results.map do |chunks| + results = split_array_at(chunks) {|chunk|chunk.customer?} + results.map do |data| { - :customer => chunks.select{|x|x.customer?}[0], - :net => chunks.select{|x|x.network?}[0], - :contacts => chunks.select{|x|x.contact?} + :customer => data.select{|x|x.customer?}[0], + :net => data.select{|x|x.network?}[0], + :contacts => data.select{|x|x.contact?} } end end diff --git a/data/rbot/plugins/lastfm.rb b/data/rbot/plugins/lastfm.rb index 2e4c5114..4255e8a5 100644 --- a/data/rbot/plugins/lastfm.rb +++ b/data/rbot/plugins/lastfm.rb @@ -194,11 +194,11 @@ class LastFmPlugin < Plugin elsif venue begin venues = search_venue_by(:name => venue.to_s, :limit => 1) - rescue Exception => e - error e + rescue Exception => err + error err m.reply _("an error occurred looking for venue %{venue}: %{e}") % { :venue => venue.to_s, - :e => e.message + :e => err.message } end @@ -453,11 +453,11 @@ class LastFmPlugin < Plugin if results > 0 begin hits = [] - doc.root.each_element("results/trackmatches/track") do |track| + doc.root.each_element("results/trackmatches/track") do |trck| hits << _("%{bold}%{t}%{bold} by %{bold}%{a}%{bold} (%{n} listeners)") % { - :t => track.elements["name"].text, - :a => track.elements["artist"].text, - :n => track.elements["listeners"].text, + :t => trck.elements["name"].text, + :a => trck.elements["artist"].text, + :n => trck.elements["listeners"].text, :bold => Bold } end @@ -608,8 +608,8 @@ class LastFmPlugin < Plugin begin res = @bot.httputil.get_response(uri) raise _("no response body") unless res.body - rescue Exception => e - m.reply _("I had problems accessing last.fm: %{e}") % {:e => e.message} + rescue Exception => err + m.reply _("I had problems accessing last.fm: %{e}") % {:e => err.message} return end doc = Document.new(res.body) diff --git a/data/rbot/plugins/rss.rb b/data/rbot/plugins/rss.rb index 6b163619..4280c52a 100644 --- a/data/rbot/plugins/rss.rb +++ b/data/rbot/plugins/rss.rb @@ -935,8 +935,8 @@ class RSSFeedsPlugin < Plugin stop_watches # Read watches from list. - watchlist.each{ |handle, feed| - watchRss(feed, m) + watchlist.each{ |hndl, fd| + watchRss(fd, m) } m.okay if m end diff --git a/data/rbot/plugins/slashdot.rb b/data/rbot/plugins/slashdot.rb index 69f1566f..2c4a2361 100644 --- a/data/rbot/plugins/slashdot.rb +++ b/data/rbot/plugins/slashdot.rb @@ -75,9 +75,9 @@ class SlashdotPlugin < Plugin debug xml.inspect begin doc = Document.new xml - rescue REXML::ParseException => e - warning e.inspect - m.reply "couldn't parse output XML: #{e.class}" + rescue REXML::ParseException => err + warning err.inspect + m.reply "couldn't parse output XML: #{err.class}" return end unless doc diff --git a/data/rbot/plugins/urban.rb b/data/rbot/plugins/urban.rb index 6c10ed4b..d6688306 100644 --- a/data/rbot/plugins/urban.rb +++ b/data/rbot/plugins/urban.rb @@ -34,7 +34,7 @@ class UrbanPlugin < Plugin return m.reply("#{Bold}#{word}#{Bold} not found") if rv.empty? if notfound - suggestions = rv.map { |s| Underline + s[1] + Underline }.uniq.join ', ' + suggestions = rv.map { |str| Underline + str[1] + Underline }.uniq.join ', ' m.reply "#{Bold}#{word}#{Bold} not found. maybe you mean #{suggestions}?" return end |