Skip to content

Instantly share code, notes, and snippets.

@suhrmann
Last active June 8, 2017 03:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suhrmann/fcf0eb4c1faa9d2d1f0d6d61f82d593c to your computer and use it in GitHub Desktop.
Save suhrmann/fcf0eb4c1faa9d2d1f0d6d61f82d593c to your computer and use it in GitHub Desktop.
A Script for sinusbot to kick a player who's randomly choosen and play a sound shortly before the kick.
registerPlugin({
name: 'Random Kick With Sound',
version: '1.0',
description: 'If someone sends "!rkick" to the bot, he will randomly kick one member from the channel while playing a medley.',
author: 'vadammt <vadammt@mordsgau.de>',
vars: {
message: {
title: 'Message which user activated random kick. (%n = nickname)',
type: 'string'
},
kickmessage: {
title: 'Message which user was kicked. (%n = nickname)',
type: 'string'
},
messageMedium: {
title: 'TODO: Transmit the message by poking every player (in the channel) or by writing it to the channel.',
type: 'select',
options: [
'poke',
'channel'
]
},
track: {
title: 'Sound File:',
type: 'track',
placeholder: 'Search for track...'
},
kickOffset: {
title: 'Kick after this number of miliseconds (min. 500):',
type: 'number'
}
}
}, function (sinusbot, config) {
// Check config
if (!config || !config.message || !config.kickmessage || !config.messageMedium || !config.track || config.kickOffset < 500) {
sinusbot.log("Settings invalid.");
return;
}
sinusbot.on('chat', function (ev) {
if (ev.msg != '!rkick') {
return;
}
var clients;
var kickStarterNickname;
var startedByMessage;
var whoWasKickedMessage;
var msgid;
var randomnumber;
var theChosenOne;
var allchannel;
// Who threw it? Who threw that stone?
allchannel = sinusbot.getChannels();
for (var j = 0; j < allchannel.length; j++) {
for (var client = 0; client < allchannel[j].clients.length; client++) {
if (allchannel[j].clients[client].uid == ev.clientUid) {
kickStarterNickname = allchannel[j].clients[client].nick;
}
}
}
startedByMessage = config.message.replace(/%n/g, kickStarterNickname);
// Play the song
sinusbot.play(config.track.url);
// Start to kick
setTimeout(function () {
clients = sinusbot.getChannel(sinusbot.getCurrentChannelId()).clients;
if (clients.length <= 1) {
// There's no one (but the bot) in this channel.
return;
}
// Find a player to kick...
// Collect the nominees (except the bot)
nominees = sinusbot.getChannel(sinusbot.getCurrentChannelId()).clients;
for (var i = 0; i < nominees.length; i++) {
if (nominees[i].nick == sinusbot.getNick()) { // uid (string) unique id of the client ;
nominees.splice(i, 1);
break;
}
}
// Find the chosen one
randomnumber = Math.floor(Math.random() * nominees.length);
theChosenOne = nominees[randomnumber];
// Kick this scum!!!
whoWasKickedMessage = config.kickmessage.replace(/%n/g, theChosenOne.nick);
chatChannel(whoWasKickedMessage);
kickServer(theChosenOne.id);
}, config.kickOffset);
if (config.messageMedium == 0) { // 0 = poke
clients = sinusbot.getChannel(sinusbot.getCurrentChannelId()).clients;
for (var i = 0; i < clients.length; i++) {
msgid = clients[i].id;
sinusbot.poke(msgid, startedByMessage);
}
}
else if (config.messageMedium == 1) { // 1 = channel
chatChannel(startedByMessage);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment