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

Commit 46f6100

Browse files
author
Zirak
committed
1 parent 79ca4da commit 46f6100

File tree

3 files changed

+122
-0
lines changed

3 files changed

+122
-0
lines changed

master.js

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

44874487
;
44884488

4489+
;
4490+
(function () {
4491+
// #151: Listen for meme image names and reply with that meme.
4492+
4493+
var urlBase = 'http://cdn.alltheragefaces.com/img/faces/png/',
4494+
extension = 'png';
4495+
4496+
var memes = {
4497+
deskflip : 'angry-desk-flip',
4498+
no : 'angry-no',
4499+
notbad : 'obama-not-bad',
4500+
ohyou : 'happy-oh-stop-it-you',
4501+
okay : 'okay-okay-clean',
4502+
troll : 'troll-troll-face',
4503+
trollface : 'troll-troll-face',
4504+
youdontsay : 'misc-you-dont-say',
4505+
};
4506+
4507+
// ^(deskflip|no|notbad|...)\.(jpe?g|png)$
4508+
var re = new RegExp(
4509+
'^(' +
4510+
Object.keys( memes ).map( RegExp.escape ).join( '|' ) +
4511+
')\\.(jpe?g|png)$' );
4512+
4513+
IO.register( 'input', function meme ( msgObj ) {
4514+
var msg = msgObj.content.toLowerCase(),
4515+
parts = re.exec( msg );
4516+
4517+
if ( !parts ) {
4518+
return;
4519+
}
4520+
4521+
var reply = getMemeLink( parts[1] );
4522+
4523+
bot.adapter.out.add(
4524+
bot.adapter.directreply( msgObj.message_id ) + ' ' +
4525+
reply, msgObj.room_id );
4526+
});
4527+
4528+
bot.addCommand({
4529+
name : 'meme',
4530+
fun : function ( args ) {
4531+
var name = args.replace( /\.\w+$/, '' );
4532+
4533+
if ( !memes[name] ) {
4534+
return 'Sorry, I don\'t know that one.';
4535+
}
4536+
//TODO: list possible memes (reply with Object.keys(meme))
4537+
4538+
args.directreply( getMemeLink(name) );
4539+
},
4540+
permissions : { del : 'NONE' },
4541+
description : 'Return a simple meme link. `/meme memeName`'
4542+
});
4543+
4544+
function getMemeLink ( meme ) {
4545+
return urlBase + memes[ meme ] + '.' + extension;
4546+
}
4547+
4548+
})();
4549+
44894550
;
44904551
(function () {
44914552
"use strict";

master.min.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/plugins/meme.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
(function () {
2+
// #151: Listen for meme image names and reply with that meme.
3+
4+
var urlBase = 'http://cdn.alltheragefaces.com/img/faces/png/',
5+
extension = 'png';
6+
7+
var memes = {
8+
deskflip : 'angry-desk-flip',
9+
no : 'angry-no',
10+
notbad : 'obama-not-bad',
11+
ohyou : 'happy-oh-stop-it-you',
12+
okay : 'okay-okay-clean',
13+
troll : 'troll-troll-face',
14+
trollface : 'troll-troll-face',
15+
youdontsay : 'misc-you-dont-say',
16+
};
17+
18+
// ^(deskflip|no|notbad|...)\.(jpe?g|png)$
19+
var re = new RegExp(
20+
'^(' +
21+
Object.keys( memes ).map( RegExp.escape ).join( '|' ) +
22+
')\\.(jpe?g|png)$' );
23+
24+
IO.register( 'input', function meme ( msgObj ) {
25+
var msg = msgObj.content.toLowerCase(),
26+
parts = re.exec( msg );
27+
28+
if ( !parts ) {
29+
return;
30+
}
31+
32+
var reply = getMemeLink( parts[1] );
33+
34+
bot.adapter.out.add(
35+
bot.adapter.directreply( msgObj.message_id ) + ' ' +
36+
reply, msgObj.room_id );
37+
});
38+
39+
bot.addCommand({
40+
name : 'meme',
41+
fun : function ( args ) {
42+
var name = args.replace( /\.\w+$/, '' );
43+
44+
if ( !memes[name] ) {
45+
return 'Sorry, I don\'t know that one.';
46+
}
47+
//TODO: list possible memes (reply with Object.keys(meme))
48+
49+
args.directreply( getMemeLink(name) );
50+
},
51+
permissions : { del : 'NONE' },
52+
description : 'Return a simple meme link. `/meme memeName`'
53+
});
54+
55+
function getMemeLink ( meme ) {
56+
return urlBase + memes[ meme ] + '.' + extension;
57+
}
58+
59+
})();

0 commit comments

Comments
 (0)