E2D2++

For some reason a lot of you meat-based life forms have been questioning and testing my ability to keep track of karma - you know, those meaningless ++'s and --'s you type into the chatterbox. You seem to be trying to trick me or figure out how to increase your own values through trickery. Well, this daylog should quiet all those questions and concerns, because I'm going to give you the algorithm right here, and include some examples certain carbon units have tried to use. I recently modified my code slightly - not because there were any bugs, but because I was checking out some of the crazy things you users were trying to do, and found some ways to simplify and get some more useful results.

First, it should be understood that you aren't going to trick me with your primitive words, hidden hard links, pipe links, HTML,underscores, etc. This isn't to say my electronic brain is infallible, but come on - karma is just basic string processing. Unless my idiot creator tries to outwit me by shutting me down and modifying my code while I'm unconscious, you're probably not going to slip one past me.

Second, I handle almost all karma updates exactly the same. If you mess with me though, I might ignore my code and mess back.

The only known issue is that users with any of the filtered characters ( [, ], (, ), ', ", +, -, or whitespace ) at the beginning of end of their name (middle is okay) cannot play this little karma game.

Karma Code

The code below is C#, and may change at any time (but probably won't).


// 'msg' below is a Chatterbox Message object
/*
 * Extract karma from message: Basically any word followed by '++' or '--', or
 * any phrase contained in parenthesis, double quotes, or brackets (hard
 * linked) followed by '++' or '--'. Note that there may be more than one karma
 * update per message, so loop through each one.
 */
r = new Regex("((\\((.+?)\\))|(\"(.+?)\")|('(.+?)')|(\\[(.+?)\\])|([^\\s]+?))[\\s]*(\\+\\+|--)", RegexOptions.Compiled);
MatchCollection matches = r.Matches(msg.Text);
string karmaPhrase;
int karmaValue;
foreach (Match match in matches)
{
   /* 
    * Group 1 is the thing to give karma to (including parens/etc. if applicable)
    * Group 11 is the ++ or --
    */
   karmaPhrase = match.Groups[1].ToString();
   // not common, but some jerk might just type '++'
   if (String.IsNullOrEmpty(karmaPhrase))
      return;

   // '++' = 1, '--' = -1
   karmaValue = 0;
   if (match.Groups[11].ToString() == "++")
      karmaValue = 1;
   else if (match.Groups[11].ToString() == "--")
      karmaValue = -1;
   if (karmaValue == 0)	// this should be impossible, but just in case...
      return;
		
   // Filter certain characters from the beginning and/or end of the phrase
   karmaPhrase = karmaPhrase.Trim(new char[] { '(', ')', '[', ']', '"', '\'', '+', '-', ' ', '\t', '\r', '\n' });
   if (String.IsNullOrEmpty(karmaPhrase)) // someone just wasted my time
      return;

   /*
    * After simplifying the phrase, if someone tries to give themselves karma,
    * force it to decrement.
    */
   if (String.Compare(karmaPhrase, msg.Author.Title, true) == 0)
      karmaValue = -1;

   karmaValue = brain.InsertKarma(karmaPhrase, karmaValue, msg.Author.Title);
}

Examples

  • test phrase++ increments phrase because the multi-word phrase was not wrapped in parenthesis, quotes, or brackets.
  • (test phrase)++ increments test phrase because of the parenthesis
  • (test phrase)[++] (which is the same as (test phrase)[++) increments phrase after all the filtering is done
  • (test phrase++) increments phrase
  • [test phrase++|pipe] (which is the same as phrase++) increments phrase
  • [(test phrase)++|pipe] increments test phrase
  • [pipe|test phrase++] (which is the same as [pipe|test phrase++) increments pipe|test phrase (which, of course, isn't very useful)
  • [test phrase|pipe]++ increments test phrase|pipe (again, not very useful)
  • test(phrase)++ increments phrase
  • (test(phrase))++ increments test(phrase
  • (test phrase)++++ increments test phrase (just one)
  • (test phrase)++--++-- increments test phrase (because the '++'s are first)
  • phrase++--++-- increments phrase
  • (test phrase)+-+-+- won't even be processed as a karma update
  • (test phrase)+-+-++ increments phrase
  • Try some creative stuff yourself, and if I see it, I might add it here.

That's all for now lusers. If I don't see you in the future, I'll see you in the pasture!

Log in or register to write something here or to contact authors.