Skip to content
This repository was archived by the owner on Jul 17, 2020. It is now read-only.

Commit 8910962

Browse files
author
Zirak
committed
added meme listener and /meme. fixes #151
1 parent ce7fc71 commit 8910962

File tree

3 files changed

+120
-2
lines changed

3 files changed

+120
-2
lines changed

master.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5269,6 +5269,67 @@ bot.addCommand({
52695269

52705270
})();
52715271

5272+
;
5273+
(function () {
5274+
// #151: Listen for meme image names and reply with that meme.
5275+
5276+
var urlBase = 'http://cdn.alltheragefaces.com/img/faces/png/',
5277+
extension = 'png';
5278+
5279+
var memes = {
5280+
deskflip : 'angry-desk-flip',
5281+
no : 'angry-no',
5282+
notbad : 'obama-not-bad',
5283+
ohyou : 'happy-oh-stop-it-you',
5284+
okay : 'okay-okay-clean',
5285+
troll : 'troll-troll-face',
5286+
trollface : 'troll-troll-face',
5287+
youdontsay : 'misc-you-dont-say',
5288+
};
5289+
5290+
// ^(deskflip|no|notbad|...)\.(jpe?g|png)$
5291+
var re = new RegExp(
5292+
'^(' +
5293+
Object.keys( memes ).map( RegExp.escape ).join( '|' ) +
5294+
')\\.(jpe?g|png)$' );
5295+
5296+
IO.register( 'input', function meme ( msgObj ) {
5297+
var msg = msgObj.content.toLowerCase(),
5298+
parts = re.exec( msg );
5299+
5300+
if ( !parts ) {
5301+
return;
5302+
}
5303+
5304+
var reply = getMemeLink( parts[1] );
5305+
5306+
bot.adapter.out.add(
5307+
bot.adapter.directreply( msgObj.message_id ) + ' ' +
5308+
reply, msgObj.room_id );
5309+
});
5310+
5311+
bot.addCommand({
5312+
name : 'meme',
5313+
fun : function ( args ) {
5314+
if ( !memes[args] ) {
5315+
return 'Sorry, I don\'t know that one.';
5316+
}
5317+
//TODO: list possible memes (reply with Object.keys(meme))
5318+
5319+
args.directreply( getMemeLink(args) );
5320+
},
5321+
permissions : { del : 'NONE' },
5322+
description : 'Return a simple meme link. `/meme memeName`'
5323+
});
5324+
5325+
function getMemeLink ( meme ) {
5326+
return urlBase + memes[ meme ] + '.' + extension;
5327+
}
5328+
5329+
})();
5330+
5331+
;
5332+
52725333
;
52735334
(function () {
52745335
"use strict";

0 commit comments

Comments
 (0)