Skip to content

Commit

Permalink
Merge pull request #68 from saiteja-madha/bug-fixes
Browse files Browse the repository at this point in the history
Bug fixes
  • Loading branch information
saiteja-madha authored Dec 8, 2021
2 parents e1eb859 + a2b98c8 commit 0ab32c9
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 25 deletions.
1 change: 1 addition & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = {
BASE_API: "https://image-api.strangebot.xyz",
},
MUSIC: {
IDLE_TIME: 60, // Time in seconds before the bot disconnects from the voice channel
MAX_SEARCH_RESULTS: 5,
NODES: [
{
Expand Down
6 changes: 3 additions & 3 deletions dashboard/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ async function fetchGuild(guildID, client, guilds) {
async function fetchUser(userData, client, query) {
if (userData.guilds) {
userData.guilds.forEach((guild) => {
const perms = new Discord.Permissions(BigInt(guild.permissions));
if (perms.has("MANAGE_GUILD")) {
guild.admin = true;
if (guild.permissions) {
const perms = new Discord.Permissions(BigInt(guild.permissions));
if (perms.has("MANAGE_GUILD")) guild.admin = true;
}
guild.settingsUrl = client.guilds.cache.get(guild.id)
? `/manage/${guild.id}/`
Expand Down
3 changes: 0 additions & 3 deletions src/commands/admin/greeting/farewell.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,7 @@ async function setDescription(settings, desc) {

async function setThumbnail(settings, status) {
settings.farewell.embed.thumbnail = status.toUpperCase() === "ON" ? true : false;

settings.farewell.embed.thumbnail = null;
await settings.save();

return "Configuration saved! Farewell message updated";
}

Expand Down
3 changes: 0 additions & 3 deletions src/commands/admin/greeting/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,7 @@ async function setDescription(settings, desc) {

async function setThumbnail(settings, status) {
settings.welcome.embed.thumbnail = status.toUpperCase() === "ON" ? true : false;

settings.welcome.embed.thumbnail = null;
await settings.save();

return "Configuration saved! Welcome message updated";
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/admin/ticket/ticket.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ module.exports = class Ticket extends Command {
if (args.length < 2) return message.reply("Please provide a channel where ticket logs must be sent");
const target = getMatchingChannel(message.guild, args[1]);
if (target.length === 0) return message.reply("Could not find any matching channel");
response = await setupLogChannel(message, target);
response = await setupLogChannel(message, target[0]);
}

// Set limit
Expand Down
7 changes: 5 additions & 2 deletions src/commands/fun/facts.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = class FactCommand extends Command {
command: {
enabled: true,
usage: "<animal>",
aliases: ["fact"],
minArgsCount: 1,
},
slashCommand: {
Expand Down Expand Up @@ -61,10 +62,12 @@ async function getFact(user, choice) {
const response = await getJson(`${BASE_URL}/${choice}`);
if (!response.success) return MESSAGES.API_ERROR;

const imageUrl = response.data?.fact;
const fact = response.data?.fact;
const imageUrl = response.data?.image;
const embed = new MessageEmbed()
.setColor(EMBED_COLORS.TRANSPARENT)
.setImage(imageUrl)
.setThumbnail(imageUrl)
.setDescription(fact)
.setFooter(`Requested by ${user.tag}`);

return { embeds: [embed] };
Expand Down
2 changes: 1 addition & 1 deletion src/commands/information/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ module.exports = class PingCommand extends Command {
super(client, {
name: "ping",
description: "shows the current ping from the bot to the discord servers",
category: "INFORMATION",
command: {
enabled: true,
category: "INFORMATION",
},
slashCommand: {
enabled: true,
Expand Down
8 changes: 4 additions & 4 deletions src/commands/utility/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,29 +171,29 @@ const waiter = (msg, userId, prefix) => {
arrEmbeds = prefix ? getMsgCategoryEmbeds(msg.client, cat, prefix) : getSlashCategoryEmbeds(msg.client, cat);
currentPage = 0;
buttonsRow.components.forEach((button) => button.setDisabled(arrEmbeds.length > 1 ? false : true));
await msg.edit({ embeds: [arrEmbeds[currentPage]], components: [menuRow, buttonsRow] });
msg.editable && (await msg.edit({ embeds: [arrEmbeds[currentPage]], components: [menuRow, buttonsRow] }));
break;
}

case "previousBtn":
if (currentPage !== 0) {
--currentPage;
await msg.edit({ embeds: [arrEmbeds[currentPage]], components: [menuRow, buttonsRow] });
msg.editable && (await msg.edit({ embeds: [arrEmbeds[currentPage]], components: [menuRow, buttonsRow] }));
}
break;

case "nextBtn":
if (currentPage < arrEmbeds.length - 1) {
currentPage++;
await msg.edit({ embeds: [arrEmbeds[currentPage]], components: [menuRow, buttonsRow] });
msg.editable && (await msg.edit({ embeds: [arrEmbeds[currentPage]], components: [menuRow, buttonsRow] }));
}
break;
}
});

collector.on("end", () => {
if (cache[`${msg.guildId}|${userId}`]) delete cache[`${msg.guildId}|${userId}`];
return msg.edit({ components: [] });
return msg.editable && msg.edit({ components: [] });
});
};

Expand Down
4 changes: 2 additions & 2 deletions src/events/guild/guildDelete.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const { getSettings } = require("@schemas/Guild");
* @param {import('discord.js').Guild} guild
*/
module.exports = async (client, guild) => {
if (!guild.members.cache.has(guild.ownerId)) await guild.fetchOwner({ cache: true });
client.logger.log(`Guild Left: ${guild.name} Members: ${guild.memberCount}`);

const settings = await getSettings(guild);
Expand All @@ -15,13 +14,14 @@ module.exports = async (client, guild) => {

if (!client.joinLeaveWebhook) return;

const owner = await client.users.fetch(guild.ownerId);
const embed = new MessageEmbed()
.setTitle("Guild Left")
.setThumbnail(guild.iconURL())
.setColor(client.config.EMBED_COLORS.ERROR)
.addField("Name", guild.name, false)
.addField("ID", guild.id, false)
.addField("Owner", `${client.users.cache.get(guild.ownerId).tag} [\`${guild.ownerId}\`]`, false)
.addField("Owner", `${owner.username}#${owner.discriminator} [\`${owner.id}\`]`, false)
.addField("Members", `\`\`\`yaml\n${guild.memberCount}\`\`\``, false)
.setFooter(`Guild #${client.guilds.cache.size}`);

Expand Down
3 changes: 3 additions & 0 deletions src/events/ready.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { counterHandler, inviteHandler } = require("@src/handlers");
const { cacheReactionRoles } = require("@schemas/Message");
const { getSettings } = require("@schemas/Guild");
const { updateCounterChannels } = require("@src/handlers/counter");

/**
* @param {import('@src/structures').BotClient} client
Expand Down Expand Up @@ -38,6 +39,8 @@ module.exports = async (client) => {
inviteHandler.cacheGuildInvites(guild);
}
}

setInterval(() => updateCounterChannels(client), 10 * 60 * 1000);
};

/**
Expand Down
6 changes: 4 additions & 2 deletions src/events/voice/voiceStateUpdate.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { MUSIC } = require("@root/config");

/**
* @param {import('@src/structures').BotClient} client
* @param {import('discord.js').VoiceState} oldState
Expand All @@ -10,12 +12,12 @@ module.exports = async (client, oldState, newState) => {
if (oldState.channelId !== guild.me.voice.channelId || newState.channel) return;

// otherwise, check how many people are in the channel now
if (!oldState.channel.members.size - 1) {
if (oldState.channel.members.size === 1) {
setTimeout(() => {
// if 1 (you), wait 1 minute
if (!oldState.channel.members.size - 1)
// if there's still 1 member,
client.musicManager.get(guild.id) && client.musicManager.get(guild.id).destroy();
}, 1 * 60 * 1000); // (check and disconnect after 1 min)
}, MUSIC.IDLE_TIME * 1000);
}
};
5 changes: 4 additions & 1 deletion src/helpers/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ simpleLogger.setLevel("debug");
const errorWebhook = process.env.ERROR_LOGS ? new WebhookClient({ url: process.env.ERROR_LOGS }) : undefined;

const sendWebhook = (content, err) => {
if (!content && !err) return;
const errString = err?.stack || err;

const embed = new MessageEmbed()
.setColor(config.EMBED_COLORS.ERROR)
.setAuthor(err?.name || "Error")
.setDescription("```js\n" + err?.stack || err + "```");
.setDescription("```js\n" + (errString.length > 4096 ? `${errString.substr(0, 4000)}...` : errString) + "\n```");

if (err?.description) embed.addField("Description", content);
if (err?.message) embed.addField("Message", err?.message);
Expand Down
2 changes: 1 addition & 1 deletion src/structures/Command.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class Command {
try {
await this.messageRun(message, args, invoke, prefix);
} catch (ex) {
await message.reply("Oops! An error occurred while running the command");
await message.channel.send("Oops! An error occurred while running the command");
this.client.logger.error("messageRun", ex);
} finally {
this.applyCooldown(message.author.id);
Expand Down
4 changes: 2 additions & 2 deletions src/utils/botUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ async function sendMessage(channel, content, seconds) {
if (content.embeds && content.embeds.length > 0) perms.push("EMBED_LINKS");
if (channel.type !== "DM" && !channel.permissionsFor(channel.guild.me).has(perms)) return;
try {
if (!seconds) return channel.send(content);
if (!seconds) return await channel.send(content);
const reply = await channel.send(content);
setTimeout(() => reply.deletable && reply.delete().catch((ex) => {}), seconds * 1000);
} catch (ex) {
Expand All @@ -92,7 +92,7 @@ async function safeDM(user, message, seconds) {
if (!user || !message) return;
try {
const dm = await user.createDM();
if (!seconds) return dm.send(message);
if (!seconds) return await dm.send(message);
const reply = await dm.send(message);
setTimeout(() => reply.deletable && reply.delete().catch((ex) => {}), seconds * 1000);
} catch (ex) {
Expand Down

0 comments on commit 0ab32c9

Please sign in to comment.