<commit_before>-module(command_lock).
-compile(export_all).

-include("definitions.hrl").

get_commands() ->
	[
		{"start", fun start/1, user},
		{"stop", fun stop/1, user}
	].

start(#{reply:=R, ping:=P, params:=[]}) -> {irc, {msg, {R, [P, "Provide a command to start using!"]}}};
start(#{origin:=O, reply:=R, ping:=P, params:=Params}) ->
	config:set_value(temp, [?MODULE, locked, O], Params),
	{irc, {msg, {R, [P, "Command '", string:join(Params, " "), "' started."]}}}.

handle_event(msg_nocommand, {User, Channel, Tokens}) ->
	case config:get_value(temp, [?MODULE, locked, User]) of
		'$none' -> ok;
		Locked ->
			io:fwrite("~p\n", [Locked ++ Tokens]),
			bot ! {irc, {msg, {User, Channel, Locked ++ Tokens}}}
	end;
handle_event(_, _) -> ok.

stop(#{origin:=O, reply:=R, ping:=P}) ->
	case config:get_value(temp, [?MODULE, locked, O]) of
		'$none' -> {irc, {msg, {R, [P, "You do not have an active command!"]}}};
		Command -><commit_msg>fix an infinite loop issue<commit_after>-module(command_lock).
-compile(export_all).

-include("definitions.hrl").

get_commands() ->
	[
		{"start", fun start/1, user},
		{"stop", fun stop/1, user}
	].

start(#{reply:=R, ping:=P, params:=[]}) -> {irc, {msg, {R, [P, "Provide a command to start using!"]}}};
start(#{origin:=O, reply:=R, ping:=P, params:=Params}) ->
	config:set_value(temp, [?MODULE, locked, O], Params),
	{irc, {msg, {R, [P, "Command '", string:join(Params, " "), "' started."]}}}.

handle_event(msg_nocommand, {User, Channel, Tokens}) ->
	case config:get_value(temp, [?MODULE, locked, User]) of
		'$none' -> ok;
		Locked ->
			case lists:prefix(Locked, Tokens) of
				true -> ok; % the locked command was already prepended!
				false ->
					io:fwrite("~p\n", [Locked ++ Tokens]),
					bot ! {irc, {msg, {User, Channel, Locked ++ Tokens}}}
			end
	end;
handle_event(_, _) -> ok.

stop(#{origin:=O, reply:=R, ping:=P}) ->
	case config:get_value(temp, [?MODULE, locked, O]) of
		'$none' -> {irc, {msg, {R, [P, "You do not have an active command!"]}}};
		Command ->
{'fraction_non_alphanumeric': 0.23899059871350817, 'fraction_numerical': 0.0019792182088075212, 'mean_word_length': 4.524590163934426, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '768963', 'n_tokens_mistral': 841, 'n_tokens_neox': 776, 'n_words': 196}