registerPlugin({
name: 'Welcome Sound by Server Groups',
version: '1.0',
description: 'Play a sound on joining of selected server groups',
author: 'Nobody',
vars: {
Tracks: {
title: 'Add New',
type: 'array',
vars: [
{
name: 'channelId',
title: 'Default Channel (Channel(s) Id(s)):',
type: 'channel',
placeholder: '44,137,256 (Comma Separated)'
},
{
name: 'track',
title: 'Sound File:',
type: 'track',
placeholder: 'Search for track...'
},
{
name: 'resume',
title: 'Resume last track or stream after welcomesound:',
type: 'select',
options: [
'Disabled',
'Enabled'
]
},
{
name: 'servergroup',
title: 'Servergroup Ids (Comma seperated):',
type: 'string',
placeholder: '9,15,42'
}
]
}
}
//Funzione Di Ripresa di una traccia musicale
}, function(sinusbot, config) {
if (!config || !config.channelId || !config.track) {
sinusbot.log("Settings invalid.");
return;
}
var resumePlayback = false;
var resumeTrack = false;
var resumePos = 0;
var securejoin = true;
var getUUID = function (url) {
var match = url.match(/track:\/\/(\.)?(.[^/:]+)/i);
if (match != null && match.length > 2 && typeof match[2] === 'string' && match[2].length > 0) {
return match[2];
}
else {
return null;
}
}
// Permette di far partire la traccia quando un utente entra nella stanza
sinusbot.on('clientMove', function(ev) {
if (ev.newChannel == config.channelId && sinusbot.getCurrentChannelId() == config.channelId) {
sinusbot.log("Welcome-Sound starting...");
if (config.resume && sinusbot.playing() && (sinusbot.getCurrentTrack().uuid != "" || sinusbot.getCurrentTrack().type == 'url') && (sinusbot.getCurrentTrack().uuid != getUUID(config.track.url))) {
resumePlayback = true;
resumeTrack = sinusbot.getCurrentTrack();
resumePos = sinusbot.getPos();
sinusbot.play(config.track.url + '&callback=welcomesound©=true');
} else if (resumePlayback) {
securejoin = false;
sinusbot.play(config.track.url + '&callback=welcomesound©=true');
} else {
sinusbot.play(config.track.url);
}
}
});
// Permette di far riprendere la musica precende alla riproduzione del suono di benvenuto
sinusbot.on('trackEnd', function(cb) {
if (cb == 'welcomesound' && resumePlayback) {
if (securejoin) {
sinusbot.log("Resume last track: " + resumeTrack.title);
resumePlayback = false;
if (resumeTrack.type == 'url') {
sinusbot.play(resumeTrack.filename);
} else {
sinusbot.setMute(true);
sinusbot.play("track://" + resumeTrack.uuid);
sinusbot.seek(resumePos);
sinusbot.setMute(false);
}
}
securejoin = true;
}
});
});