Initial Oceanic port (still unfinished), update packages, remove serverinfo and userinfo
This commit is contained in:
parent
bf90ae108a
commit
888f2f8b4a
49 changed files with 573 additions and 515 deletions
|
@ -25,7 +25,7 @@ export default async (client, interaction) => {
|
|||
// eslint-disable-next-line no-unused-vars
|
||||
const commandClass = new cmd(client, { type: "application", interaction });
|
||||
const result = await commandClass.run();
|
||||
const replyMethod = interaction.acknowledged ? "editOriginalMessage" : "createMessage";
|
||||
const replyMethod = interaction.acknowledged ? "editOriginal" : "createMessage";
|
||||
if (typeof result === "string") {
|
||||
await interaction[replyMethod]({
|
||||
content: result,
|
||||
|
@ -35,9 +35,9 @@ export default async (client, interaction) => {
|
|||
await interaction[replyMethod](Object.assign(result, {
|
||||
flags: result.flags ?? (commandClass.success ? 0 : 64)
|
||||
}));
|
||||
} else if (typeof result === "object" && result.file) {
|
||||
} else if (typeof result === "object" && result.contents) {
|
||||
const fileSize = 8388119;
|
||||
if (result.file.length > fileSize) {
|
||||
if (result.contents.length > fileSize) {
|
||||
if (process.env.TEMPDIR && process.env.TEMPDIR !== "") {
|
||||
await upload(client, result, interaction, true);
|
||||
} else {
|
||||
|
@ -47,11 +47,11 @@ export default async (client, interaction) => {
|
|||
});
|
||||
}
|
||||
} else {
|
||||
await interaction[replyMethod](result.text ? result.text : {}, result);
|
||||
await interaction[replyMethod](result.text ? result.text : { files: [result] });
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
const replyMethod = interaction.acknowledged ? "editOriginalMessage" : "createMessage";
|
||||
const replyMethod = interaction.acknowledged ? "editOriginal" : "createMessage";
|
||||
if (error.toString().includes("Request entity too large")) {
|
||||
await interaction[replyMethod]({ content: "The resulting file was too large to upload. Try again with a smaller image if possible.", flags: 64 });
|
||||
} else if (error.toString().includes("Job ended prematurely")) {
|
||||
|
@ -63,11 +63,16 @@ export default async (client, interaction) => {
|
|||
try {
|
||||
let err = error;
|
||||
if (error?.constructor?.name == "Promise") err = await error;
|
||||
await interaction[replyMethod]("Uh oh! I ran into an error while running this command. Please report the content of the attached file at the following link or on the esmBot Support server: <https://github.com/esmBot/esmBot/issues>", {
|
||||
file: `Message: ${clean(err)}\n\nStack Trace: ${clean(err.stack)}`,
|
||||
name: "error.txt"
|
||||
await interaction[replyMethod]({
|
||||
content: "Uh oh! I ran into an error while running this command. Please report the content of the attached file at the following link or on the esmBot Support server: <https://github.com/esmBot/esmBot/issues>",
|
||||
files: [{
|
||||
contents: `Message: ${clean(err)}\n\nStack Trace: ${clean(err.stack)}`,
|
||||
name: "error.txt"
|
||||
}]
|
||||
});
|
||||
} catch { /* silently ignore */ }
|
||||
} catch (e) {
|
||||
logger.error(`While attempting to send the previous error message, another error occurred: ${e.stack || e}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -2,7 +2,7 @@ import database from "../utils/database.js";
|
|||
import { log, error as _error } from "../utils/logger.js";
|
||||
import { prefixCache, aliases, disabledCache, disabledCmdCache, commands } from "../utils/collections.js";
|
||||
import parseCommand from "../utils/parseCommand.js";
|
||||
import { clean } from "../utils/misc.js";
|
||||
import { clean, cleanMessage } from "../utils/misc.js";
|
||||
import { upload } from "../utils/tempimages.js";
|
||||
|
||||
// run when someone sends a message
|
||||
|
@ -11,28 +11,28 @@ export default async (client, message) => {
|
|||
if (message.author.bot) return;
|
||||
|
||||
// don't run command if bot can't send messages
|
||||
if (message.channel.guild && !message.channel.permissionsOf(client.user.id).has("sendMessages")) return;
|
||||
if (message.guildID && !message.channel.permissionsOf(client.user.id.toString()).has("SEND_MESSAGES")) return;
|
||||
|
||||
let prefixCandidate;
|
||||
let guildDB;
|
||||
if (message.channel.guild) {
|
||||
const cachedPrefix = prefixCache.get(message.channel.guild.id);
|
||||
if (message.guildID) {
|
||||
const cachedPrefix = prefixCache.get(message.guildID);
|
||||
if (cachedPrefix) {
|
||||
prefixCandidate = cachedPrefix;
|
||||
} else {
|
||||
guildDB = await database.getGuild(message.channel.guild.id);
|
||||
guildDB = await database.getGuild(message.guildID);
|
||||
if (!guildDB) {
|
||||
guildDB = await database.fixGuild(message.channel.guild);
|
||||
guildDB = await database.fixGuild(message.guildID);
|
||||
}
|
||||
prefixCandidate = guildDB.prefix;
|
||||
prefixCache.set(message.channel.guild.id, guildDB.prefix);
|
||||
prefixCache.set(message.guildID, guildDB.prefix);
|
||||
}
|
||||
}
|
||||
|
||||
let prefix;
|
||||
let isMention = false;
|
||||
if (message.channel.guild) {
|
||||
const user = message.channel.guild.members.get(client.user.id);
|
||||
if (message.guildID) {
|
||||
const user = message.guild.members.get(client.user.id);
|
||||
if (message.content.startsWith(user.mention)) {
|
||||
prefix = `${user.mention} `;
|
||||
isMention = true;
|
||||
|
@ -50,8 +50,8 @@ export default async (client, message) => {
|
|||
if (!message.content.startsWith(prefix)) return;
|
||||
|
||||
// separate commands and args
|
||||
const replace = isMention ? `@${(message.channel.guild ? message.channel.guild.members.get(client.user.id).nick : client.user.username) ?? client.user.username} ` : prefix;
|
||||
const content = message.cleanContent.substring(replace.length).trim();
|
||||
const replace = isMention ? `@${(message.guild ? message.guild.members.get(client.user.id).nick : client.user.username) ?? client.user.username} ` : prefix;
|
||||
const content = cleanMessage(message).substring(replace.length).trim();
|
||||
const rawContent = message.content.substring(prefix.length).trim();
|
||||
const preArgs = content.split(/\s+/g);
|
||||
preArgs.shift();
|
||||
|
@ -60,22 +60,22 @@ export default async (client, message) => {
|
|||
const aliased = aliases.get(command);
|
||||
|
||||
// don't run if message is in a disabled channel
|
||||
if (message.channel.guild) {
|
||||
const disabled = disabledCache.get(message.channel.guild.id);
|
||||
if (message.guildID) {
|
||||
const disabled = disabledCache.get(message.guildID);
|
||||
if (disabled) {
|
||||
if (disabled.includes(message.channel.id) && command != "channel") return;
|
||||
if (disabled.includes(message.channelID) && command != "channel") return;
|
||||
} else {
|
||||
guildDB = await database.getGuild(message.channel.guild.id);
|
||||
disabledCache.set(message.channel.guild.id, guildDB.disabled);
|
||||
if (guildDB.disabled.includes(message.channel.id) && command !== "channel") return;
|
||||
guildDB = await database.getGuild(message.guildID);
|
||||
disabledCache.set(message.guildID, guildDB.disabled);
|
||||
if (guildDB.disabled.includes(message.channelID) && command !== "channel") return;
|
||||
}
|
||||
|
||||
const disabledCmds = disabledCmdCache.get(message.channel.guild.id);
|
||||
const disabledCmds = disabledCmdCache.get(message.guildID);
|
||||
if (disabledCmds) {
|
||||
if (disabledCmds.includes(aliased ?? command)) return;
|
||||
} else {
|
||||
guildDB = await database.getGuild(message.channel.guild.id);
|
||||
disabledCmdCache.set(message.channel.guild.id, guildDB.disabled_commands ?? guildDB.disabledCommands);
|
||||
guildDB = await database.getGuild(message.guildID);
|
||||
disabledCmdCache.set(message.guildID, guildDB.disabled_commands ?? guildDB.disabledCommands);
|
||||
if ((guildDB.disabled_commands ?? guildDB.disabledCommands).includes(aliased ?? command)) return;
|
||||
}
|
||||
}
|
||||
|
@ -85,15 +85,15 @@ export default async (client, message) => {
|
|||
if (!cmd) return;
|
||||
|
||||
// block certain commands from running in DMs
|
||||
if (!cmd.directAllowed && !message.channel.guild) return;
|
||||
if (!cmd.directAllowed && !message.guildID) return;
|
||||
|
||||
// actually run the command
|
||||
log("log", `${message.author.username} (${message.author.id}) ran classic command ${command}`);
|
||||
const reference = {
|
||||
messageReference: {
|
||||
channelID: message.channel.id,
|
||||
channelID: message.channelID,
|
||||
messageID: message.id,
|
||||
guildID: message.channel.guild ? message.channel.guild.id : undefined,
|
||||
guildID: message.guildID ?? undefined,
|
||||
failIfNotExists: false
|
||||
},
|
||||
allowedMentions: {
|
||||
|
@ -110,15 +110,15 @@ export default async (client, message) => {
|
|||
if ((endTime - startTime) >= 180000) reference.allowedMentions.repliedUser = true;
|
||||
if (typeof result === "string") {
|
||||
reference.allowedMentions.repliedUser = true;
|
||||
await client.createMessage(message.channel.id, Object.assign({
|
||||
await client.rest.channels.createMessage(message.channelID, Object.assign({
|
||||
content: result
|
||||
}, reference));
|
||||
} else if (typeof result === "object" && result.embeds) {
|
||||
await client.createMessage(message.channel.id, Object.assign(result, reference));
|
||||
} else if (typeof result === "object" && result.file) {
|
||||
await client.rest.channels.createMessage(message.channelID, Object.assign(result, reference));
|
||||
} else if (typeof result === "object" && result.contents) {
|
||||
let fileSize = 8388119;
|
||||
if (message.channel.guild) {
|
||||
switch (message.channel.guild.premiumTier) {
|
||||
if (message.guildID) {
|
||||
switch (message.guild.premiumTier) {
|
||||
case 2:
|
||||
fileSize = 52428308;
|
||||
break;
|
||||
|
@ -127,42 +127,44 @@ export default async (client, message) => {
|
|||
break;
|
||||
}
|
||||
}
|
||||
if (result.file.length > fileSize) {
|
||||
if (result.contents.length > fileSize) {
|
||||
if (process.env.TEMPDIR && process.env.TEMPDIR !== "") {
|
||||
await upload(client, result, message);
|
||||
} else {
|
||||
await client.createMessage(message.channel.id, "The resulting image was more than 8MB in size, so I can't upload it.");
|
||||
await client.rest.channels.createMessage(message.channelID, "The resulting image was more than 8MB in size, so I can't upload it.");
|
||||
}
|
||||
} else {
|
||||
await client.createMessage(message.channel.id, Object.assign({
|
||||
content: result.text ? result.text : undefined
|
||||
}, reference), result);
|
||||
await client.rest.channels.createMessage(message.channelID, Object.assign({
|
||||
content: result.text ? result.text : undefined,
|
||||
files: [result]
|
||||
}, reference));
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.toString().includes("Request entity too large")) {
|
||||
await client.createMessage(message.channel.id, Object.assign({
|
||||
await client.rest.channels.createMessage(message.channelID, Object.assign({
|
||||
content: "The resulting file was too large to upload. Try again with a smaller image if possible."
|
||||
}, reference));
|
||||
} else if (error.toString().includes("Job ended prematurely")) {
|
||||
await client.createMessage(message.channel.id, Object.assign({
|
||||
await client.rest.channels.createMessage(message.channelID, Object.assign({
|
||||
content: "Something happened to the image servers before I could receive the image. Try running your command again."
|
||||
}, reference));
|
||||
} else if (error.toString().includes("Timed out")) {
|
||||
await client.createMessage(message.channel.id, Object.assign({
|
||||
await client.rest.channels.createMessage(message.channelID, Object.assign({
|
||||
content: "The request timed out before I could download that image. Try uploading your image somewhere else or reducing its size."
|
||||
}, reference));
|
||||
} else {
|
||||
_error(`Error occurred with command message ${message.cleanContent}: ${error.stack || error}`);
|
||||
_error(`Error occurred with command message ${message.content}: ${error.stack || error}`);
|
||||
try {
|
||||
let err = error;
|
||||
if (error?.constructor?.name == "Promise") err = await error;
|
||||
await client.createMessage(message.channel.id, Object.assign({
|
||||
content: "Uh oh! I ran into an error while running this command. Please report the content of the attached file at the following link or on the esmBot Support server: <https://github.com/esmBot/esmBot/issues>"
|
||||
}, reference), [{
|
||||
file: `Message: ${clean(err)}\n\nStack Trace: ${clean(err.stack)}`,
|
||||
await client.rest.channels.createMessage(message.channelID, Object.assign({
|
||||
content: "Uh oh! I ran into an error while running this command. Please report the content of the attached file at the following link or on the esmBot Support server: <https://github.com/esmBot/esmBot/issues>",
|
||||
files: [{
|
||||
contents: `Message: ${clean(err)}\n\nStack Trace: ${clean(err.stack)}`,
|
||||
name: "error.txt"
|
||||
}]);
|
||||
}]
|
||||
}, reference));
|
||||
} catch (e) {
|
||||
_error(`While attempting to send the previous error message, another error occurred: ${e.stack || e}`);
|
||||
}
|
||||
|
|
|
@ -6,21 +6,25 @@ const isWaiting = new Map();
|
|||
|
||||
export default async (client, member, oldChannel) => {
|
||||
if (!oldChannel) return;
|
||||
const connection = players.get(oldChannel.guild.id);
|
||||
const connection = players.get(oldChannel.guildID);
|
||||
if (oldChannel.id === connection?.voiceChannel.id) {
|
||||
if (oldChannel.voiceMembers.filter((i) => i.id !== client.user.id && !i.bot).length === 0) {
|
||||
if (isWaiting.has(oldChannel.id)) return;
|
||||
isWaiting.set(oldChannel.id, true);
|
||||
connection.player.setPaused(true);
|
||||
const waitMessage = await client.createMessage(connection.originalChannel.id, "🔊 Waiting 10 seconds for someone to return...");
|
||||
const waitMessage = await client.rest.channels.createMessage(connection.originalChannel.id, {
|
||||
content: "🔊 Waiting 10 seconds for someone to return..."
|
||||
});
|
||||
const awaitRejoin = new AwaitRejoin(oldChannel, true, member.id);
|
||||
awaitRejoin.on("end", async (rejoined, newMember) => {
|
||||
isWaiting.delete(oldChannel.id);
|
||||
if (rejoined) {
|
||||
connection.player.setPaused(false);
|
||||
if (member.id !== newMember.id) {
|
||||
players.set(connection.voiceChannel.guild.id, { player: connection.player, type: connection.type, host: newMember.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel, loop: connection.loop, shuffle: connection.shuffle, playMessage: connection.playMessage });
|
||||
waitMessage.edit(`🔊 ${newMember.mention} is the new voice channel host.`);
|
||||
players.set(connection.voiceChannel.guildID, { player: connection.player, type: connection.type, host: newMember.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel, loop: connection.loop, shuffle: connection.shuffle, playMessage: connection.playMessage });
|
||||
waitMessage.edit({
|
||||
content: `🔊 ${newMember.mention} is the new voice channel host.`
|
||||
});
|
||||
} else {
|
||||
try {
|
||||
await waitMessage.delete();
|
||||
|
@ -35,20 +39,24 @@ export default async (client, member, oldChannel) => {
|
|||
// no-op
|
||||
}
|
||||
try {
|
||||
connection.player.node.leaveChannel(connection.originalChannel.guild.id);
|
||||
connection.player.node.leaveChannel(connection.originalChannel.guildID);
|
||||
} catch {
|
||||
// no-op
|
||||
}
|
||||
players.delete(connection.originalChannel.guild.id);
|
||||
queues.delete(connection.originalChannel.guild.id);
|
||||
skipVotes.delete(connection.originalChannel.guild.id);
|
||||
client.createMessage(connection.originalChannel.id, `🔊 The voice channel session in \`${connection.originalChannel.name}\` has ended.`);
|
||||
players.delete(connection.originalChannel.guildID);
|
||||
queues.delete(connection.originalChannel.guildID);
|
||||
skipVotes.delete(connection.originalChannel.guildID);
|
||||
client.rest.channels.createMessage(connection.originalChannel.id, {
|
||||
content: `🔊 The voice channel session in \`${connection.originalChannel.name}\` has ended.`
|
||||
});
|
||||
}
|
||||
});
|
||||
} else if (member.id === connection.host) {
|
||||
if (isWaiting.has(oldChannel.id)) return;
|
||||
isWaiting.set(oldChannel.id, true);
|
||||
const waitMessage = await client.createMessage(connection.originalChannel.id, "🔊 Waiting 10 seconds for the host to return...");
|
||||
const waitMessage = await client.rest.channels.createMessage(connection.originalChannel.id, {
|
||||
content: "🔊 Waiting 10 seconds for the host to return..."
|
||||
});
|
||||
const awaitRejoin = new AwaitRejoin(oldChannel, false, member.id);
|
||||
awaitRejoin.on("end", async (rejoined) => {
|
||||
isWaiting.delete(oldChannel.id);
|
||||
|
@ -67,32 +75,38 @@ export default async (client, member, oldChannel) => {
|
|||
// no-op
|
||||
}
|
||||
try {
|
||||
connection.player.node.leaveChannel(connection.originalChannel.guild.id);
|
||||
connection.player.node.leaveChannel(connection.originalChannel.guildID);
|
||||
} catch {
|
||||
// no-op
|
||||
}
|
||||
players.delete(connection.originalChannel.guild.id);
|
||||
queues.delete(connection.originalChannel.guild.id);
|
||||
skipVotes.delete(connection.originalChannel.guild.id);
|
||||
client.createMessage(connection.originalChannel.id, `🔊 The voice channel session in \`${connection.originalChannel.name}\` has ended.`);
|
||||
players.delete(connection.originalChannel.guildID);
|
||||
queues.delete(connection.originalChannel.guildID);
|
||||
skipVotes.delete(connection.originalChannel.guildID);
|
||||
client.rest.channels.createMessage(connection.originalChannel.id, {
|
||||
content: `🔊 The voice channel session in \`${connection.originalChannel.name}\` has ended.`
|
||||
});
|
||||
} else {
|
||||
const randomMember = random(members);
|
||||
players.set(connection.voiceChannel.guild.id, { player: connection.player, type: connection.type, host: randomMember.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel, loop: connection.loop, shuffle: connection.shuffle, playMessage: connection.playMessage });
|
||||
waitMessage.edit(`🔊 ${randomMember.mention} is the new voice channel host.`);
|
||||
players.set(connection.voiceChannel.guildID, { player: connection.player, type: connection.type, host: randomMember.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel, loop: connection.loop, shuffle: connection.shuffle, playMessage: connection.playMessage });
|
||||
waitMessage.edit({
|
||||
content: `🔊 ${randomMember.mention} is the new voice channel host.`
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if (member.id === client.user.id) {
|
||||
isWaiting.delete(oldChannel.id);
|
||||
try {
|
||||
connection.player.node.leaveChannel(connection.originalChannel.guild.id);
|
||||
connection.player.node.leaveChannel(connection.originalChannel.guildID);
|
||||
} catch {
|
||||
// no-op
|
||||
}
|
||||
players.delete(connection.originalChannel.guild.id);
|
||||
queues.delete(connection.originalChannel.guild.id);
|
||||
skipVotes.delete(connection.originalChannel.guild.id);
|
||||
await client.createMessage(connection.originalChannel.id, `🔊 The voice channel session in \`${connection.originalChannel.name}\` has ended.`);
|
||||
players.delete(connection.originalChannel.guildID);
|
||||
queues.delete(connection.originalChannel.guildID);
|
||||
skipVotes.delete(connection.originalChannel.guildID);
|
||||
await client.rest.channels.createMessage(connection.originalChannel.id, {
|
||||
content: `🔊 The voice channel session in \`${connection.originalChannel.name}\` has ended.`
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue