Skip to content

Commit

Permalink
Add ban, clear, endGame, kick, spam, startGame & minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kpxyy committed Nov 23, 2023
1 parent 29ce41f commit 781a757
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 2 deletions.
21 changes: 21 additions & 0 deletions commands/ban.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
name: 'ban',
description: 'ban command',
execute(data, client, prefix) {
if (data.msg.startsWith(`${prefix}ban`)) {
const username = data.msg.split(' ')[1];
if (username) {
const player = client.players.find(player => player.name === username);
if (player) {
client.hostBan(player.id);
client.sendMessage(`I banned ${player.name}, If I have host permissons of course.`);
} else {
client.sendMessage('Invalid username, try again.');
}
} else {
client.sendMessage(`Please specify a valid username after ${prefix}ban`);
}
return;
}
},
};
11 changes: 11 additions & 0 deletions commands/clear.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
name: 'clear',
description: 'clear command',
execute(data, client, prefix) {
if (data.msg.startsWith(`${prefix}clear`)) {
client.clearCanvas();
client.sendMessage('I cleared the canva, If I am the current drawer of course.');
return;
}
},
};
11 changes: 11 additions & 0 deletions commands/endGame.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
name: 'endgame',
description: 'end game command',
execute(data, client, prefix) {
if (data.msg.startsWith(`${prefix}endgame`)) {
client.endGame();
client.sendMessage('Ended Game, If I have host of course.');
return;
}
},
};
17 changes: 16 additions & 1 deletion commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,27 @@ module.exports = {

setTimeout(() => {
client.sendMessage(`${prefix}userinfo - gives you basic user information, you must include a username.`);
client.sendMessage(`${prefix}spam - spams chat (<message> <time (seconds)> <cooldown (seconds)>).`);
}, 16000)

setTimeout(() => {
client.sendMessage(`${prefix}ban - bans a user. you must include a username.`);
client.sendMessage(`${prefix}kick - kicks a user. you must include a username.`);
}, 21000)

setTimeout(() => {
client.sendMessage(`${prefix}clear - clears current drawing`);
client.sendMessage(`${prefix}endGame - ends the game.`);
}, 26000)

setTimeout(() => {
client.sendMessage(`${prefix}startGame - starts the game.`);
}, 32000)

setTimeout(() => {
client.sendMessage(`${prefix}leave - disconnects the bot & quits the program.`);
client.sendMessage(`The current prefix is "${prefix}".`)
}, 22000)
}, 36000)

return;
}
Expand Down
21 changes: 21 additions & 0 deletions commands/kick.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
name: 'kick',
description: 'kick command',
execute(data, client, prefix) {
if (data.msg.startsWith(`${prefix}kick`)) {
const username = data.msg.split(' ')[1];
if (username) {
const player = client.players.find(player => player.name === username);
if (player) {
client.hostKick(player.id);
client.sendMessage(`I kicked ${player.name}, If I have host permissons of course.`);
} else {
client.sendMessage('Invalid username, try again.');
}
} else {
client.sendMessage(`Please specify a valid username after ${prefix}kick`);
}
return;
}
},
};
1 change: 1 addition & 0 deletions commands/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
execute(data, client, prefix) {
if (data.msg.startsWith(`${prefix}ping`)) {
client.sendMessage('Pong');
return;
}
},
};
37 changes: 37 additions & 0 deletions commands/spam.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
module.exports = {
name: 'spam',
description: 'Spam command',
execute(data, client, prefix) {
let i;
let t;

if (data.msg.startsWith(`${prefix}spam`)) {
const msg = data.msg.split(' ')[1];
const timer = data.msg.split(' ')[2];
const cooldown = data.msg.split(' ')[3];

if (typeof msg !== "string" && typeof timer !== "string" && typeof cooldown !== "string") {
client.sendMessage(`Invaild spam fields. Make sure your fields is correct! (${prefix}spam <string> <num> <num>)`);

return;
}

if(msg && timer && cooldown) {
client.sendMessage(`Spam started; This will end in ${timer}s; ${prefix}leave to cancel & quit the program.`);

i = setInterval(() => {
client.sendMessage(msg);
}, cooldown * 1000)

t = setTimeout(() => {
client.sendMessage('Spam ended');
clearInterval(i);
}, timer * 1000)
} else {
client.sendMessage(`You're missing fields! ex: ${prefix}spam <message> <time (in seconds)> <cooldown (in seconds)>`);
}

return;
}
},
};
11 changes: 11 additions & 0 deletions commands/startGame.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
name: 'startgame',
description: 'start game command',
execute(data, client, prefix) {
if (data.msg.startsWith(`${prefix}startgame`)) {
client.startGame();
client.sendMessage('Started Game, If I have host of course.');
return;
}
},
};
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let prefix = "!";
function main() {
const client = new Client({
name: "CommanderBox",
lobbyCode: ""
lobbyCode: "LbCd3hrR"
});

const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
Expand Down

0 comments on commit 781a757

Please sign in to comment.