我已被分配到我公司做一个Slack任务机器人,该机器人应该能够创建任务并将其分配给用户。
使用命令(完成x)后,我似乎无法删除任务,它只显示任务已完成的消息,但是每当我查看任务时,“已删除”任务就会显示在列表中。
controller.hears(['done (.*)'],'direct_message,direct_mention,mention',
function(bot, message) {
var number = message.match[1];
if (isNaN(number)) {
bot.reply(message, 'Please specify a number.');
} else {
// adjust for 0-based array index
number = parseInt(number) - 1;
controller.storage.users.get(message.user, function(err, user) {
if (!user) {
user = {};
user.id = message.user;
user.tasks = [];
}
if (number > 0 || number <= user.tasks.length) {
var item = user.tasks.splice(number,1);
// reply with a strikethrough message...
bot.reply(message, '~' + item + '~');
if (user.tasks.length > 0) {
bot.reply(message, 'Here are our remaining tasks:\n' + generateTaskList(user));
} else {
bot.reply(message, 'Your list is now empty!');
}
} else {
bot.reply(message, 'Sorry, your input is out of range. Right now there are ' + user.tasks.length + ' items on your list.');
}
user.tasks.push(number);
controller.storage.users.delete(user, function(err, deleted) {
if (err) {
bot.reply(message, 'I experienced an error deleting your task: ' + err);
} else {
bot.api.reactions.add({
name: 'wastebasket',
channel: message.channel,
timestamp: message.ts
});
}
});
});
}
});strong text