hacked together thread support because im impatient

This commit is contained in:
Cynthia Foxwell 2021-08-30 12:01:33 -06:00
parent 336a9abedd
commit 2ee2b46bbf
4 changed files with 52 additions and 30 deletions

View file

@ -1,3 +1,13 @@
// ensure gateway/rest v9
const Constants = require("eris/lib/Constants");
const fixedConstants = Constants;
fixedConstants.GATEWAY_VERSION = 9;
fixedConstants.REST_VERSION = 9;
const constantsPath = require.resolve("eris/lib/Constants");
require.cache[constantsPath].exports = fixedConstants;
const Eris = require("eris");
const logger = require("./lib/logger.js");
const fs = require("fs");
@ -55,9 +65,22 @@ for (const file of fs.readdirSync(resolve(__dirname, "modules"))) {
bot.on("messageCreate", async (msg) => {
// fix DMs cause of gateway v8 changes
if (!(msg.channel instanceof Eris.Channel) && msg.author.id != bot.user.id) {
if (
!(msg.channel instanceof Eris.Channel) &&
msg.author.id != bot.user.id &&
!msg.guildID
) {
const newChannel = await bot.getDMChannel(msg.author.id);
if (msg.channel.id == newChannel.id) msg.channel = newChannel;
} else if (
msg.guildID &&
!bot.guilds.get(msg.guildID).channels.has(msg.channel.id)
) {
const threads = await bot.requestHandler
.request("GET", `/guilds/${msg.guildID}/threads/active`, true)
.then((x) => x.threads);
const thread = threads.filter((x) => x.id == msg.channel.id)[0];
if (thread) msg.channel = new Eris.TextChannel(thread, bot);
}
// if we still have no dm channel (threads cause this too)

View file

@ -38,7 +38,7 @@ async function runCommand(msg, cmd, line, args) {
return "No\n\nSent from my iPhone.";
}
if (cmdObj.guildOnly && !msg.channel.guild) {
if (cmdObj.guildOnly && !msg.guildID) {
return "This command can only be used in guilds.";
}

View file

@ -10,11 +10,12 @@ function pastelize(id) {
}
function getTopColor(msg, id, fallback = 0x7289da) {
if (!msg.channel.guild) return fallback;
if (!msg.guildID) return fallback;
const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID);
const roles = msg.channel.guild.members
const roles = guild.members
.get(id)
.roles.map((role) => msg.channel.guild.roles.get(role))
.roles.map((role) => guild.roles.get(role))
.filter((role) => role.color);
roles.sort((a, b) => b.position - a.position);
@ -282,8 +283,9 @@ async function lookupUser(msg, str, filter) {
let users;
if (filter) {
users = hf.bot.users.filter(filter).values();
} else if (msg.channel.guild) {
users = msg.channel.guild.members.values();
} else if (msg.guildID) {
const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID);
users = guild.members.values();
} else {
users = hf.bot.users.values();
}

View file

@ -69,15 +69,12 @@ avatar.helpText = "Get avatar of a user";
avatar.usage = "<user>";
avatar.callback = async function (msg, line) {
if (line == "--server" || line == "--guild") {
if (!msg.channel.guild) {
if (!msg.guildID) {
return "`--server/--guild` can only be used within guilds.";
} else {
const url = `${ICON_BASE}${msg.channel.guild.id}/${
msg.channel.guild.icon
}.${
msg.channel.guild.icon.startsWith("a_")
? "gif?size=1024&_=.gif"
: "png?size=1024"
const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID);
const url = `${ICON_BASE}${guild.id}/${guild.icon}.${
guild.icon.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024"
}`;
return {
embeds: [
@ -101,11 +98,12 @@ avatar.callback = async function (msg, line) {
return user;
} else {
let member = user;
if (msg.channel.guild) {
if (msg.channel.guild.members.has(user.id)) {
member = msg.channel.guild.members.get(user.id);
const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID);
if (guild) {
if (guild.members.has(user.id)) {
member = guild.members.get(user.id);
} else {
const fetched = await msg.channel.guild.fetchMembers({
const fetched = await guild.fetchMembers({
userIDs: [user.id],
});
member = fetched[0];
@ -113,8 +111,8 @@ avatar.callback = async function (msg, line) {
}
const avatar = member.avatar || member.user.avatar;
const url =
msg.channel.guild && member.avatar
? `https://cdn.discordapp.com/guilds/${msg.channel.guild.id}/users/${
guild && member.avatar
? `https://cdn.discordapp.com/guilds/${guild.id}/users/${
member.id
}/avatars/${member.avatar}.${
member.avatar.startsWith("a_")
@ -137,9 +135,10 @@ avatar.callback = async function (msg, line) {
};
}
} else {
const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID);
const avatar = msg.member.avatar || msg.author.avatar;
const url = msg.member.avatar
? `https://cdn.discordapp.com/guilds/${msg.channel.guild.id}/users/${
? `https://cdn.discordapp.com/guilds/${guild.id}/users/${
msg.member.id
}/avatars/${msg.member.avatar}.${
msg.member.avatar.startsWith("a_")
@ -172,15 +171,12 @@ banner.callback = async function (msg, line) {
let id = msg.author.id;
if (line == "--server" || line == "--guild") {
if (!msg.channel.guild) {
if (!msg.guildID) {
return "`--server/--guild` can only be used within guilds.";
} else {
const url = `${BANNER_BASE}${msg.channel.guild.id}/${
msg.channel.guild.banner
}.${
msg.channel.guild.banner.startsWith("a_")
? "gif?size=1024&_=.gif"
: "png?size=1024"
const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID);
const url = `${BANNER_BASE}${guild.id}/${guild.banner}.${
guild.banner.startsWith("a_") ? "gif?size=1024&_=.gif" : "png?size=1024"
}`;
return {
embeds: [
@ -455,8 +451,9 @@ flagdump.callback = async function (msg, line) {
const num = parseInt(line);
if (/<@!?([0-9]*)>/.test(line)) {
const id = line.match(/<@?!([0-9]*)>/)[1];
let user = await msg.channel.guild.fetchMembers({userIDs: [id]});
if (!user[0]) {
const guild = msg.channel.guild || hf.bot.guilds.get(msg.guildID);
let user = guild && (await guild.fetchMembers({userIDs: [id]}));
if (!user || !user[0]) {
user = hf.bot.users.get(id);
} else {
user = user[0].user;