diff --git a/accidentalbot.js b/accidentalbot.js index 754678c..13387c0 100644 --- a/accidentalbot.js +++ b/accidentalbot.js @@ -16,6 +16,7 @@ var TITLE_LIMIT = 75; var titles = []; var connections = []; var links = []; +var chapters = []; function sendToAll(packet) { connections.forEach(function (connection) { @@ -114,13 +115,36 @@ function handleNewLink(from, message) { } } +function handleNewChapter(from, message) { + if (message.startsWith('!chapter')) { + message = message.substring(9); + } else if (message.startsWith('!c')) { + message = message.substring(3); + } + + if (message.startsWith('http')) { + var chapter = { + id: chapters.length, + author: from, + chapter: message, + time: new Date() + }; + chapters.push(chapter); + + sendToAll({operation: 'NEWCHAPTER', chapter: chapter}); + } else { + client.say(from, "That doesn't look like a chapter to me."); + } +} + function handleHelp(from) { client.say(from, 'Options:'); client.say(from, '!s {title} - suggest a title (in ' + channel + ' only).'); client.say(from, '!votes - get the three most highly voted titles.'); client.say(from, '!link {URL} - suggest a link.'); + client.say(from, '!chapter {chapter} - suggest a chapter title.'); client.say(from, '!help - see this message.'); - client.say(from, 'To see titles/links, go to: ' + webAddress); + client.say(from, 'To see titles/links/chapters, go to: ' + webAddress); } var options = { diff --git a/webclient/showbot.html b/webclient/showbot.html index 01df3ae..186c309 100644 --- a/webclient/showbot.html +++ b/webclient/showbot.html @@ -23,6 +23,12 @@ {{author}} {{timeAgo time}} + diff --git a/webclient/showbot.js b/webclient/showbot.js index 5fff523..d65a0af 100644 --- a/webclient/showbot.js +++ b/webclient/showbot.js @@ -7,6 +7,7 @@ Showbot.Bot = (function ($) { // Templates var titleRowTemplate = null; var linkRowTemplate = null; + var chapterRowTemplate = null; var connectingTemplate = null; // State @@ -16,6 +17,7 @@ Showbot.Bot = (function ($) { $(function () { titleRowTemplate = titleRowTemplate || Handlebars.compile($("#titleRow").html()); linkRowTemplate = linkRowTemplate || Handlebars.compile($('#linkRow').html()); + chapterRowTemplate = chapterRowTemplate || Handlebars.compile($('#chapterRow').html()); connectingTemplate = connectingTemplate || Handlebars.compile($('#connectingMessage').html()); Handlebars.registerHelper('timeAgo', function (date) {