Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMonDon committed Oct 20, 2023
2 parents d90de1b + b777aa8 commit a4793fd
Show file tree
Hide file tree
Showing 35 changed files with 3,097 additions and 523 deletions.
49 changes: 8 additions & 41 deletions commands/Games/connect4.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,34 +65,6 @@ class Connect4 extends Command {
);
}

function checkLine(a, b, c, d) {
return a !== null && a === b && a === c && a === d;
}

function verifyWin(bd) {
for (let r = 0; r < 3; r++) {
for (let c = 0; c < 7; c++) {
if (checkLine(bd[r][c], bd[r + 1][c], bd[r + 2][c], bd[r + 3][c])) return bd[r][c];
}
}
for (let r = 0; r < 6; r++) {
for (let c = 0; c < 4; c++) {
if (checkLine(bd[r][c], bd[r][c + 1], bd[r][c + 2], bd[r][c + 3])) return bd[r][c];
}
}
for (let r = 0; r < 3; r++) {
for (let c = 0; c < 4; c++) {
if (checkLine(bd[r][c], bd[r + 1][c + 1], bd[r + 2][c + 2], bd[r + 3][c + 3])) return bd[r][c];
}
}
for (let r = 3; r < 6; r++) {
for (let c = 0; c < 4; c++) {
if (checkLine(bd[r][c], bd[r - 1][c + 1], bd[r - 2][c + 2], bd[r - 3][c + 3])) return bd[r][c];
}
}
return null;
}

function generateBoard() {
const arr = [];
for (let i = 0; i < 6; i++) {
Expand Down Expand Up @@ -203,7 +175,6 @@ class Connect4 extends Command {
const playerTwo = opponent.user;
const board = generateBoard();
let lastMove = 'None';
let gameOver = false;
let winner = null;

// Global var for updating the collected interaction
Expand Down Expand Up @@ -249,13 +220,11 @@ class Connect4 extends Command {
let displayName = opponentUser.displayName;

// Replace content and move if the game is over
if (gameOver) {
if (AIEngine.gameStatus().gameOver) {
content = winner ? `Congrats, ${winner}!` : "Looks like it's a draw...";
move = `Final Move: **${lastMove}**`;
displayName = currentUser.displayName;
}

if (opponentUser.bot) {
} else if (opponentUser.bot) {
content = '';
move = `I placed mine in **${lastMove}**.`;
}
Expand All @@ -271,7 +240,7 @@ class Connect4 extends Command {
`,
);

const buttons = await getButtons(gameOver);
const buttons = await getButtons(AIEngine.gameStatus().gameOver);

// Return an object without content built in so it doesn't edit a space
if (!content) return { embeds: [embed], components: buttons };
Expand All @@ -287,7 +256,7 @@ class Connect4 extends Command {
let currentEmoji;
let opponentEmoji;

while (!gameOver && board.some((row) => row.includes(null))) {
while (!AIEngine.gameStatus().gameOver && board.some((row) => row.includes(null))) {
let sign;
if (turn === 1) {
currentUser = playerOne;
Expand Down Expand Up @@ -317,9 +286,8 @@ class Connect4 extends Command {
const content = await getContent(currentUser, opponentUser, opponentEmoji, currentEmoji);
await collected.editReply(content).catch(console.error);

if (verifyWin(board)) {
if (AIEngine.winner) {
winner = currentUser;
gameOver = true;
break;
}
turn === 1 ? (turn = 2) : (turn = 1);
Expand All @@ -337,7 +305,7 @@ class Connect4 extends Command {

if (!collected) {
// They never pressed the button, end the game due to time and edit the message directly since collected doesn't exist
gameOver = true;
AIEngine.gameOver = true;
winner = 'time';
this.client.games.delete(msg.channel.id);

Expand All @@ -362,7 +330,7 @@ class Connect4 extends Command {
} else if (selectedColumn.toLowerCase() === 'stop') {
// The player pressed the stop sign, stop the game and let the other person win.
winner = opponentUser;
gameOver = true;
AIEngine.gameOver = true;
break;
} else {
i = Number.parseInt(selectedColumn, 10) - 1;
Expand All @@ -383,9 +351,8 @@ class Connect4 extends Command {
colLevels[i]--;

// Check if the last move made them a winner, stop the game
if (verifyWin(board)) {
if (AIEngine.winner) {
winner = currentUser;
gameOver = true;
break;
}

Expand Down
16 changes: 8 additions & 8 deletions commands/General/reminders.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ class Reminders extends Command {
}
}

em.setTitle(`To delete a reminder, use **\`${msg.settings.prefix}reminders <ID>\`**`);
em.setTitle(`To delete a reminder, use **\`${msg.settings.prefix}reminders <ID>\`**`).setColor(
msg.settings.embedColor,
);

if (em?.data?.fields?.length !== 0) {
em.setAuthor({ name: msg.author.username, iconURL: msg.author.displayAvatarURL() });
Expand All @@ -85,7 +87,6 @@ class Reminders extends Command {
`${msg.author.username}, you don't have any reminders, use the **remindme** command to create a new one!`,
);
}
em.setColor(msg.settings.embedColor);

return msg.channel.send({ embeds: [em] });
}
Expand All @@ -94,16 +95,15 @@ class Reminders extends Command {
const reminder = await db.get(`global.reminders.${ID}`);

if (!ID) {
em.setColor(errorColor);
em.setDescription(`${msg.author.username}, that isn't a valid reminder.`);
em.setColor(errorColor).setDescription(`${msg.author.username}, that isn't a valid reminder.`);
} else if (!reminder || reminder.userID !== msg.author.id) {
em.setColor(errorColor);
em.setDescription(`${msg.author.username}, that isn't a valid reminder.`);
em.setColor(errorColor).setDescription(`${msg.author.username}, that isn't a valid reminder.`);
} else {
await db.delete(`global.reminders.${ID}`);

em.setColor(msg.settings.embedSuccessColor);
em.setDescription(`${msg.member.displayName}, you've successfully deleted your reminder.`);
em.setColor(msg.settings.embedSuccessColor).setDescription(
`${msg.member.displayName}, you've successfully deleted your reminder.`,
);
}
return msg.channel.send({ embeds: [em] });
}
Expand Down
6 changes: 3 additions & 3 deletions commands/General/remindme.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { EmbedBuilder, ChannelType } = require('discord.js');
const { EmbedBuilder } = require('discord.js');
const Command = require('../../base/Command.js');
const { QuickDB } = require('quick.db');
const chrono = require('chrono-node');
Expand Down Expand Up @@ -63,10 +63,10 @@ class RemindMe extends Command {
const originalMessage = await msg.channel.send({ embeds: [embed] }).catch(() => {});

const obj = {
channelID: msg.channel.type === ChannelType.DM ? null : msg.channel.id,
channelID: msg.channel.id || null,
createdAt: now.getTime(),
userID: msg.author.id,
guild: msg.guild.id,
guildID: msg.guild.id,
reminder: message,
triggerOn: start,
originalMessage,
Expand Down
96 changes: 51 additions & 45 deletions commands/Moderator/blacklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,52 +52,58 @@ class Blacklist extends Command {
.setColor(msg.settings.embedColor)
.setTimestamp();

if (type === 'add') {
// Add member to blacklist
if (blacklist) {
return msg.channel.send('That user is already blacklisted.');
switch (type) {
case 'add': {
// Add member to blacklist
if (blacklist) {
return msg.channel.send('That user is already blacklisted.');
}
if (!reason) return this.client.util.errorEmbed(msg, msg.settings.prefix + this.help.usage, 'Invalid Reason');

await db.set(`servers.${msg.guild.id}.users.${mem.id}.blacklist`, true);
await db.set(`servers.${msg.guild.id}.users.${mem.id}.blacklistReason`, reason);

embed.setTitle(`${memberName} has been added to the blacklist.`).addFields([
{ name: 'Reason:', value: reason },
{ name: 'Member:', value: `${mem.displayName} \n(${mem.id})` },
{ name: 'Server:', value: `${msg.guild.name} \n(${msg.guild.id})` },
]);

msg.channel.send({ embeds: [embed] });
return mem.send({ embeds: [embed] });
}

case 'remove': {
// remove member from blacklist
if (!blacklist) return msg.channel.send('That user is not blacklisted');
if (!reason) return this.client.util.errorEmbed(msg, msg.settings.prefix + this.help.usage, 'Invalid Reason');

await db.set(`servers.${msg.guild.id}.users.${mem.id}.blacklist`, false);
await db.set(`servers.${msg.guild.id}.users.${mem.id}.blacklistReason`, reason);

embed.setTitle(`${memberName} has been removed to the blacklist.`).addFields([
{ name: 'Reason:', value: reason },
{ name: 'Member:', value: `${mem.displayName} \n(${mem.id})` },
{ name: 'Server:', value: `${msg.guild.name} \n(${msg.guild.id})` },
]);

msg.channel.send({ embeds: [embed] });
return mem.send({ embeds: [embed] });
}

case 'check': {
// check if member is blacklisted
const reason = (await db.get(`servers.${msg.guild.id}.users.${mem.id}.blacklistReason`)) || false;

const bl = blacklist ? 'is' : 'is not';
embed.setTitle(`${memberName} blacklist check`).addFields([
{ name: 'Member:', value: `${memberName} (${mem.id})`, inline: true },
{ name: 'Is Blacklisted?', value: `That user ${bl} blacklisted.` },
]);
if (reason) embed.addFields([{ name: 'reason', value: reason, inline: true }]);

return msg.channel.send({ embeds: [embed] });
}
if (!reason) return this.client.util.errorEmbed(msg, msg.settings.prefix + this.help.usage, 'Invalid Reason');

await db.set(`servers.${msg.guild.id}.users.${mem.id}.blacklist`, true);
await db.set(`servers.${msg.guild.id}.users.${mem.id}.blacklistReason`, reason);

embed.setTitle(`${memberName} has been added to the blacklist.`).addFields([
{ name: 'Reason:', value: reason },
{ name: 'Member:', value: `${mem.displayName} \n(${mem.id})` },
{ name: 'Server:', value: `${msg.guild.name} \n(${msg.guild.id})` },
]);

msg.channel.send({ embeds: [embed] });
return mem.send({ embeds: [embed] });
} else if (type === 'remove') {
// remove member from blacklist
if (!blacklist) return msg.channel.send('That user is not blacklisted');
if (!reason) return this.client.util.errorEmbed(msg, msg.settings.prefix + this.help.usage, 'Invalid Reason');

await db.set(`servers.${msg.guild.id}.users.${mem.id}.blacklist`, false);
await db.set(`servers.${msg.guild.id}.users.${mem.id}.blacklistReason`, reason);

embed.setTitle(`${memberName} has been removed to the blacklist.`).addFields([
{ name: 'Reason:', value: reason },
{ name: 'Member:', value: `${mem.displayName} \n(${mem.id})` },
{ name: 'Server:', value: `${msg.guild.name} \n(${msg.guild.id})` },
]);

msg.channel.send({ embeds: [embed] });
return mem.send({ embeds: [embed] });
} else if (type === 'check') {
// check if member is blacklisted
const reason = (await db.get(`servers.${msg.guild.id}.users.${mem.id}.blacklistReason`)) || false;

const bl = blacklist ? 'is' : 'is not';
embed.setTitle(`${memberName} blacklist check`).addFields([
{ name: 'Member:', value: `${memberName} (${mem.id})`, inline: true },
{ name: 'Is Blacklisted?', value: `That user ${bl} blacklisted.` },
]);
if (reason) embed.addFields([{ name: 'reason', value: reason, inline: true }]);

return msg.channel.send({ embeds: [embed] });
}
}
}
Expand Down
Loading

0 comments on commit a4793fd

Please sign in to comment.