Some assorted fixes

This commit is contained in:
TheEssem 2021-02-07 11:08:55 -06:00
parent 443da54298
commit e7ffa23411
4 changed files with 25 additions and 26 deletions

View file

@ -60,12 +60,11 @@ exports.getCounts = async () => {
exports.addCount = async (command) => {
const count = await connection.query("SELECT * FROM counts WHERE command = $1", [command]);
if (count.rows[0].count) await connection.query("INSERT INTO counts (command, count) VALUES ($1, $2)", [command, 0]);
await connection.query("UPDATE counts SET count = $1 WHERE command = $2", [count.rows[0].count ? count.rows[0].count + 1 : 1, command]);
};
exports.addGuild = async (guild) => {
await connection.query("INSERT INTO guilds (guild_id, tags, prefix, warns, disabled, tags_disabled) VALUES ($1, $2, $3, $4, $5, $6)", [guild.id, misc.tagDefaults, process.env.PREFIX, {}, [], false]);
await connection.query("INSERT INTO guilds (guild_id, tags, prefix, disabled, tags_disabled) VALUES ($1, $2, $3, $4, $5)", [guild.id, misc.tagDefaults, process.env.PREFIX, [], false]);
return await this.getGuild(guild.id);
};

View file

@ -11,16 +11,16 @@ class ReactionCollector extends EventEmitter {
this.ended = false;
this.collected = [];
this.bot = client;
this.listener = async (message, emoji, userID) => await this.verify(message, emoji, userID);
this.listener = async (message, emoji, member) => await this.verify(message, emoji, member);
this.bot.on("messageReactionAdd", this.listener);
if (options.time) setTimeout(() => this.stop("time"), options.time);
}
async verify(message, emoji, userID) {
async verify(message, emoji, member) {
if (this.message.id !== message.id) return false;
if (this.filter(message, emoji, userID)) {
this.collected.push({ message: message, emoji: emoji, userID: userID });
this.emit("reaction", await client.getMessage(message.channel.id, message.id), emoji, userID);
if (this.filter(message, emoji, member)) {
this.collected.push({ message: message, emoji: emoji, member: member });
this.emit("reaction", await client.getMessage(message.channel.id, message.id), emoji, member);
if (this.collected.length >= this.options.maxMatches) this.stop("maxMatches");
return true;
}

View file

@ -3,21 +3,21 @@ const MessageCollector = require("./awaitmessages.js");
const client = require("../client.js");
module.exports = async (message, pages, timeout = 120000) => {
const manageMessages = message.channel.guild && (message.channel.guild.members.get(client.user.id).permission.has("manageMessages") || message.channel.permissionsOf(client.user.id).has("manageMessages")) ? true : false;
const manageMessages = message.channel.guild && (message.channel.guild.members.get(client.user.id).permissions.has("manageMessages") || message.channel.permissionsOf(client.user.id).has("manageMessages")) ? true : false;
let page = 0;
const currentPage = await message.channel.createMessage(pages[page]);
let currentPage = await message.channel.createMessage(pages[page]);
const emojiList = ["◀", "🔢", "▶", "🗑"];
for (const emoji of emojiList) {
await currentPage.addReaction(emoji);
}
const reactionCollector = new ReactionCollector(currentPage, (message, reaction, user) => emojiList.includes(reaction.name) && !client.users.get(user).bot, { time: timeout });
reactionCollector.on("reaction", (msg, reaction, userID) => {
if (userID === message.author.id) {
const reactionCollector = new ReactionCollector(currentPage, (message, reaction, member) => emojiList.includes(reaction.name) && !member.bot, { time: timeout });
reactionCollector.on("reaction", async (msg, reaction, member) => {
if (member.id === message.author.id) {
switch (reaction.name) {
case "◀":
page = page > 0 ? --page : pages.length - 1;
currentPage.edit(pages[page]);
if (manageMessages) msg.removeReaction("◀", userID);
currentPage = await currentPage.edit(pages[page]);
if (manageMessages) msg.removeReaction("◀", member.id);
break;
case "🔢":
message.channel.createMessage(`${message.author.mention}, what page do you want to jump to?`).then(askMessage => {
@ -25,11 +25,11 @@ module.exports = async (message, pages, timeout = 120000) => {
time: timeout,
maxMatches: 1
});
return messageCollector.on("message", response => {
return messageCollector.on("message", async response => {
if (askMessage.channel.messages.get(askMessage.id)) askMessage.delete();
page = Number(response.content) - 1;
currentPage.edit(pages[page]);
if (manageMessages) msg.removeReaction("🔢", userID);
currentPage = await currentPage.edit(pages[page]);
if (manageMessages) msg.removeReaction("🔢", member.id);
});
}).catch(error => {
throw error;
@ -37,21 +37,21 @@ module.exports = async (message, pages, timeout = 120000) => {
break;
case "▶":
page = page + 1 < pages.length ? ++page : 0;
currentPage.edit(pages[page]);
if (manageMessages) msg.removeReaction("▶", userID);
currentPage = await currentPage.edit(pages[page]);
if (manageMessages) msg.removeReaction("▶", member.id);
break;
case "🗑":
reactionCollector.emit("end");
if (currentPage.channel.messages.get(currentPage.id)) currentPage.delete();
if (currentPage.channel.messages.get(currentPage.id)) await currentPage.delete();
return;
default:
break;
}
}
});
reactionCollector.once("end", () => {
if (message.channel.messages.get(currentPage.id) && manageMessages) {
currentPage.removeReactions();
reactionCollector.once("end", async () => {
if (currentPage.channel.messages.get(currentPage.id) && manageMessages) {
await currentPage.removeReactions();
}
});
return currentPage;

View file

@ -50,7 +50,7 @@ exports.connect = async () => {
exports.play = async (sound, message, music = false) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.voiceState.channelID) return `${message.author.mention}, you need to be in a voice channel first!`;
if (!message.channel.guild.members.get(client.user.id).permission.has("voiceConnect") || !message.channel.permissionsOf(client.user.id).has("voiceConnect")) return `${message.author.mention}, I can't join this voice channel!`;
if (!message.channel.guild.members.get(client.user.id).permissions.has("voiceConnect") || !message.channel.permissionsOf(client.user.id).has("voiceConnect")) return `${message.author.mention}, I can't join this voice channel!`;
const voiceChannel = message.channel.guild.channels.get(message.member.voiceState.channelID);
if (!voiceChannel.permissionsOf(client.user.id).has("voiceConnect")) return `${message.author.mention}, I don't have permission to join this voice channel!`;
const player = this.players.get(message.channel.guild.id);
@ -239,8 +239,8 @@ exports.queue = async (message) => {
if (!message.channel.guild) return `${message.author.mention}, this command only works in servers!`;
if (!message.member.voiceState.channelID) return `${message.author.mention}, you need to be in a voice channel first!`;
if (!message.channel.guild.members.get(client.user.id).voiceState.channelID) return `${message.author.mention}, I'm not in a voice channel!`;
if (!message.channel.guild.members.get(client.user.id).permission.has("addReactions") && !message.channel.permissionsOf(client.user.id).has("addReactions")) return `${message.author.mention}, I don't have the \`Add Reactions\` permission!`;
if (!message.channel.guild.members.get(client.user.id).permission.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`;
if (!message.channel.guild.members.get(client.user.id).permissions.has("addReactions") && !message.channel.permissionsOf(client.user.id).has("addReactions")) return `${message.author.mention}, I don't have the \`Add Reactions\` permission!`;
if (!message.channel.guild.members.get(client.user.id).permissions.has("embedLinks") && !message.channel.permissionsOf(client.user.id).has("embedLinks")) return `${message.author.mention}, I don't have the \`Embed Links\` permission!`;
const queue = this.queues.get(message.channel.guild.id);
const player = this.players.get(message.channel.guild.id);
const tracks = await fetch(`http://${player.player.node.host}:${player.player.node.port}/decodetracks`, { method: "POST", body: JSON.stringify(queue), headers: { Authorization: player.player.node.password, "Content-Type": "application/json" } }).then(res => res.json());