-
Notifications
You must be signed in to change notification settings - Fork 3
Added various todo.jsm features #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mcpower
wants to merge
9
commits into
auscompgeek:master
Choose a base branch
from
mcpower:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
37a7774
todo.jsm: save todos after delete
mcpower 9e8b274
todo.jsm: display todo indices when getting todos
mcpower 99e35bd
todo.jsm: allow deletion of multiple todos
mcpower a34c051
todo.jsm: allow deletion of todos by name
mcpower 90cbdae
updated tododel help string
mcpower ba0b124
todo.jsm: implemented todoins
mcpower 511da4a
todo.jsm: more concise, doesn't notice people
mcpower d6d59f7
todo.jsm: various fixes
mcpower bb98703
todo.jsm: even more various fixes
mcpower File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
/*global module: false */ | ||
|
||
module.version = 0.5; | ||
module.version = 0.92; | ||
module.users = {}; | ||
module.DB_FILENAME = "todo.json"; | ||
|
||
|
@@ -33,11 +33,13 @@ module.cmd_todo = function cmd_todo(e) { | |
if (e.args) { | ||
list.push(e.args); | ||
this.saveUsers(); | ||
e.notice("Ok."); | ||
// e.notice("Ok."); | ||
} else if (!list.length) { | ||
e.reply("Nothing on your todo list."); | ||
} else { | ||
e.reply(list.join("; ")); | ||
e.reply(list.map(function addIndex(todo, index) { | ||
return "[{0}] {1}".format(index, todo); | ||
}).join(" ")); | ||
} | ||
|
||
return true; | ||
|
@@ -49,20 +51,78 @@ module.cmd_tododel = function cmd_tododel(e) { | |
e.reply(this.cmd_tododel.help); | ||
return true; | ||
} | ||
var index = e.args >>> 0; | ||
|
||
var list = this.getList(e.nick); | ||
|
||
if (index >= list.length) { | ||
e.reply("You only have {0} things in your todo list.".format(list.length)); | ||
if (/^[0-9,]+$/.test(e.args)) { | ||
var indexes = e.args.split(",").map(Number); | ||
|
||
var notDeleted = 0; | ||
for (var i = 0; i < indexes.length; i++) { | ||
if (indexes[i] >= list.length) { | ||
notDeleted++; | ||
} else { | ||
list.splice(indexes[i], 1); | ||
} | ||
} | ||
|
||
var deleted = indexes.length - notDeleted; | ||
if (deleted != 0) { | ||
this.saveUsers(); | ||
// e.notice("Ok, deleted {0} todo{1}.".format(deleted, deleted == 1 ? "" : "s")); | ||
} | ||
if (notDeleted > 0) { | ||
e.reply("You only have {0} todo{1}.".format(list.length, list.length == 1 ? "" : "s")); | ||
} | ||
} else { | ||
list.splice(index, 1); | ||
e.notice("Ok."); | ||
} | ||
var filteredList = list.map(function (s, i) { | ||
return { | ||
elem: s, | ||
index: i | ||
}; | ||
}).filter(function (todo) { | ||
return todo.elem.startsWith(e.args); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks confusing. How about something like: var filteredList = list.filter(function (s) {
return s.startsWith(e.args);
}); I believe I've shimmed the |
||
|
||
switch (filteredList.length) { | ||
case 0: | ||
e.reply('No todos starting with "{0}".'.format(e.args)); | ||
break; | ||
case 1: | ||
list.splice(list.indexOf(filteredList[0].index), 1); | ||
this.saveUsers(); | ||
// e.notice("Ok, deleted \"{0}\".".format(filteredList[0].elem)); | ||
break; | ||
default: | ||
e.reply("Did you mean: {0}".format(filteredList.map(function (todo) { | ||
return "[{0}] {1}".format(todo.index, todo.elem); | ||
}).join(" "))); | ||
} | ||
} | ||
return true; | ||
}; | ||
module.cmd_tododel.help = "Delete an item from your todo list. Usage: tododel <index>"; | ||
module.cmd_tododel.help = "Delete an item from your todo list. Usage: tododel <comma separated indexes | beginning of todo>"; | ||
|
||
module.cmd_todoins = function cmd_todoins(e) { | ||
var match = /^([0-9]+) (.+)$/.exec(e.args); | ||
if (!match) { | ||
e.reply(this.cmd_todoins.help); | ||
return true; | ||
} | ||
var list = this.getList(e.nick); | ||
var index = match[1] >>> 0, todo = match[2]; | ||
|
||
if (index >= list.length) { | ||
e.reply("You only have {0} todo{1}.".format(list.length, list.length == 1 ? "" : "s")); | ||
} else { | ||
list.splice(index, 0, todo); | ||
this.saveUsers(); | ||
// e.notice("Ok."); | ||
} | ||
return true; | ||
} | ||
|
||
module.cmd_todoins.help = "Inserts a todo before the specified index. Usage: todoins <index> <todo>"; | ||
|
||
try { module.loadUsers(); } catch (ex) { | ||
println("Error while loading todo lists from disk: ", ex); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know about half the codebase is missing braces, but could we please move towards using braces everywhere? Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was under the impression that not adding braces was the intended convention in this codebase. Will change these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see how you were got that impression. Indeed, that used to be the convention in the codebase. I still haven't gotten around to fixing it all up though.