Auto ban bot for multiple channels

So I posted yesterday asking if something would be possable and was told yes so I attempted it. I have never used js befor and wanted to know if this bot would work or atleast is heading in the right direction.
I would test it but since it is to do with banning users from a channel I dont want it to get abused.
It should receive a command !ban from the user who must be a mod or broadcaster and then ban that person in multiple channels.
Any imput would be apreciated!

const tmi = require(‘tmi.js’);

// Define configuration options
const opts = {
identity: {
username: ‘example’,
password: ‘oauth:example’
},

//List of channels
channels: [
	'example'
] //End channel list

}; //End opts

// Create a client with our options
const client = new tmi.client(opts);

// Register our event handlers (defined below)
client.on(‘message’, onMessageHandler);
client.on(‘connected’, onConnectedHandler);

// Connect to Twitch:
client.connect();

// Called every time a message comes in
function onMessageHandler (target, context, msg, self) {

//Gets badge info for the user
> @badge-info=<badge-info>;badges=<badges>;color=<color>;display-name=<display-name>;emotes=<emotes>;id=<id-of-msg>;mod=<mod>;room-id=<room-id>;subscriber=<subscriber>;tmi-sent-ts=<timestamp>;turbo=<turbo>;user-id=<user-id>;user-type=<user-type> :<user>!<user>@<user>.tmi.twitch.tv PRIVMSG #<channel> :<message>

// Ignore messages from the bot and non moderators
if (self || ($msgtags(badges).key !== broadcaster/1) || ($msgtags(badges).key !== moderator/1)) { return; }

// split string
const commandName = splitString(msg, ' ');

//If the user wants to ban someone
if (commandName[0] === '!ban') {
	ban(commandName[1], commandName[2]);
} //End if
//If the user wants to unban another user
else if(commandName[0] === '!unban') {
	unban(commandName[0]);
} else {
	console.log(`* Unknown command ${commandName}`);
} //End else

} //End messageHandeler

// Function called when the “ban” command is issued
function ban(userName, reason) {

client.say('/ban ' + (userName) + ' ' + (reason)`);
console.log(`* Executed ${commandName} command`);

} //End ban function

// Function called when the “unban” command is issued
function unban(userName) {

client.say(target, `/unban (userName)`);
console.log(`* Executed ${commandName} command`);

} //End unban function

// Called every time the bot connects to Twitch chat
function onConnectedHandler (addr, port) {
console.log(* Connected to ${addr}:${port});
}

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.