<commit_before>import simplejson as json
from time import time
from helpers import *
from random import randrange

lol_filename = "plugins/redstoner-utils.py.dir/files/lol.json"
lols         = []
timeout      = 15
last_msg     = 0

try:
  lols = json.loads(open(lol_filename).read())
except Exception, e:
  error("Failed to load lols: %s" % e)



def save_lols():
  try:
    lolfile = open(lol_filename, "w")
    lolfile.write(json.dumps(lols))
    lolfile.close()
  except Exception, e:
    error("Failed to write lols: " + str(e))

def add_lol(txt):
  lols.append(txt)
  save_lols()

def del_lol(lid):
  lols.pop(lid)
  save_lols()

def print_lol(sender, lid):
  global last_msg
  if time() - last_msg > timeout:
    dispname = sender.getDisplayName() if isPlayer(sender) else sender.getName()
    broadcast("", "&8[&blol&8] &7%s&8: &e%s" % (dispname, lols[lid]))
    last_msg = time()
  else:
    plugHeader(sender, "SayLol")
    msg(sender, "&cYou can use SayLol again in &a%s seconds!" % int(timeout + 1 - (time() - last_msg)))


@hook.command("lol")
def onLolCommand(sender, args):
  cmd = args[0] if len(args) > 0 else None
  if len(args) == 0:
    if sender.hasPermission("utils.lol"):
      print_lol(sender, randrange(len(lols)))
    else:
      noperm(sender)

  elif cmd == "id":
    if sender.hasPermission("utils.lol.id"):
      try:
        i = int(args[1])
        print_lol(sender, i)
      except ValueError:
        plugHeader(sender, "SayLol")
        msg(sender, "&cInvalid number '&e%s&c'" % args[1])
    else:
      noperm(sender)<commit_msg>fix out of range /lol id<commit_after>import simplejson as json
from time import time
from helpers import *
from random import randrange

lol_filename = "plugins/redstoner-utils.py.dir/files/lol.json"
lols         = []
timeout      = 15
last_msg     = 0

try:
  lols = json.loads(open(lol_filename).read())
except Exception, e:
  error("Failed to load lols: %s" % e)



def save_lols():
  try:
    lolfile = open(lol_filename, "w")
    lolfile.write(json.dumps(lols))
    lolfile.close()
  except Exception, e:
    error("Failed to write lols: " + str(e))

def add_lol(txt):
  lols.append(txt)
  save_lols()

def del_lol(lid):
  lols.pop(lid)
  save_lols()

def print_lol(sender, lid):
  global last_msg
  if time() - last_msg > timeout:
    if len(lols) > lid:
      dispname = sender.getDisplayName() if isPlayer(sender) else sender.getName()
      broadcast("", "&8[&blol&8] &7%s&8: &e%s" % (dispname, lols[lid]))
      last_msg = time()
    else:
      plugHeader(sender, "SayLol")
      msg(sender, "&cInvalid id")
  else:
    plugHeader(sender, "SayLol")
    msg(sender, "&cYou can use SayLol again in &a%s seconds!" % int(timeout + 1 - (time() - last_msg)))


@hook.command("lol")
def onLolCommand(sender, args):
  cmd = args[0] if len(args) > 0 else None
  if len(args) == 0:
    if sender.hasPermission("utils.lol"):
      print_lol(sender, randrange(len(lols)))
    else:
      noperm(sender)

  elif cmd == "id":
    if sender.hasPermission("utils.lol.id"):
      try:
        i = int(args[1])
        print_lol(sender, i)
      except ValueError:
        plugHeader(sender, "SayLol")
        msg(sender, "&cInvalid number '&e%s&c'" % args[1])
    else:
      noperm(sender)
{'fraction_non_alphanumeric': 0.15046153846153845, 'fraction_numerical': 0.008, 'mean_word_length': 3.2832674571805005, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 8, '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': '5843613', 'n_tokens_mistral': 1248, 'n_tokens_neox': 1233, 'n_words': 289}