Last active
February 8, 2016 17:12
-
-
Save maxanier/b5edb790313d898a1805 to your computer and use it in GitHub Desktop.
Script for SinusBot https://frie.se/ts3bot/ - Allows you to configure individual welcome messages for users/groups via TTS/Poke/Chat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
registerPlugin({ | |
name : 'Individual Welcome', | |
version : '1.0', | |
description : 'This plugin will let the bot greet everyone.', | |
author : 'Maxanier <dev@maxgb.de>', | |
vars : { | |
messages : { | |
title : 'The message that should be displayed. (%n = nickname)', | |
type : 'string' | |
}, | |
dtype : { | |
title : 'Type of output', | |
type : 'select', | |
options : ['TTS', | |
'Poke', 'Chat'] | |
}, | |
dvoice : { | |
title : 'Default voice', | |
type : 'string' | |
} | |
} | |
}, function (sinusbot, config) { | |
log("Parsing messages "+ config.messages); | |
var messages=JSON.parse(config.messages); | |
log("Parsed messages"); | |
var getMsg = function (client) { | |
for (var i = 0; i < messages.users.length; i++) { | |
if (messages.users[i].name === client.clientNick) { | |
return messages.users[i]; | |
} | |
} | |
if(client.clientServerGroups.length==0){ | |
log("User has no group"); | |
var id=9999; | |
for(var j=0;j<messages.groups.length;j++){ | |
if(id==messages.groups[j].id){ | |
return messages.groups[j]; | |
} | |
} | |
} | |
for(var i=0;i<client.clientServerGroups.length;i++){ | |
log("group "+client.clientServerGroups[i]); | |
var id=client.clientServerGroups[i].i; | |
for(var j=0;j<messages.groups.length;j++){ | |
if(id==messages.groups[j].id){ | |
return messages.groups[j]; | |
} | |
} | |
} | |
if(messages.default.length==0){ | |
return undefined; | |
} | |
var defId = Math.floor(Math.random() * messages.default.length); | |
return messages.default[defId]; | |
}; | |
sinusbot.on('clientMove', function (ev) { | |
var msg; | |
if (ev.oldChannel == 0) { | |
var msg = getMsg(ev); | |
if(msg==undefined){ | |
log("No message for "+ev.clientNick+" found"); | |
return; | |
} | |
log("Selected message: " + msg.msg + " with " + msg.type + ":" + msg.voice); | |
var text = msg.msg.replace("%n",ev.clientNick); | |
var type = config.dtype; | |
var voice= config.dvoice; | |
log("Default type: "+type); | |
log("Default voice: "+voice); | |
if (msg.type != undefined) { | |
type = msg.type; | |
} | |
if (msg.voice!= undefined) { | |
voice = msg.voice; | |
} | |
log("Selected type: "+type); | |
log("Selected voice: "+voice); | |
if (type == 0) { | |
if (ev.newChannel == getCurrentChannelId()) { | |
say(text, voice); | |
log("Saying: "+text); | |
} | |
else{ | |
log("Not saying something, since I'm in another channel"); | |
} | |
} | |
else if(type==1){ | |
poke(ev.clientId,text); | |
} | |
else if(type==2){ | |
chatPrivate(ev.clientId,text); | |
} | |
} | |
return; | |
}); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment