<commit_before>require 'cinch'
require 'plugin_helpers'
require 'sqlite3'

class Leaderboard
  include Cinch::Plugin, SlackCat::PluginHelpers

  match /(troll) (.*)?/i, prefix: ".", method: :modify_leaderboard
  match /(trolls)/i, prefix: ".", method: :leaderboard

  match /(pluses)/i, prefix: ".", method: :leaderboard
  match /(leaderboard)/i, prefix: ".", method: :leaderboard

  match /(increment) (.*)?/i, prefix: ".", method: :modify_leaderboard
  match /(plus) (.*)?/i, prefix: ".", method: :modify_leaderboad

  match /(decrement) (.*)?/i, prefix: ".", method: :modify_leaderboad
  match /(minus) (.*)?/i, prefix: ".", method: :modify_leaderboard

  match /^([a-zA-Z\.]+)(\+\+)$/, use_prefix: false, method: :modify_leaderboard
  match /^([a-zA-Z\.]+)(--)$/, use_prefix: false, method: :modify_leaderboard

  match /^(\+\+)([a-zA-Z\.]+)$/, use_prefix: false, method: :modify_leaderboard
  match /^(--)([a-zA-Z\.]+)$/, use_prefix: false, method: :modify_leaderboard

  def get_table_name(command)
    # Create hash with default table to pluses then add ones that are different
    tables = Hash.new("pluses")
    tables["troll"] = "trolls"
    tables[command.to_s]
  end

  def get_sign(command)
    decrement_commands = ["--", "decrement", "minus"]
    decrement_commands.include?(command.to_s) ? "-" : "+"
  end

  def modify_leaderboard(memo, first_match, second_match)
    # Check if we are pre or post increment and swap if needed
    if (second_match.to_s == "++" || second_match.to_s == "--")
      first_match, second_match = second_match, first_match
    end

    # Name these variables something sane
    command, nick = first_match, second_match

    table = get_table_name(command)
    sign = get_sign(command)

    db = SQLite3::Database.new "pluses.db"
    if (nick != "") 
      if (nick.to_s == memo.user.to_s)
        memo.reply "Nice try!"
      else
        db.execute("INSERT OR IGNORE INTO #{table} VALUES (?, 0)", [nick])<commit_msg>Fixing pre and post increment regexes to handle mid line<commit_after>require 'cinch'
require 'plugin_helpers'
require 'sqlite3'

class Leaderboard
  include Cinch::Plugin, SlackCat::PluginHelpers

  match /(troll) (.*)?/i, prefix: ".", method: :modify_leaderboard
  match /(trolls)/i, prefix: ".", method: :leaderboard

  match /(pluses)/i, prefix: ".", method: :leaderboard
  match /(leaderboard)/i, prefix: ".", method: :leaderboard

  match /(increment) (.*)?/i, prefix: ".", method: :modify_leaderboard
  match /(plus) (.*)?/i, prefix: ".", method: :modify_leaderboad

  match /(decrement) (.*)?/i, prefix: ".", method: :modify_leaderboad
  match /(minus) (.*)?/i, prefix: ".", method: :modify_leaderboard

  match /([a-zA-Z\.]+)(\+\+)/, use_prefix: false, method: :modify_leaderboard
  match /([a-zA-Z\.]+)(--)/, use_prefix: false, method: :modify_leaderboard

  match /(\+\+)([a-zA-Z\.]+)/, use_prefix: false, method: :modify_leaderboard
  match /(--)([a-zA-Z\.]+)/, use_prefix: false, method: :modify_leaderboard

  def get_table_name(command)
    # Create hash with default table to pluses then add ones that are different
    tables = Hash.new("pluses")
    tables["troll"] = "trolls"
    tables[command.to_s]
  end

  def get_sign(command)
    decrement_commands = ["--", "decrement", "minus"]
    decrement_commands.include?(command.to_s) ? "-" : "+"
  end

  def modify_leaderboard(memo, first_match, second_match)
    # Check if we are pre or post increment and swap if needed
    if (second_match.to_s == "++" || second_match.to_s == "--")
      first_match, second_match = second_match, first_match
    end

    # Name these variables something sane
    command, nick = first_match, second_match

    table = get_table_name(command)
    sign = get_sign(command)

    db = SQLite3::Database.new "pluses.db"
    if (nick != "") 
      if (nick.to_s == memo.user.to_s)
        memo.reply "Nice try!"
      else
        db.execute("INSERT OR IGNORE INTO #{table} VALUES (?, 0)", [nick])
{'fraction_non_alphanumeric': 0.17419843473870233, 'fraction_numerical': 0.0015147689977278464, 'mean_word_length': 3.6611764705882353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '763260', 'n_tokens_mistral': 1456, 'n_tokens_neox': 1376, 'n_words': 338}