|
1 | 1 | class Kandan.Plugins.Emoticons
|
2 | 2 |
|
3 | 3 | @options:
|
4 |
| - regex: /\([a-zA-Z]+\)/g |
| 4 | + regex: /\([a-zA-Z]+\)|(^|\s)+([:|=][\)|\(|P|p])($|\s)/g |
5 | 5 | template: _.template '''
|
6 |
| - <img class="emoticon-embed" src="/assets/emoticons/<%= emoticon %>" title="<%= title %>" height="40" width="40" /> |
| 6 | + <img class="emoticon-embed <%= css %>" src="/assets/emoticons/<%= src %>" title="<%= title %>" /> |
7 | 7 | '''
|
8 | 8 |
|
9 | 9 |
|
10 | 10 | @emoticons: {
|
11 |
| - "(alone)" : "alone.jpg", |
12 |
| - "(awwyea)" : "awwyea.jpg", |
13 |
| - "(badass)" : "badass.png", |
14 |
| - "(bitchplease)" : "bitchplease.jpg", |
15 |
| - "(cereal)" : "cereal.jpg", |
16 |
| - "(challenge)" : "challenge.jpg", |
17 |
| - "(fuckyeah)" : "fuckyeah.jpg", |
18 |
| - "(gtfo)" : "seriously.jpg", |
19 |
| - "(ilied)" : "ilied.jpg", |
20 |
| - "(megusta)" : "megusta.jpg", |
21 |
| - "(notbad)" : "notbad.jpg", |
22 |
| - "(okay)" : "okay.jpg", |
23 |
| - "(omgface)" : "omgface.jpg", |
24 |
| - "(pokerface)" : "pokerface.jpg", |
25 |
| - "(problem)" : "trollface.jpg", |
26 |
| - "(rageguy)" : "rageguy.jpg", |
27 |
| - "(seriously)" : "seriously.jpg", |
28 |
| - "(sweetjesus)" : "sweetjesus.jpg", |
29 |
| - "(trollface)" : "trollface.jpg", |
30 |
| - "(truestory)" : "truestory.png", |
31 |
| - "(youdontsay)" : "youdontsay.png", |
32 |
| - "(yuno)" : "yuno.jpg" |
| 11 | + "(alone)" : { src : "alone.jpg", css : "big", title : "alone"}, |
| 12 | + "(awwyea)" : { src : "awwyea.jpg", css : "big", title : "awwyea"}, |
| 13 | + "(badass)" : { src : "badass.jpg", css : "big", title : "badass"}, |
| 14 | + "(bitchplease)" : { src : "bitchplease.jpg", css : "big", title : "bitchplease"}, |
| 15 | + "(cereal)" : { src : "cereal.jpg", css : "big", title : "cereal"}, |
| 16 | + "(challenge)" : { src : "challenge.jpg", css : "big", title : "challenge"}, |
| 17 | + "(fuckyeah)" : { src : "fuckyeah.jpg", css : "big", title : "fuckyeah"}, |
| 18 | + "(gtfo)" : { src : "gtfo.jpg", css : "big", title : "gtfo"}, |
| 19 | + "(ilied)" : { src : "ilied.jpg", css : "big", title : "ilied"}, |
| 20 | + "(megusta)" : { src : "megusta.jpg", css : "big", title : "megusta"}, |
| 21 | + "(notbad)" : { src : "notbad.jpg", css : "big", title : "notbad"}, |
| 22 | + "(okay)" : { src : "okay.jpg", css : "big", title : "okay"}, |
| 23 | + "(omgface)" : { src : "omgface.jpg", css : "big", title : "omgface"}, |
| 24 | + "(pokerface)" : { src : "pokerface.jpg", css : "big", title : "pokerface"}, |
| 25 | + "(problem)" : { src : "problem.jpg", css : "big", title : "problem"}, |
| 26 | + "(rageguy)" : { src : "rageguy.jpg", css : "big", title : "rageguy"}, |
| 27 | + "(seriously)" : { src : "seriously.jpg", css : "big", title : "seriously"}, |
| 28 | + "(sweetjesus)" : { src : "sweetjesus.jpg", css : "big", title : "sweetjesus"}, |
| 29 | + "(trollface)" : { src : "trollface.jpg", css : "big", title : "trollface"}, |
| 30 | + "(truestory)" : { src : "truestory.jpg", css : "big", title : "truestory"}, |
| 31 | + "(youdontsay)" : { src : "youdontsay.jpg", css : "big", title : "youdontsay"}, |
| 32 | + "(yuno)" : { src : "yuno.jpg", css : "big", title : "yuno"}, |
| 33 | + ":(" : { src : "sad.png", css : "small", title : "sad"}, |
| 34 | + "=(" : { src : "sad.png", css : "small", title : "sad"}, |
| 35 | + ":)" : { src : "happy.png", css : "small", title : "happy"}, |
| 36 | + "=)" : { src : "sad.png", css : "small", title : "happy"}, |
| 37 | + ":p" : { src : "tongue.png", css : "small", title : ":p"} |
| 38 | + "=p" : { src : "tongue.png", css : "small", title : "=p"} |
33 | 39 | }
|
34 | 40 |
|
35 | 41 | @init: ()->
|
36 | 42 | Kandan.Modifiers.register @options.regex, (message, state) =>
|
37 | 43 | matches = message.content.match(@options.regex)
|
38 | 44 | for match in _.unique(matches)
|
| 45 | + match = match.trim(); |
39 | 46 | emoticon = @emoticons[match]
|
40 |
| - title = match.replace(/\(|\)/g, "") |
41 |
| - needle = match.replace('(', '\\(').replace(')', '\\)') |
42 |
| - search = new RegExp(needle, 'g') |
43 |
| - replacement = @options.template({ emoticon: emoticon, title: title}) |
44 |
| - message.content = message.content.replace(search, replacement) if emoticon |
| 47 | + |
| 48 | + if emoticon |
| 49 | + needle = match.replace('(', '\\(').replace(')', '\\)') |
| 50 | + search = new RegExp(needle, 'g') |
| 51 | + replacement = @options.template(emoticon) |
| 52 | + message.content = message.content.replace(search, replacement) |
| 53 | + |
45 | 54 | return Kandan.Helpers.Activities.buildFromMessageTemplate(message)
|
46 | 55 |
|
47 | 56 | # Kandan.Plugins.register "Kandan.Plugins.Emoticons"
|
0 commit comments