forked from upnextfm/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreact.js
54 lines (51 loc) · 1.76 KB
/
react.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* Script: Reaction GIFs
* Version: 1.5.1
* Author: headzoo
*
* Displays a random image from replygif.net based on your search term
*
* Use the command "/react [search-term]" where [search-term] is a simple
* reaction term like "okay" or "clapping". The script provides autocomplete
* which will suggest possible search terms.
*/
(function() {
$proxy.getJSON("http://replygif.net/api/tags?reaction=1&api-key=39YAprx5Yi", function(res) {
$('#chatline').textcomplete([
{
id: 'react',
match: /\/react ([\w]*)$/,
search: function (term, callback) {
callback($.map(res, function (tag) {
return tag.title.replace('/react', '').indexOf(term) === 0 ? tag.title : null;
}));
},
template: function (title) {
return title;
},
replace: function (title) {
return '/react ' + title;
},
index: 1
}
], {
maxCount: 8
});
});
$api.on("send", function(e, data) {
var msg = data.msg.toLowerCase();
if (msg.indexOf("/react ") === 0) {
var query = msg.replace("/react ", "");
var url = "http://replygif.net/api/gifs?api-key=39YAprx5Yi&tag=" + query;
$proxy.getJSON(url, function(res) {
if (res.length == 0) {
$api.notice("No reaction found.", true);
} else {
var item = res[Math.floor(Math.random()*res.length)];
$api.send(item.file);
}
});
e.cancel();
}
});
})();