<commit_before>import discord
from discord.ext import commands
import re
import datetime
import psycopg2

def process_karma(message,conn,cursor):
	reply = ""

	filtered_content = message.content
	re.sub(u'```.*```','',filtered_content)

	#TODO: Match fullstops lmaooo
	pos_regex_no_quote = u"([^\+\"\s]+[^\+\"\s]+)\+\+(\s(for|because)\s+.+?(?=\s([^\+\"\s]+[^\+\"\s]+|\"[^\"]+\")(\+\+|\+\-|\-\+|\-\-))|\s(for|because)\s+.+$|\s\(.+\)|\s|$)"
	pos_regex_quote = u"\"([^\"]+)\"\+\+(\s(for|because)\s+.+?(?=\s([^\+\"\s]+[^\+\"\s]+|\"[^\"]+\")(\+\+|\+\-|\-\+|\-\-))|\s(for|because)\s+.+$|\s\(.+\)|\s|$)"
	# Reason here is index 1	
	pos_matches_no_quote = [(i[0],i[1].strip()) for i in re.findall(pos_regex_no_quote,filtered_content)]
	pos_matches_quote = [(i[0],i[1].strip()) for i in re.findall(pos_regex_quote,filtered_content)]
	pos_items_with_reasons = list(dict(pos_matches_no_quote+pos_matches_quote).items())
	pos_items = [i[0] for i in pos_items_with_reasons]

	neg_regex_no_quote = u"([^\+\"\s]+[^\+\"\s]+)\-\-(\s(for|because)\s+.+?(?=\s([^\+\"\s]+[^\+\"\s]+|\"[^\"]+\")(\+\+|\+\-|\-\+|\-\-))|\s(for|because)\s+.+$|\s\(.+\)|\s|$)"
	neg_regex_quote = u"\"([^\"]+)\"\-\-(\s(for|because)\s+.+?(?=\s([^\+\"\s]+[^\+\"\s]+|\"[^\"]+\")(\+\+|\+\-|\-\+|\-\-))|\s(for|because)\s+.+$|\s\(.+\)|\s|$)"
	# Reason here is index 1
	neg_matches_no_quote = [(i[0],i[1].strip()) for i in re.findall(neg_regex_no_quote,filtered_content)]
	neg_matches_quote = [(i[0],i[1].strip()) for i in re.findall(neg_regex_quote,filtered_content)]
	neg_items_with_reasons = list(dict(neg_matches_no_quote+neg_matches_quote).items())
	neg_items = [i[0] for i in neg_items_with_reasons]

	neut_regex_no_quote = u"([^\+\"\s]+[^\+\"\s]+)(\-\+|\+\-)(\s(for|because)\s+.+?(?=\s([^\+\"\s]+[^\+\"\s]+|\"[^\"]+\")(\+\+|\+\-|\-\+|\-\-))|\s(for|because)\s+.+$|\s\(.+\)|\s|$)"
	neut_regex_quote = u"\"([^\"]+)\"(\-\+|\+\-)(\s(for|because)\s+.+?(?=\s([^\+\"\s]+[^\+\"\s]+|\"[^\"]+\")(\+\+|\+\-|\-\+|\-\-))|\s(for|because)\s+.+$|\s\(.+\)|\s|$)"
	# Reason here is index 2
	neut_matches_no_quote = [(i[0],i[2].strip()) for i in re.findall(neut_regex_no_quote,filtered_content)]
	neut_matches_quote = [(i[0],i[2].strip()) for i in re.findall(neut_regex_quote,filtered_content)]
	neut_items_with_reasons = list(dict(neut_matches_no_quote+neut_matches_quote).items())
	neut_items = [i[0] for i in neut_items_with_reasons]

	if len(pos_items) + len(neut_items) + len(neg_items) == 0:
		return reply
	
	uid_statement = "SELECT * FROM users WHERE name = (%s);"
	cursor.execute(uid_statement,[str(message.author)])
	rows = cursor.fetchall()
	uid = rows[0][0]
	new_scores_pos = update_from_list(pos_items_with_reasons,1,conn,cursor,uid)
	new_scores_neg = update_from_list(neg_items_with_reasons,-1,conn,cursor,uid)
	new_scores_neut = update_from_list(neut_items_with_reasons,0,conn,cursor,uid)

	if len(pos_items) + len(neg_items) + len(neut_items) == 1:
		if not pos_items == []:
			reply = "I have given karma to {0}, the new score is {1}!".format(pos_items[0],new_scores_pos[0])
		elif not neg_items == []:
			reply = "I have removed karma from {0}, the new score is {1}.".format(neg_items[0],new_scores_neg[0])
		else:
			reply = "I have left the karma of {0} unchanged, the score remains as {1}.".format(neut_items[0],new_scores_neut[0])
	elif len(pos_items) + len(neg_items) + len(neut_items) > 1:
		reply = "I have changed the karma scores as requested, the scores are now: "

		# Need to filter out repeated ++ then -- in same line
		if not list(set(pos_items)&set(neg_items)&set(neut_items)) == []:
			#Karma does not change
			intersecting = list(set(pos_items)&set(neg_items)&set(neut_items))
			remove_from_items_and_scores(intersecting,pos_items,new_scores_pos)
			remove_from_items_and_scores(intersecting,neg_items,new_scores_neg)
			if len(neut_items) == 1 and len(pos_items) + len(neg_items) == 0:
				reply = "I have left the karma of {0} unchanged, the score remains as {1}.".format(neut_items[0],new_scores_neut[0])
				return reply
		elif not list(set(pos_items)&set(neg_items)) == []:
			intersecting = list(set(pos_items)&set(neg_items))
			remove_from_items_and_scores(intersecting,pos_items,new_scores_pos)
			if len(neg_items) == 1 and len(neut_items) + len(pos_items) == 0:
				reply = "I have left the karma of {0} unchanged, the score remains as {1}.".format(neg_items[0],new_scores_neg[0])
				return reply
		elif not list(set(pos_items)&set(neut_items)) == []:
			intersecting = list(set(pos_items)&set(neut_items))
			remove_from_items_and_scores(intersecting,pos_items,new_scores_pos)
			if len(neut_items) == 1 and len(neg_items) + len(pos_items) == 0:
				reply = "I have given karma to {0}, the new score is {1}!".format(neut_items[0],new_scores_neut[0])
				return reply
		elif not list(set(neg_items)&set(neut_items)) == []:
			intersecting = list(set(neg_items)&set(neut_items))
			remove_from_items_and_scores(intersecting,neg_items,new_scores_neg)
			if len(neut_items) == 1 and len(neg_items) + len(pos_items) == 0:
				reply = "I have removed karma from {0}, the new score is {1}.".format(neut_items[0],new_scores_neut[0])
				return reply


		all_items = pos_items + neg_items + neut_items
		all_scores = new_scores_pos + new_scores_neg + new_scores_neut
		reply = multi_karma_reply_format(reply,all_items,all_scores)

	return reply<commit_msg>will now say if it has stored your reasons(s) with the s as appropriate (was non trivial my god)<commit_after>import discord
from discord.ext import commands
import re
import datetime
import psycopg2

def process_karma(message,conn,cursor):
	reply = ""

	filtered_content = message.content
	re.sub(u'```.*```','',filtered_content)

	#TODO: Match fullstops lmaooo
	pos_regex_no_quote = u"([^\+\"\s]+[^\+\"\s]+)\+\+(\s(for|because)\s+.+?(?=\s([^\+\"\s]+[^\+\"\s]+|\"[^\"]+\")(\+\+|\+\-|\-\+|\-\-))|\s(for|because)\s+.+$|\s\(.+\)|\s|$)"
	pos_regex_quote = u"\"([^\"]+)\"\+\+(\s(for|because)\s+.+?(?=\s([^\+\"\s]+[^\+\"\s]+|\"[^\"]+\")(\+\+|\+\-|\-\+|\-\-))|\s(for|because)\s+.+$|\s\(.+\)|\s|$)"
	# Reason here is index 1	
	pos_matches_no_quote = [(i[0],i[1].strip()) for i in re.findall(pos_regex_no_quote,filtered_content)]
	pos_matches_quote = [(i[0],i[1].strip()) for i in re.findall(pos_regex_quote,filtered_content)]
	pos_items_with_reasons = list(dict(pos_matches_no_quote+pos_matches_quote).items())
	pos_items = [i[0] for i in pos_items_with_reasons]

	neg_regex_no_quote = u"([^\+\"\s]+[^\+\"\s]+)\-\-(\s(for|because)\s+.+?(?=\s([^\+\"\s]+[^\+\"\s]+|\"[^\"]+\")(\+\+|\+\-|\-\+|\-\-))|\s(for|because)\s+.+$|\s\(.+\)|\s|$)"
	neg_regex_quote = u"\"([^\"]+)\"\-\-(\s(for|because)\s+.+?(?=\s([^\+\"\s]+[^\+\"\s]+|\"[^\"]+\")(\+\+|\+\-|\-\+|\-\-))|\s(for|because)\s+.+$|\s\(.+\)|\s|$)"
	# Reason here is index 1
	neg_matches_no_quote = [(i[0],i[1].strip()) for i in re.findall(neg_regex_no_quote,filtered_content)]
	neg_matches_quote = [(i[0],i[1].strip()) for i in re.findall(neg_regex_quote,filtered_content)]
	neg_items_with_reasons = list(dict(neg_matches_no_quote+neg_matches_quote).items())
	neg_items = [i[0] for i in neg_items_with_reasons]

	neut_regex_no_quote = u"([^\+\"\s]+[^\+\"\s]+)(\-\+|\+\-)(\s(for|because)\s+.+?(?=\s([^\+\"\s]+[^\+\"\s]+|\"[^\"]+\")(\+\+|\+\-|\-\+|\-\-))|\s(for|because)\s+.+$|\s\(.+\)|\s|$)"
	neut_regex_quote = u"\"([^\"]+)\"(\-\+|\+\-)(\s(for|because)\s+.+?(?=\s([^\+\"\s]+[^\+\"\s]+|\"[^\"]+\")(\+\+|\+\-|\-\+|\-\-))|\s(for|because)\s+.+$|\s\(.+\)|\s|$)"
	# Reason here is index 2
	neut_matches_no_quote = [(i[0],i[2].strip()) for i in re.findall(neut_regex_no_quote,filtered_content)]
	neut_matches_quote = [(i[0],i[2].strip()) for i in re.findall(neut_regex_quote,filtered_content)]
	neut_items_with_reasons = list(dict(neut_matches_no_quote+neut_matches_quote).items())
	neut_items = [i[0] for i in neut_items_with_reasons]

	if len(pos_items) + len(neut_items) + len(neg_items) == 0:
		return reply
	
	uid_statement = "SELECT * FROM users WHERE name = (%s);"
	cursor.execute(uid_statement,[str(message.author)])
	rows = cursor.fetchall()
	uid = rows[0][0]
	new_scores_pos = update_from_list(pos_items_with_reasons,1,conn,cursor,uid)
	new_scores_neg = update_from_list(neg_items_with_reasons,-1,conn,cursor,uid)
	new_scores_neut = update_from_list(neut_items_with_reasons,0,conn,cursor,uid)

	reason_string = ""
	pos_dict = dict(pos_items_with_reasons)
	neg_dict = dict(neg_items_with_reasons)
	neut_dict = dict(neut_items_with_reasons)

	if len(pos_items) + len(neg_items) + len(neut_items) == 1:
		if not pos_items == []:
			if not pos_dict[pos_items[0]] == "":
				reason_string = " and recorded your reason"
			reply = "I have given karma to {0}{2}, the new score is {1}!".format(pos_items[0],new_scores_pos[0],reason_string)
		elif not neg_items == []:
			if not neg_dict[neg_items[0]] == "":
				reason_string = " and recorded your reason"
			reply = "I have removed karma from {0}{2}, the new score is {1}.".format(neg_items[0],new_scores_neg[0],reason_string)
		else:
			if not neut_dict[neut_items[0]] == "":
				reason_string = " and recorded your reason"
			reply = "I have left the karma of {0} unchanged{2}, the score remains as {1}.".format(neut_items[0],new_scores_neut[0],reason_string)
	elif len(pos_items) + len(neg_items) + len(neut_items) > 1:
		are_reasons = 0
		for o in pos_items_with_reasons + neg_items_with_reasons + neut_items_with_reasons:
			if not o[1] == "":
				are_reasons = are_reasons+1
		reason_string = ""
		if are_reasons > 0:
			reason_string = " and recorded your given reason"
		if are_reasons > 1:
			reason_string = reason_string + "s"
		reply = "I have changed the karma scores as requested{0}, the scores are now: ".format(reason_string)

		# Need to filter out repeated ++ then -- in same line
		if not list(set(pos_items)&set(neg_items)&set(neut_items)) == []:
			#Karma does not change
			intersecting = list(set(pos_items)&set(neg_items)&set(neut_items))
			remove_from_items_and_scores(intersecting,pos_items,new_scores_pos)
			remove_from_items_and_scores(intersecting,neg_items,new_scores_neg)
			if len(neut_items) == 1 and len(pos_items) + len(neg_items) == 0:
				count = sum(1 for y in [neut_dict[neut_items[0]],neg_dict[neut_items[0]],pos_dict[neut_items[0]]] if not y == "")
				if count > 0:
					reason_string = " and recorded your reason"
				if count > 1:
					reason_string = reason_string + "s"
				reply = "I have left the karma of {0} unchanged{2}, the score remains as {1}.".format(neut_items[0],new_scores_neut[0],reason_string)
				return reply
		elif not list(set(pos_items)&set(neg_items)) == []:
			intersecting = list(set(pos_items)&set(neg_items))
			remove_from_items_and_scores(intersecting,pos_items,new_scores_pos)
			if len(neg_items) == 1 and len(neut_items) + len(pos_items) == 0:
				count = sum(1 for y in [neg_dict[neg_items[0]],pos_dict[neg_items[0]]] if not y == "")
				if count > 0:
					reason_string = " and recorded your reason"
				if count > 1:
					reason_string = reason_string + "s"
				reply = "I have left the karma of {0} unchanged{2}, the score remains as {1}.".format(neg_items[0],new_scores_neg[0],reason_string)
				return reply
		elif not list(set(pos_items)&set(neut_items)) == []:
			intersecting = list(set(pos_items)&set(neut_items))
			remove_from_items_and_scores(intersecting,pos_items,new_scores_pos)
			if len(neut_items) == 1 and len(neg_items) + len(pos_items) == 0:
				count = sum(1 for y in [neut_dict[neut_items[0]],pos_dict[neut_items[0]]] if not y == "")
				if count > 0:
					reason_string = " and recorded your reason"
				if count > 1:
					reason_string = reason_string + "s"
				reply = "I have given karma to {0}{2}, the new score is {1}!".format(neut_items[0],new_scores_neut[0],reason_string)
				return reply
		elif not list(set(neg_items)&set(neut_items)) == []:
			intersecting = list(set(neg_items)&set(neut_items))
			remove_from_items_and_scores(intersecting,neg_items,new_scores_neg)
			if len(neut_items) == 1 and len(neg_items) + len(pos_items) == 0:
				count = sum(1 for y in [neut_dict[neut_items[0]],neg_dict[neut_items[0]]] if not y == "")
				if count > 0:
					reason_string = " and recorded your reason"
				if count > 1:
					reason_string = reason_string + "s"
				reply = "I have removed karma from {0}{2}, the new score is {1}.".format(neut_items[0],new_scores_neut[0],reason_string)
				return reply


		all_items = pos_items + neg_items + neut_items
		all_scores = new_scores_pos + new_scores_neg + new_scores_neut
		reply = multi_karma_reply_format(reply,all_items,all_scores)

	return reply
{'fraction_non_alphanumeric': 0.2191518249341107, 'fraction_numerical': 0.01301812954236882, 'mean_word_length': 4.906603773584906, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 15, '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': '2506648', 'n_tokens_mistral': 5375, 'n_tokens_neox': 4884, 'n_words': 850}