Last active
August 29, 2015 14:01
-
-
Save yatemmma/bee1c9fa120554f1947e to your computer and use it in GitHub Desktop.
limechat script
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
var KEYWORD = "yask"; | |
var PREFIX = "[" + KEYWORD + "] "; | |
var Commands = { all: "?", del: "-", push: "!", full: "@" }; | |
var sequence = 0; | |
var tasks = []; | |
function Task(nick, channel, text) { | |
this.id = ++sequence; | |
this.nick = nick; | |
this.channel = channel; | |
this.text = text; | |
this.finished = false; | |
this.priority = ""; | |
this.createAt = now(); | |
} | |
Task.prototype.summary = function() { | |
return "[" + this.id + "] " + this.nick + " " + this.text; | |
} | |
Task.prototype.detail = function() { | |
return this.priority + "[" + this.id + "] " + this.createAt + " " + this.channel + " (" + this.nick + ") " + this.text; | |
} | |
function now() { | |
var now = new Date(); | |
return now.getHours() + ":" + now.getMinutes(); | |
} | |
function event::onChannelText(prefix, channel, text) { | |
if (new RegExp("\\b"+KEYWORD+"\\"+Commands.all).test(text)) { | |
allTask(prefix.nick, channel, text); | |
} else if (new RegExp("\\b"+KEYWORD+"\\"+Commands.full).test(text)) { | |
fullTask(prefix.nick, channel, text); | |
} else if (new RegExp("\\b"+KEYWORD+"\\"+Commands.del+"(\\s*[0-9]+)").test(text)) { | |
delTask(prefix.nick, channel, text, RegExp.$1); | |
} else if (new RegExp("\\b"+KEYWORD+"\\"+Commands.del).test(text)) { | |
delLastTask(prefix.nick, channel, text); | |
} else if (new RegExp("\\b"+KEYWORD+"\\"+Commands.push+"(\\s*[0-9]+)").test(text)) { | |
pushTask(prefix.nick, channel, text, RegExp.$1); | |
} else if (new RegExp("\\b"+KEYWORD+"\\b").test(text)) { | |
addTask(prefix.nick, channel, text); | |
} | |
} | |
function addTask(nick, channel, text) { | |
var task = new Task(nick, channel, text); | |
tasks.push(task); | |
send(channel, PREFIX + "了解。[" + task.id + "]"); | |
} | |
function allTask(nick, channel, text) { | |
var processingTasks = []; | |
for (var i = 0; i < tasks.length; i++) { | |
var task = tasks[i]; | |
if (!task.finished) { | |
processingTasks.push(task); | |
} | |
} | |
if (processingTasks.length) { | |
send(channel, PREFIX + "-------------------------------------"); | |
for (var i = 0; i < processingTasks.length; i++) { | |
var task = processingTasks[i]; | |
send(channel, task.detail()); | |
} | |
send(channel, "------------------------------------------"); | |
} else { | |
send(channel, PREFIX + "I have no task."); | |
} | |
} | |
function fullTask(nick, channel, text) { | |
send(channel, PREFIX + "-------------------------------------"); | |
for (var i = 0; i < tasks.length; i++) { | |
var task = tasks[i]; | |
send(channel, "[" + (task.finished ? "x": " ") + "] " + task.detail()); | |
} | |
send(channel, "------------------------------------------"); | |
} | |
function delTask(nick, channel, text, id) { | |
for (var i = 0; i < tasks.length; i++) { | |
var task = tasks[i]; | |
if (task.id == id) { | |
task.finished = true; | |
send(task.channel, PREFIX + "完了!" + task.summary()); | |
return; | |
} | |
} | |
} | |
function delLastTask(nick, channel, text) { | |
var list = tasks.concat().reverse(); | |
for (var i = 0; i < list.length; i++) { | |
var task = list[i]; | |
if (!task.finished) { | |
task.finished = true; | |
send(task.channel, PREFIX + "完了!" + task.summary()); | |
return; | |
} | |
} | |
} | |
function pushTask(nick, channel, text, id) { | |
for (var i = 0; i < tasks.length; i++) { | |
var task = tasks[i]; | |
if (task.id == id) { | |
task.priority += "*"; | |
send(channel, PREFIX + "はいー " + task.summary()); | |
return; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment