<commit_before>const moment = require('moment')
const needle = require('needle')
const UserError = require('flying-squid').UserError

module.exports.server = function (serv, settings) {
  serv.ban = async (uuid, reason) => {
    if (!serv.bannedPlayers[uuid]) {
      serv.bannedPlayers[uuid] = {
        time: +moment(),
        reason: reason || 'Your account is banned!'
      }
      return true
    } else return false
  }
  serv.banIP = async (IP, reason) => {
    if (!serv.bannedIPs[IP]) {
      serv.bannedIPs[IP] = {
        time: +moment(),
        reason: reason || 'Your IP is banned!'
      }
      Object.keys(serv.players)
        .filter(uuid => serv.players[uuid]._client.socket.remoteAddress === IP)
        .forEach(uuid => serv.players[uuid].kick(serv.bannedIPs[serv.players[uuid]._client.socket.remoteAddress].reason))
      return true
    } else return false
  }

  function uuidInParts (plainUUID) {
    return plainUUID.length === 32 ? plainUUID.substring(0, 8) + '-' + plainUUID.substring(8, 12) + '-' + plainUUID.substring(12, 16) + '-' + plainUUID.substring(16, 20) + '-' + plainUUID.substring(20) : plainUUID
  }

  serv.getUUIDFromUsername = async username => {
    return await new Promise((resolve, reject) => {
      needle('get', 'https://api.mojang.com/users/profiles/minecraft/' + username, { json: true })
        .then((response) => {
          if (!response.body) throw new Error('username not found')
          const idstr = response.body.id
          if (typeof idstr !== 'string') throw new Error('username not found')
          resolve(uuidInParts(idstr))
        })
        .catch(err => { throw err })
    })
  }

  serv.banUsername = async (username, reason) => {
    return serv.ban(username, reason)
  }

  serv.banUUID = async (username, reason) => {
    return serv.getUUIDFromUsername(username).then(uuid => serv.ban(uuid, reason))
  }

  serv.pardonUsername = async (username) => {
    return pardon(username)
  }

  serv.pardonUUID = async (username) => {
    return serv.getUUIDFromUsername(username)
      .then(pardon)
  }

  serv.pardonIP = async (IP) => {
    return serv.bannedIPs[IP] ? delete serv.bannedIPs[IP] : false
  }

  function pardon (uuid) {
    if (serv.bannedPlayers[uuid]) {
      delete serv.bannedPlayers[uuid]
      return true
    }
    return false
  }

  serv.bannedPlayers = {}
  serv.bannedIPs = {}

  serv.commands.add({
    base: 'op',
    info: 'Op a player',
    usage: '/op <player>',
    op: true,
    parse (params) {
      if (!params.match(/([a-zA-Z0-9_]+)/)) return false
      return params
    },
    action (params) {
      params = params.split(' ')
      const player = serv.getPlayer(params[0])
      if (player === undefined || player === null) {
        const arr = serv.selectorString(params)
        if (arr.length === 0) throw new UserError('Could not find player')

        arr.map(entity => {
          entity.op = true
          return `Opped ${entity}`
        })
      } else {
        if (!player.op) {
          player.op = true

          player.chat(`§7§o[Server: Opped ${params[0]}]`)
          return `Opped ${params[0]}`
        } else {
          return `${params[0]} is opped already`
        }
      }
    }
  })

  serv.commands.add({
    base: 'deop',
    info: 'Deop a player',
    usage: '/deop <player>',<commit_msg>Commands(OP): Make player non-case-sensitive (#596)<commit_after>const moment = require('moment')
const needle = require('needle')
const UserError = require('flying-squid').UserError

module.exports.server = function (serv, settings) {
  serv.ban = async (uuid, reason) => {
    if (!serv.bannedPlayers[uuid]) {
      serv.bannedPlayers[uuid] = {
        time: +moment(),
        reason: reason || 'Your account is banned!'
      }
      return true
    } else return false
  }
  serv.banIP = async (IP, reason) => {
    if (!serv.bannedIPs[IP]) {
      serv.bannedIPs[IP] = {
        time: +moment(),
        reason: reason || 'Your IP is banned!'
      }
      Object.keys(serv.players)
        .filter(uuid => serv.players[uuid]._client.socket.remoteAddress === IP)
        .forEach(uuid => serv.players[uuid].kick(serv.bannedIPs[serv.players[uuid]._client.socket.remoteAddress].reason))
      return true
    } else return false
  }

  function uuidInParts (plainUUID) {
    return plainUUID.length === 32 ? plainUUID.substring(0, 8) + '-' + plainUUID.substring(8, 12) + '-' + plainUUID.substring(12, 16) + '-' + plainUUID.substring(16, 20) + '-' + plainUUID.substring(20) : plainUUID
  }

  serv.getUUIDFromUsername = async username => {
    return await new Promise((resolve, reject) => {
      needle('get', 'https://api.mojang.com/users/profiles/minecraft/' + username, { json: true })
        .then((response) => {
          if (!response.body) throw new Error('username not found')
          const idstr = response.body.id
          if (typeof idstr !== 'string') throw new Error('username not found')
          resolve(uuidInParts(idstr))
        })
        .catch(err => { throw err })
    })
  }

  serv.banUsername = async (username, reason) => {
    return serv.ban(username, reason)
  }

  serv.banUUID = async (username, reason) => {
    return serv.getUUIDFromUsername(username).then(uuid => serv.ban(uuid, reason))
  }

  serv.pardonUsername = async (username) => {
    return pardon(username)
  }

  serv.pardonUUID = async (username) => {
    return serv.getUUIDFromUsername(username)
      .then(pardon)
  }

  serv.pardonIP = async (IP) => {
    return serv.bannedIPs[IP] ? delete serv.bannedIPs[IP] : false
  }

  function pardon (uuid) {
    if (serv.bannedPlayers[uuid]) {
      delete serv.bannedPlayers[uuid]
      return true
    }
    return false
  }

  serv.bannedPlayers = {}
  serv.bannedIPs = {}

  serv.commands.add({
    base: 'op',
    info: 'Op a player',
    usage: '/op <player>',
    op: true,
    parse (params) {
      if (!params.match(/([a-zA-Z0-9_]+)/)) return false
      return params
    },
    action (params) {
      const [inputUsername] = params.split(' ')
      // get player, by non-case-sensitive username
      const player = serv.players.find(player => player.username.toLowerCase() === inputUsername.toLowerCase())
      if (player === undefined || player === null) {
        const arr = serv.selectorString(params)
        if (arr.length === 0) throw new UserError('Could not find player')

        arr.map(entity => {
          entity.op = true
          return `Opped ${entity}`
        })
      } else {
        if (!player.op) {
          player.op = true

          player.chat(`§7§o[${player.username ?? 'Server'}: Opped ${player.username}]`)
          return `Opped ${player.username}`
        } else {
          return `${player.username} is opped already`
        }
      }
    }
  })

  serv.commands.add({
    base: 'deop',
    info: 'Deop a player',
    usage: '/deop <player>',
{'fraction_non_alphanumeric': 0.15457184325108853, 'fraction_numerical': 0.007111756168359942, 'mean_word_length': 2.5667701863354035, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 38, 'https://': 2, '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': '6620215', 'n_tokens_mistral': 2223, 'n_tokens_neox': 2192, 'n_words': 484}