<commit_before>from lrrbot import bot
from config import config
import storage
import random
import utils
import re

def generate_docstring():
	inverse_responses = {}
	for command, response in storage.data["responses"].items():
		if isinstance(response, (tuple, list)):
			response = tuple(response)
		inverse_responses.setdefault(response, [])
		inverse_responses[response] += [command]
	def generator():
		for response, command in inverse_responses.items():
			fragment = ""
			if isinstance(command, list):
				for cmd in command:
					fragment += "Command: %s%s\n" % (config["commandprefix"], cmd)
			else:
				fragment += "Command: %s%s\n" % (config["commandprefix"], cmd)
			fragment += "Throttled: 5\n"
			fragment += "Literal-Response: true\n"
			fragment += "\n"
			response = response if isinstance(response, str) else random.choice(response)
			fragment += response + "\n"
			yield fragment
	return "\n--command\n".join(generator())

def generate_expression(node):
	return "(%s)" % "|".join(re.escape(c).replace("\\ ", " ") for c in node)

@utils.throttle(5, params=[4])
def static_response(lrrbot, conn, event, respond_to, command):
	if storage.data["subsciption_check"][command.lower()] is True:
		if lrrbot.is_sub(event):
			response = storage.data["responses"][" ".join(command.lower().split())]
			if isinstance(response, (tuple, list)):
				response = random.choice(response)
			conn.privmsg(respond_to, response)
		else:
			return
	else:
		response = storage.data["responses"][" ".join(command.lower().split())]
		if isinstance(response, (tuple, list)):
			response = random.choice(response)
		conn.privmsg(respond_to, response)

def modify_commands(commands):
    bot.remove_command(generate_expression(storage.data["responses"]))
    storage.data["responses"] = {" ".join(k.lower().split()): v for k,v in commands.items()}
    storage.save()
    static_response.__doc__ = generate_docstring()<commit_msg>New format<commit_after>from lrrbot import bot
from config import config
import storage
import random
import utils
import re

def generate_docstring():
	inverse_responses = {}
	for command, response in storage.data["responses"].items():
		if isinstance(response, (tuple, list)):
			response = tuple(response)
		inverse_responses.setdefault(response, [])
		inverse_responses[response] += [command]
	def generator():
		for response, command in inverse_responses.items():
			fragment = ""
			if isinstance(command, list):
				for cmd in command:
					fragment += "Command: %s%s\n" % (config["commandprefix"], cmd)
			else:
				fragment += "Command: %s%s\n" % (config["commandprefix"], cmd)
			fragment += "Throttled: 5\n"
			fragment += "Literal-Response: true\n"
			fragment += "\n"
			response = response if isinstance(response, str) else random.choice(response)
			fragment += response + "\n"
			yield fragment
	return "\n--command\n".join(generator())

def generate_expression(node):
	return "(%s)" % "|".join(re.escape(c).replace("\\ ", " ") for c in node)

@utils.throttle(5, params=[4])
def static_response(lrrbot, conn, event, respond_to, command):
	if storage.data["response"][command.lower()]["access"] is "sub":
		if lrrbot.is_sub(event) or lrrbot.is_mod(event):
			response = storage.data["responses"][" ".join(command.lower().split())]
			if isinstance(response, (tuple, list)):
				response = random.choice(response)
			conn.privmsg(respond_to, response)
		else:
			return
	else:
		response = storage.data["responses"][" ".join(command.lower().split())]
		if isinstance(response, (tuple, list)):
			response = random.choice(response)
		conn.privmsg(respond_to, response)

def modify_commands(commands):
    bot.remove_command(generate_expression(storage.data["responses"]))
    storage.data["responses"] = {" ".join(k.lower().split()): v for k,v in commands.items()}
    storage.save()
    static_response.__doc__ = generate_docstring()
{'fraction_non_alphanumeric': 0.15939033841384656, 'fraction_numerical': 0.0015499870834409714, 'mean_word_length': 4.947772657450077, 'pattern_counts': {'":': 1, '<': 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': '3578913', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1208, 'n_words': 286}