<commit_before>exports.mod = function(context, server)
{
	this.lists = {};

	this.help$register = function()
	{
		server.do('help$register', 'todo');
	}

	this._help = function(topic, params)
	{
		switch(topic)
		{
			case 'todo':
				switch(params[0])
				{
					case '+':
						return 'Add an entry to your todo list.';
					case '-':
						return 'Remove an entry from your todo list.';
					case '?':
						return 'Display your todo list.';
					default:
						return {
							text: 'A simple account-based todo list.',
							sub: ['+', '-', '?']
						};
				}
				break;
		}
	}

	this.core$cmd = function(prefix, target, cmd, params, $core)
	{
		if(cmd === 'todo')
		{
			switch(params[0])
			{
				case '+':
					var syntax = 'Syntax: todo + <data>';
					var data = params.slice(1).join(' ');

					if(data === '') { $core._privmsg(target, syntax); break; }

					var login = server.do('account$getlogin', prefix);

					if(login === undefined)
					{
						$core._privmsg(target, 'You are not logged in.');
						break;
					}

					if(this.lists[login] === undefined) this.lists[login] = [];

					// TODO: make priority configurable
					this.lists[login].push({data: data, priority: 5});

					$core._privmsg(target, 'Added entry to todo list.');
					break;
				case '-':
					var syntax = 'Syntax: todo - <entry #>';
					var entry_no = parseInt(params[1]);

					if(isNaN(entry_no)) { $core._privmsg(target, syntax); break; }

					var login = server.do('account$getlogin', prefix);

					if(login === undefined)
					{
						$core._privmsg(target, 'You are not logged in.');
						break;
					}

					if(entry_no < 1 || this.lists[login] === undefined || this.lists[login].length < entry_no)
					{
						$core._privmsg(target, 'That entry does not exist on your todo list.');
						break;
					}

					var entry = this.lists[login].splice(entry_no - 1, 1);

					$core._privmsg(target, 'Removed entry from todo list. Sending removed entry via NOTICE.');
					$core._notice(prefix.nick, '#' + entry_no + ': ' + entry[0].data);
					break;
				case '?':
				default:
					var login = server.do('account$getlogin', prefix);

					if(login === undefined)
					{
						$core._privmsg(target, 'You are not logged in.');
						break;
					}

					if(this.lists[login] === undefined || this.lists[login].length === 0)
					{
						$core._privmsg(target, 'Your todo list is empty.');
						break;
					}

					$core._privmsg(target, 'Sending todo list via NOTICE.');

					for(var iTodo=0; iTodo<this.lists[login].length; ++iTodo)
					{
						$core._notice(prefix.nick, '#' + (iTodo + 1) + ': ' + this.lists[login][iTodo].data);
					}

					break;
			}
		}
	}
}<commit_msg>Implemented todo list saving/loading, max todo list size, and removing more than one todo entry at once.<commit_after>exports.mod = function(context, server)
{
	this.max_length = 10;
	this.lists = {};

	this.help$register = function()
	{
		server.do('help$register', 'todo');
	}

	this._help = function(topic, params)
	{
		switch(topic)
		{
			case 'todo':
				switch(params[0])
				{
					case '+':
						return 'Add an entry to your todo list.';
					case '-':
						return 'Remove an entry from your todo list.';
					case '?':
						return 'Display your todo list.';
					default:
						return {
							text: 'A simple account-based todo list.',
							sub: ['+', '-', '?']
						};
				}
				break;
		}
	}

	this._load = function(data)
	{
		if(data.max_length !== undefined) this.max_length = data.max_length;
		if(data.lists !== undefined) this.lists = data.lists;
	}

	this._suspend = function()
	{
		return {
			max_length: this.max_length,
			lists: this.lists
		};
	}

	this._resume = function(data)
	{
		if(data.max_length !== undefined) this.max_length = data.max_length;
		if(data.lists !== undefined) this.lists = data.lists;
	}

	this._save = function()
	{
		return {
			max_length: this.max_length,
			lists: this.lists
		};
	}

	this.core$cmd = function(prefix, target, cmd, params, $core)
	{
		if(cmd === 'todo')
		{
			switch(params[0])
			{
				case '+':
					var syntax = 'Syntax: todo + <data>';
					var data = params.slice(1).join(' ');

					if(data === '') { $core._privmsg(target, syntax); break; }

					var login = server.do('account$getlogin', prefix);

					if(login === undefined)
					{
						$core._privmsg(target, 'You are not logged in.');
						break;
					}

					if(this.lists[login] === undefined) this.lists[login] = [];

					if(this.lists[login].length === this.max_length)
					{
						$core._privmsg(target, 'Too many entries on todo list (max=' + this.max_length + ').');
						break;
					}

					// TODO: make priority configurable
					this.lists[login].push({data: data, priority: 5});

					$core._privmsg(target, 'Added entry to todo list.');
					break;
				case '-':
					var syntax = 'Syntax: todo - <entry #> [num to remove]';
					var entry_no = parseInt(params[1]);
					var num_to_remove = parseInt(params[2]);

					if(isNaN(entry_no)) { $core._privmsg(target, syntax); break; }
					if(isNaN(num_to_remove)) num_to_remove = 1;

					var login = server.do('account$getlogin', prefix);

					if(login === undefined)
					{
						$core._privmsg(target, 'You are not logged in.');
						break;
					}

					if(entry_no < 1 || this.lists[login] === undefined || this.lists[login].length < entry_no)
					{
						$core._privmsg(target, 'That entry does not exist on your todo list.');
						break;
					}

					var entry = this.lists[login].splice(entry_no - 1, num_to_remove);

					var s = (num_to_remove === 1) ? 'entry' : 'entries';

					$core._privmsg(target, 'Removed ' + num_to_remove + ' ' + s + ' from todo list. Sending removed ' + s + ' via NOTICE.');

					for(var i=0; i<entry.length; ++i)
					{
						$core._notice(prefix.nick, '#' + entry_no + ': ' + entry[i].data);
					}
					break;
				case '?':
				default:
					var login = server.do('account$getlogin', prefix);

					if(login === undefined)
					{
						$core._privmsg(target, 'You are not logged in.');
						break;
					}

					if(this.lists[login] === undefined || this.lists[login].length === 0)
					{
						$core._privmsg(target, 'Your todo list is empty.');
						break;
					}

					$core._privmsg(target, 'Sending todo list via NOTICE.');

					for(var iTodo=0; iTodo<this.lists[login].length; ++iTodo)
					{
						$core._notice(prefix.nick, '#' + (iTodo + 1) + ': ' + this.lists[login][iTodo].data);
					}

					break;
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.1711056054506039, 'fraction_numerical': 0.004335707649427067, 'mean_word_length': 2.5685082872928175, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 7, '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': '2525769', 'n_tokens_mistral': 2896, 'n_tokens_neox': 2180, 'n_words': 496}