]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
Renames the 'karma' plugin to a 'points' system
authorEric Sorenson <eric.sorenson@puppetlabs.com>
Tue, 15 Dec 2015 22:44:51 +0000 (14:44 -0800)
committerEric Sorenson <eric.sorenson@puppetlabs.com>
Tue, 15 Dec 2015 23:27:52 +0000 (15:27 -0800)
Prior to this commit, rbot used a "karma" system for keeping
track of user points. This phrasing, while widespread, is
unnecessarily appropriationist.

This commit renames the plugin to a more neutral "points"
system, accomplishing exactly the same goal without using
culturally problematic language.

For more background please read: http://bit.ly/1MfLmce

21 files changed:
data/rbot/plugins/excuse.rb
data/rbot/plugins/karma.rb [deleted file]
data/rbot/plugins/points.rb [new file with mode: 0644]
lib/rbot/messagemapper.rb
lib/rbot/plugins.rb
po/en/rbot-karma.po [deleted file]
po/en/rbot-points.po [new file with mode: 0644]
po/fi/rbot-karma.po [deleted file]
po/fi/rbot-points.po [new file with mode: 0644]
po/fr/rbot-karma.po [deleted file]
po/fr/rbot-points.po [new file with mode: 0644]
po/it/rbot-karma.po [deleted file]
po/it/rbot-points.po [new file with mode: 0644]
po/ja/rbot-karma.po [deleted file]
po/ja/rbot-points.po [new file with mode: 0644]
po/rbot-karma.pot [deleted file]
po/rbot-points.pot [new file with mode: 0644]
po/zh_CN/rbot-karma.po [deleted file]
po/zh_CN/rbot-points.po [new file with mode: 0644]
po/zh_TW/rbot-karma.po [deleted file]
po/zh_TW/rbot-points.po [new file with mode: 0644]

index ad0e8334e58f7ad3d5889847f4502ceb59131ae4..61f38bd678ec725f2b57acfef019bdf6bdad584d 100644 (file)
@@ -387,7 +387,7 @@ class ExcusePlugin < Plugin
 "Dyslexics retyping hosts file on servers",
 "The Internet is being scanned for viruses.",
 "Your computer's union contract is set to expire at midnight.",
-"Bad user karma.",
+"Bad reputation.",
 "/dev/clue was linked to /dev/null",
 "Increased sunspot activity.",
 "We already sent around a notice about that.",
diff --git a/data/rbot/plugins/karma.rb b/data/rbot/plugins/karma.rb
deleted file mode 100644 (file)
index 93d2118..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-class KarmaPlugin < Plugin
-  def initialize
-    super
-
-    # this plugin only wants to store ints!
-    class << @registry
-      def store(val)
-        val.to_i
-      end
-      def restore(val)
-        val.to_i
-      end
-    end
-    @registry.set_default(0)
-
-    # import if old file format found
-    oldkarma = @bot.path 'karma.rbot'
-    if File.exist? oldkarma
-      log "importing old karma data"
-      IO.foreach(oldkarma) do |line|
-        if(line =~ /^(\S+)<=>([\d-]+)$/)
-          item = $1
-          karma = $2.to_i
-          @registry[item] = karma
-        end
-      end
-      File.delete oldkarma
-    end
-  end
-
-  def stats(m, params)
-    if (@registry.length)
-      max = @registry.values.max
-      min = @registry.values.min
-      best = @registry.to_hash.index(max)
-      worst = @registry.to_hash.index(min)
-      m.reply "#{@registry.length} items. Best: #{best} (#{max}); Worst: #{worst} (#{min})"
-    end
-  end
-
-  def karma(m, params)
-    thing = params[:key]
-    thing = m.sourcenick unless thing
-    thing = thing.to_s
-    karma = @registry[thing]
-    if(karma != 0)
-      m.reply "karma for #{thing}: #{@registry[thing]}"
-    else
-      m.reply "#{thing} has neutral karma"
-    end
-  end
-
-  def setkarma(m, params)
-    thing = (params[:key] || m.sourcenick).to_s
-    @registry[thing] = params[:val].to_i
-    karma(m, params)
-  end
-
-  def help(plugin, topic="")
-    "karma module: Listens to everyone's chat. <thing>++/<thing>-- => increase/decrease karma for <thing>, karma for <thing>? => show karma for <thing>, karmastats => show stats. Karma is a community rating system - only in-channel messages can affect karma and you cannot adjust your own."
-  end
-
-  def message(m)
-    return unless m.public? && m.message.match(/\+\+|--/)
-    arg = nil
-    op = nil
-    ac = Hash.new
-    m.message.split.each_with_index do |tok, i|
-      tok.sub!(/[:,]$/, '') if i == 0
-      catch :me_if_you_can do
-        if m.channel.users[tok].nil?
-          if (tok =~ /^(?:--)(.*[^-].*)$/) || (tok =~ /^(.*[^-].*)(?:--)$/)
-            op, arg = '--', $1
-            next
-          elsif (tok =~ /^(?:\+\+)(.*[^+].*)$/)||(tok =~ /^(.*[^+].*)(?:\+\+)$/)
-            op, arg = '++', $1
-            next
-          end
-        end
-
-        if (tok =~ /^--+$/) || (tok =~ /^\+\++$/)
-          op = tok.slice(0, 2)
-        else
-          arg = tok
-        end
-      end # catch
-
-      if op && arg
-        ac[arg] ||= 0
-        ac[arg] += (op == '--' ? -1 : 1) unless arg.downcase == m.sourcenick.downcase
-        op = arg = nil
-      end
-    end
-
-    ac.each do |k, v|
-      next if v == 0
-      @registry[k] += (v > 0 ? 1 : -1)
-      m.reply @bot.lang.get("thanks") if k == @bot.nick && v > 0
-    end
-  end
-end
-
-plugin = KarmaPlugin.new
-
-plugin.default_auth( 'edit', false )
-
-plugin.map 'karmastats', :action => 'stats'
-plugin.map 'karma :key', :defaults => {:key => false}
-plugin.map 'setkarma :key :val', :defaults => {:key => false}, :requirements => {:val => /^-?\d+$/}, :auth_path => 'edit::set!'
-plugin.map 'karma for :key'
diff --git a/data/rbot/plugins/points.rb b/data/rbot/plugins/points.rb
new file mode 100644 (file)
index 0000000..1a1464e
--- /dev/null
@@ -0,0 +1,110 @@
+class PointsPlugin < Plugin
+  def initialize
+    super
+
+    # this plugin only wants to store ints!
+    class << @registry
+      def store(val)
+        val.to_i
+      end
+      def restore(val)
+        val.to_i
+      end
+    end
+    @registry.set_default(0)
+
+    # import if old file format found
+    oldpoints = @bot.path 'points.rbot'
+    if File.exist? oldpoints
+      log "importing old points data"
+      IO.foreach(oldpoints) do |line|
+        if(line =~ /^(\S+)<=>([\d-]+)$/)
+          item = $1
+          points = $2.to_i
+          @registry[item] = points
+        end
+      end
+      File.delete oldpoints
+    end
+  end
+
+  def stats(m, params)
+    if (@registry.length)
+      max = @registry.values.max
+      min = @registry.values.min
+      best = @registry.to_hash.index(max)
+      worst = @registry.to_hash.index(min)
+      m.reply "#{@registry.length} items. Best: #{best} (#{max}); Worst: #{worst} (#{min})"
+    end
+  end
+
+  def points(m, params)
+    thing = params[:key]
+    thing = m.sourcenick unless thing
+    thing = thing.to_s
+    points = @registry[thing]
+    if(points != 0)
+      m.reply "points for #{thing}: #{@registry[thing]}"
+    else
+      m.reply "#{thing} has zero points"
+    end
+  end
+
+  def setpoints(m, params)
+    thing = (params[:key] || m.sourcenick).to_s
+    @registry[thing] = params[:val].to_i
+    points(m, params)
+  end
+
+  def help(plugin, topic="")
+    "points module: Keeps track of internet points, infusing your pointless life with meaning. Listens to everyone's chat. <thing>++/<thing>-- => increase/decrease points for <thing>, points for <thing>? => show points for <thing>, pointstats => show stats. Points are a community rating system - only in-channel messages can affect points and you cannot adjust your own."
+  end
+
+  def message(m)
+    return unless m.public? && m.message.match(/\+\+|--/)
+    arg = nil
+    op = nil
+    ac = Hash.new
+    m.message.split.each_with_index do |tok, i|
+      tok.sub!(/[:,]$/, '') if i == 0
+      catch :me_if_you_can do
+        if m.channel.users[tok].nil?
+          if (tok =~ /^(?:--)(.*[^-].*)$/) || (tok =~ /^(.*[^-].*)(?:--)$/)
+            op, arg = '--', $1
+            next
+          elsif (tok =~ /^(?:\+\+)(.*[^+].*)$/)||(tok =~ /^(.*[^+].*)(?:\+\+)$/)
+            op, arg = '++', $1
+            next
+          end
+        end
+
+        if (tok =~ /^--+$/) || (tok =~ /^\+\++$/)
+          op = tok.slice(0, 2)
+        else
+          arg = tok
+        end
+      end # catch
+
+      if op && arg
+        ac[arg] ||= 0
+        ac[arg] += (op == '--' ? -1 : 1) unless arg.downcase == m.sourcenick.downcase
+        op = arg = nil
+      end
+    end
+
+    ac.each do |k, v|
+      next if v == 0
+      @registry[k] += (v > 0 ? 1 : -1)
+      m.reply @bot.lang.get("thanks") if k == @bot.nick && v > 0
+    end
+  end
+end
+
+plugin = PointsPlugin.new
+
+plugin.default_auth( 'edit', false )
+
+plugin.map 'pointstats', :action => 'stats'
+plugin.map 'points :key', :defaults => {:key => false}
+plugin.map 'setpoints :key :val', :defaults => {:key => false}, :requirements => {:val => /^-?\d+$/}, :auth_path => 'edit::set!'
+plugin.map 'points for :key'
index 3e877626d54289a47ed7134f314495e54a6e0790..3966bc17f7360ec3853cda6995c479d3ab9e7590 100644 (file)
@@ -199,12 +199,12 @@ class Bot
     #
     # Further examples:
     #
-    #   # match 'karmastats' and call my stats() method
-    #   plugin.map 'karmastats', :action => 'stats'
-    #   # match 'karma' with an optional 'key' and call my karma() method
-    #   plugin.map 'karma :key', :defaults => {:key => false}
-    #   # match 'karma for something' and call my karma() method
-    #   plugin.map 'karma for :key'
+    #   # match 'pointstats' and call my stats() method
+    #   plugin.map 'pointstats', :action => 'stats'
+    #   # match 'points' with an optional 'key' and call my points() method
+    #   plugin.map 'points :key', :defaults => {:key => false}
+    #   # match 'points for something' and call my points() method
+    #   plugin.map 'points for :key'
     #
     #   # two matches, one for public messages in a channel, one for
     #   # private messages which therefore require a channel argument
index e40cfcc445a9a03abd46f24699e3e410d2dfbbc9..0e7e9d6f4a4163465aa6a2df810b913554d2198d 100644 (file)
@@ -38,36 +38,36 @@ module Plugins
 
      Examples:
 
-       plugin.map 'karmastats', :action => 'karma_stats'
+       plugin.map 'pointstats', :action => 'point_stats'
 
        # while in the plugin...
-       def karma_stats(m, params)
+       def point_stats(m, params)
          m.reply "..."
        end
 
        # the default action is the first component
-       plugin.map 'karma'
+       plugin.map 'points'
 
        # attributes can be pulled out of the match string
-       plugin.map 'karma for :key'
-       plugin.map 'karma :key'
+       plugin.map 'points for :key'
+       plugin.map 'points :key'
 
        # while in the plugin...
-       def karma(m, params)
+       def points(m, params)
          item = params[:key]
-         m.reply 'karma for #{item}'
+         m.reply 'points for #{item}'
        end
 
        # you can setup defaults, to make parameters optional
-       plugin.map 'karma :key', :defaults => {:key => 'defaultvalue'}
+       plugin.map 'points :key', :defaults => {:key => 'defaultvalue'}
 
        # the default auth check is also against the first component
        # but that can be changed
-       plugin.map 'karmastats', :auth => 'karma'
+       plugin.map 'pointstats', :auth => 'points'
 
        # maps can be restricted to public or private message:
-       plugin.map 'karmastats', :private => false
-       plugin.map 'karmastats', :public => false
+       plugin.map 'pointstats', :private => false
+       plugin.map 'pointstats', :public => false
 
      See MessageMapper#map for more information on the template format and the
      allowed options.
diff --git a/po/en/rbot-karma.po b/po/en/rbot-karma.po
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/po/en/rbot-points.po b/po/en/rbot-points.po
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/po/fi/rbot-karma.po b/po/fi/rbot-karma.po
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/po/fi/rbot-points.po b/po/fi/rbot-points.po
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/po/fr/rbot-karma.po b/po/fr/rbot-karma.po
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/po/fr/rbot-points.po b/po/fr/rbot-points.po
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/po/it/rbot-karma.po b/po/it/rbot-karma.po
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/po/it/rbot-points.po b/po/it/rbot-points.po
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/po/ja/rbot-karma.po b/po/ja/rbot-karma.po
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/po/ja/rbot-points.po b/po/ja/rbot-points.po
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/po/rbot-karma.pot b/po/rbot-karma.pot
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/po/rbot-points.pot b/po/rbot-points.pot
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/po/zh_CN/rbot-karma.po b/po/zh_CN/rbot-karma.po
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/po/zh_CN/rbot-points.po b/po/zh_CN/rbot-points.po
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/po/zh_TW/rbot-karma.po b/po/zh_TW/rbot-karma.po
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/po/zh_TW/rbot-points.po b/po/zh_TW/rbot-points.po
new file mode 100644 (file)
index 0000000..e69de29