Skip to content

Commit 4be48f8

Browse files
committed
Update youtube.js
1 parent a0e82e7 commit 4be48f8

File tree

2 files changed

+88
-8
lines changed

2 files changed

+88
-8
lines changed

youtube.js

Lines changed: 87 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
registerPlugin({
22
name: 'Youtube Search',
3-
version: '1.2.3',
3+
version: '1.3.0',
44
engine: '>= 0.9.17',
5-
description: 'Youtube video search Queue & Player',
5+
description: 'Youtube video search',
66
author: 'NT5',
77
vars: [
88
{
@@ -431,7 +431,7 @@ registerPlugin({
431431
},
432432
commands: {
433433
'youtube': {
434-
syntax: 'Syntax: !{cmd}-[{valids}] <text>',
434+
syntax: 'Syntax: !{cmd}-[{valids}] [<text>]',
435435
active: true,
436436
hidden: true,
437437
admin: false,
@@ -514,13 +514,30 @@ registerPlugin({
514514
}));
515515
};
516516

517+
var format = require('format');
518+
var message_format = [
519+
[format.bold('You'), format.color('Tube', '#ff0000'), ' '].join(''),
520+
[
521+
[format.bold('Title:'), '{title}'].join(' '),
522+
[format.bold('Link:'), '[url={yt_link}]{yt_link}[/url]'].join(' '),
523+
[format.bold('Duration:'), '{duration}'].join(' '),
524+
[format.bold('Views:'), '{viewCount}'].join(' '),
525+
[format.bold('Likes:'), '{likeCount}'].join(' '),
526+
[format.bold('Dislikes:'), '{dislikeCount}'].join(' '),
527+
[format.bold('Comments:'), '{commentCount}'].join(' '),
528+
[format.bold('By:'), '{upload_by}'].join(' '),
529+
[format.bold('Description:'), '{description_complete}'].join(' ')
530+
].join(' - ')
531+
];
532+
517533
var videoid = youtube.config.plugin.regex.youtube.exec(data.text) || data.text;
518534

519535
youtube.api.video({
520536
videoId: (typeof videoid === 'object' ? videoid[ 1 ] : videoid ),
521537
callback: function(video) {
522538
youtube.callbacks.video_message({
523539
msg: data,
540+
message_format: message_format.join(''),
524541
video: video
525542
});
526543
},
@@ -530,16 +547,76 @@ registerPlugin({
530547
});
531548
}
532549
},
550+
'search': {
551+
syntax: 'Syntax !{cmd}-{par} <text>',
552+
active: true,
553+
hidden: false,
554+
admin: false,
555+
callback: function(data) {
556+
var msg = function(text) {
557+
youtube.msg(Object.assign(data, {
558+
text: text
559+
}));
560+
};
561+
562+
var format = require('format');
563+
var message_format = [
564+
[format.bold('You'), format.color('Tube', '#ff0000'), ' '].join(''),
565+
[
566+
[format.bold('Title:'), '{title}'].join(' '),
567+
[format.bold('Link:'), '[url={yt_link}]{yt_link}[/url]'].join(' '),
568+
[format.bold('Description:'), '{description}'].join(' '),
569+
[format.bold('by:'), '{upload_by}'].join(' ')
570+
].join(' - ')
571+
];
572+
573+
youtube.api.search({
574+
query: data.text,
575+
maxresults: 5,
576+
callback: function(search) {
577+
search = (typeof search !== "object") ? {} : search;
578+
search.items = search.items || [];
579+
var items = search.items;
580+
581+
items.forEach(function(item) {
582+
engine.log(item);
583+
item = (typeof item !== "object") ? {} : item;
584+
item.id = item.id || {};
585+
item.id.videoId = item.id.videoId || 0;
586+
item.id.kind = item.id.kind || 'default';
587+
588+
youtube.callbacks.video_message({
589+
msg: data,
590+
message_format: message_format.join(''),
591+
video: {
592+
items: [{
593+
id: item.id.videoId,
594+
kind: item.id.kind,
595+
snippet: item.snippet
596+
}]
597+
}
598+
});
599+
});
600+
},
601+
error_callback: function(err) {
602+
msg("Search failed (Bad request)");
603+
}
604+
});
605+
}
606+
},
533607
'about': {
534608
syntax: false,
535609
active: true,
536610
hidden: false,
537611
admin: false,
538612
callback: function(data) {
613+
var bot = backend.getBotClient();
614+
539615
youtube.msg(Object.assign(data, {
540-
text: 'Youtube Search script v{version} by {author}'.format({
541-
version: '1.2.3',
542-
author: 'NT5'
616+
text: 'Youtube Search script v{version} by {author} running on {bot_name}'.format({
617+
version: '1.3.0',
618+
author: 'NT5',
619+
bot_name: bot.name()
543620
})
544621
}));
545622
}
@@ -604,7 +681,7 @@ registerPlugin({
604681
text: '{0}'.format(backend.getBotClient().uniqueID())
605682
}));
606683

607-
engine.log(config);
684+
engine.log(sinusbot);
608685
}
609686
},
610687
getCommands: function() {
@@ -625,6 +702,8 @@ registerPlugin({
625702
data.video = data.video || {};
626703
data.msg = data.msg || {};
627704

705+
data.message_format = data.message_format || youtube.config.plugin.command_message;
706+
628707
var msg = function(text) {
629708
youtube.msg(Object.assign(data.msg, {
630709
text: text
@@ -676,7 +755,7 @@ registerPlugin({
676755
};
677756

678757
// Send message
679-
msg(youtube.config.plugin.command_message.format(str_var));
758+
msg(data.message_format.format(str_var));
680759
} else {
681760
msg("Search failed (Invalid type)");
682761
engine.log(data.video);

0 commit comments

Comments
 (0)