<commit_before>require 'json'
require 'redis'
require 'sequel'

module Bot
  module Events
    # event logs every message and deletes them 5 hours later
    # event also manages leveling system
    module UserPost
      extend Discordrb::EventContainer
      message do |event|
        redis = Redis.new

        if Bot::JADE.profile.on(event.server).permission?(:manage_server) && Bot::JADE.profile.on(event.server).permission?(:manage_channels)
          message_hash = { user: event.message.user.username, tag: event.message.user.tag, message: event.message.content, avatar: event.message.user.avatar_url }
          redis.set event.message.id, message_hash.to_json
          redis.expire(event.message.id, 180_000) # in seconds, equal to a
          # little more than 41 hours
        end

        if Bot::JADE.profile.on(event.server).permission?(:use_voice_activity)
          levels = Bot::DB[:levels].where(user_id: event.message.user.id, server_id: event.server.id)

          if levels.empty?
            levels.insert(user_id: event.message.user.id, server_id: event.server.id, level: 1, xp: 0, to_next_level: 100)

          elsif redis.get("#{event.message.user.id}:#{event.server.id}:level_lock").nil?
            user_level = levels.get(:level)
            user_xp = levels.get(:xp)
            user_next = levels.get(:to_next_level)

            user_xp += rand(10..29)

            if user_xp >= user_next
              user_next += user_next
              user_level += 1
              event.send_message("Level up!\n#{event.message.user.display_name} is now **Level #{user_level}**")
            end
            levels.update(level: user_level, xp: user_xp, to_next_level: user_next)
            redis.set "#{event.message.user.id}:#{event.server.id}:level_lock", true
            redis.expire("#{event.message.user.id}:#{event.server.id}:level_lock", 30)
          end<commit_msg>incredibly slight modification to XP gain.<commit_after>require 'json'
require 'redis'
require 'sequel'

module Bot
  module Events
    # event logs every message and deletes them 5 hours later
    # event also manages leveling system
    module UserPost
      extend Discordrb::EventContainer
      message do |event|
        redis = Redis.new

        if Bot::JADE.profile.on(event.server).permission?(:manage_server) && Bot::JADE.profile.on(event.server).permission?(:manage_channels)
          message_hash = { user: event.message.user.username, tag: event.message.user.tag, message: event.message.content, avatar: event.message.user.avatar_url }
          redis.set event.message.id, message_hash.to_json
          redis.expire(event.message.id, 180_000) # in seconds, equal to a
          # little more than 41 hours
        end

        if Bot::JADE.profile.on(event.server).permission?(:use_voice_activity)
          levels = Bot::DB[:levels].where(user_id: event.message.user.id, server_id: event.server.id)

          if levels.empty?
            levels.insert(user_id: event.message.user.id, server_id: event.server.id, level: 1, xp: 0, to_next_level: 100)

          elsif redis.get("#{event.message.user.id}:#{event.server.id}:level_lock").nil?
            user_level = levels.get(:level)
            user_xp = levels.get(:xp)
            user_next = levels.get(:to_next_level)

            user_xp += rand(10..31)

            if user_xp >= user_next
              user_next += user_next
              user_level += 1
              event.send_message("Level up!\n#{event.message.user.display_name} is now **Level #{user_level}**")
            end
            levels.update(level: user_level, xp: user_xp, to_next_level: user_next)
            redis.set "#{event.message.user.id}:#{event.server.id}:level_lock", true
            redis.expire("#{event.message.user.id}:#{event.server.id}:level_lock", 30)
          end
{'fraction_non_alphanumeric': 0.12398851474810754, 'fraction_numerical': 0.01096319498825372, 'mean_word_length': 2.7024154589371983, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '795766', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1173, 'n_words': 238}