Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion accidentalbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var TITLE_LIMIT = 75;
var titles = [];
var connections = [];
var links = [];
var chapters = [];

function sendToAll(packet) {
connections.forEach(function (connection) {
Expand Down Expand Up @@ -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 = {
Expand Down
19 changes: 19 additions & 0 deletions webclient/showbot.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
<td>{{author}}</td>
<td class="time" data-time="{{{time}}}">{{timeAgo time}}</td>
</script>
<script id="chapterRow" type="text/x-handlebars-template">
<tr data-id="{{id}}">
<td><a href="{{{chapter}}}" onclick="return Showbot.Bot.chapterHandler(this);">Chapter</a></td>
<td>{{author}}</td>
<td class="time" data-time="{{{time}}}">{{timeAgo time}}</td>
</script>

<script id="connectingMessage" type="text/x-handlebars-template">
Connecting...
Expand Down Expand Up @@ -58,6 +64,19 @@ <h2>Links</h2>
</tbody>
</table>

<h2>Chapters</h2>
<table class="chapters table">
<thead>
<tr>
<th>Chapter</th>
<th>Author</th>
<th>Time</th>
</tr>
</thead>
<tbody>
</tbody>
</table>

<script type="text/javascript">
Showbot.Bot.init();
</script>
Expand Down
2 changes: 2 additions & 0 deletions webclient/showbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Showbot.Bot = (function ($) {
// Templates
var titleRowTemplate = null;
var linkRowTemplate = null;
var chapterRowTemplate = null;
var connectingTemplate = null;

// State
Expand All @@ -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) {
Expand Down