3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Remove hotfixMessageFetch()

This commit is contained in:
Dragory 2021-08-20 20:01:32 +03:00
parent d54f03361a
commit 329cd05652
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
8 changed files with 8 additions and 38 deletions

View file

@ -1,7 +1,6 @@
import { Message, Snowflake, TextChannel, ThreadChannel } from "discord.js";
import { GuildPluginData } from "knub";
import { MessageSaverPluginType } from "./types";
import { hotfixMessageFetch } from "../../utils/hotfixMessageFetch";
export async function saveMessagesToDB(
pluginData: GuildPluginData<MessageSaverPluginType>,
@ -16,7 +15,7 @@ export async function saveMessagesToDB(
let thisMsg: Message;
try {
thisMsg = await hotfixMessageFetch(channel, id as Snowflake);
thisMsg = await channel.messages.fetch(id);
if (!thisMsg) {
failed.push(id);

View file

@ -3,7 +3,6 @@ import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
import { isDiscordAPIError } from "../../../utils";
import { reactionRolesCmd } from "../types";
import { hotfixMessageFetch } from "../../../utils/hotfixMessageFetch";
export const ClearReactionRolesCmd = reactionRolesCmd({
trigger: "reaction_roles clear",
@ -24,7 +23,7 @@ export const ClearReactionRolesCmd = reactionRolesCmd({
let targetMessage: Message;
try {
targetMessage = await hotfixMessageFetch(args.message.channel, args.message.messageId);
targetMessage = await args.message.channel.messages.fetch(args.message.messageId);
} catch (err) {
if (isDiscordAPIError(err) && err.code === 50001) {
sendErrorMessage(pluginData, msg.channel, "Missing access to the specified message");

View file

@ -5,7 +5,6 @@ import { canUseEmoji, isDiscordAPIError, isValidEmoji, noop, trimPluginDescripti
import { canReadChannel } from "../../../utils/canReadChannel";
import { reactionRolesCmd, TReactionRolePair } from "../types";
import { applyReactionRoleReactionsToMessage } from "../util/applyReactionRoleReactionsToMessage";
import { hotfixMessageFetch } from "../../../utils/hotfixMessageFetch";
const CLEAR_ROLES_EMOJI = "❌";
@ -41,7 +40,7 @@ export const InitReactionRolesCmd = reactionRolesCmd({
let targetMessage;
try {
targetMessage = await hotfixMessageFetch(args.message.channel, args.message.messageId);
targetMessage = await args.message.channel.messages.fetch(args.message.messageId);
} catch (e) {
if (isDiscordAPIError(e)) {
sendErrorMessage(pluginData, msg.channel, `Error ${e.code} while getting message: ${e.message}`);

View file

@ -5,7 +5,6 @@ import { LogType } from "../../../data/LogType";
import { isDiscordAPIError, sleep } from "../../../utils";
import { LogsPlugin } from "../../Logs/LogsPlugin";
import { ReactionRolesPluginType } from "../types";
import { hotfixMessageFetch } from "../../../utils/hotfixMessageFetch";
const CLEAR_ROLES_EMOJI = "❌";
@ -26,7 +25,7 @@ export async function applyReactionRoleReactionsToMessage(
let targetMessage;
try {
targetMessage = await hotfixMessageFetch(channel, messageId as Snowflake);
targetMessage = channel.messages.fetch(messageId);
} catch (e) {
if (isDiscordAPIError(e)) {
if (e.code === 10008) {

View file

@ -11,7 +11,6 @@ import { LogsPlugin } from "../../Logs/LogsPlugin";
import { BOT_SLOWMODE_PERMISSIONS } from "../requiredPermissions";
import { SlowmodePluginType } from "../types";
import { applyBotSlowmodeToUserId } from "./applyBotSlowmodeToUserId";
import { hotfixMessageFetch } from "../../../utils/hotfixMessageFetch";
export async function onMessageCreate(pluginData: GuildPluginData<SlowmodePluginType>, msg: SavedMessage) {
if (msg.is_bot) return;
@ -50,7 +49,7 @@ export async function onMessageCreate(pluginData: GuildPluginData<SlowmodePlugin
// Delete any extra messages sent after a slowmode was already applied
const userHasSlowmode = await pluginData.state.slowmodes.userHasSlowmode(channel.id, msg.user_id);
if (userHasSlowmode) {
const message = await hotfixMessageFetch(channel, msg.id);
const message = await channel.messages.fetch(msg.id);
if (message) {
message.delete();
return thisMsgLock.interrupt();

View file

@ -4,7 +4,6 @@ import { allStarboardsLock } from "../../../utils/lockNameHelpers";
import { starboardEvt } from "../types";
import { saveMessageToStarboard } from "../util/saveMessageToStarboard";
import { updateStarboardMessageStarCount } from "../util/updateStarboardMessageStarCount";
import { hotfixMessageFetch } from "../../../utils/hotfixMessageFetch";
export const StarboardReactionAddEvt = starboardEvt({
event: "messageReactionAdd",
@ -22,7 +21,7 @@ export const StarboardReactionAddEvt = starboardEvt({
if (!msg.author) {
// Message is not cached, fetch it
try {
msg = await hotfixMessageFetch(msg.channel as TextChannel, msg.id);
msg = await msg.channel.messages.fetch(msg.id);
} catch {
// Sometimes we get this event for messages we can't fetch with getMessage; ignore silently
return;
@ -83,7 +82,7 @@ export const StarboardReactionAddEvt = starboardEvt({
const channel = pluginData.guild.channels.cache.get(
starboardMessage.starboard_channel_id as Snowflake,
) as TextChannel;
const realStarboardMessage = await hotfixMessageFetch(channel, starboardMessage.starboard_message_id);
const realStarboardMessage = await channel.messages.fetch(starboardMessage.starboard_message_id);
await updateStarboardMessageStarCount(
starboard,
msg,

View file

@ -4,7 +4,6 @@ import { commandTypeHelpers as ct } from "../../../commandTypes";
import { getBaseUrl, sendErrorMessage } from "../../../pluginUtils";
import { canReadChannel } from "../../../utils/canReadChannel";
import { utilityCmd } from "../types";
import { hotfixMessageFetch } from "../../../utils/hotfixMessageFetch";
export const SourceCmd = utilityCmd({
trigger: "source",
@ -22,7 +21,7 @@ export const SourceCmd = utilityCmd({
return;
}
const message = await hotfixMessageFetch(args.message.channel, args.message.messageId);
const message = await args.message.channel.messages.fetch(args.message.messageId);
if (!message) {
sendErrorMessage(pluginData, cmdMessage.channel, "Unknown message");
return;

View file

@ -1,23 +0,0 @@
import { GuildChannel, Message, TextChannel, ThreadChannel } from "discord.js";
import { Queue } from "../Queue";
import { sleep } from "../utils";
const queue = new Queue();
let n = 0;
export function hotfixMessageFetch(channel: TextChannel | ThreadChannel, messageId: string): Promise<Message> {
const thisN = ++n;
return channel.messages.fetch(messageId);
// // tslint:disable-next-line:no-console
// console.trace(
// `[${thisN}] Queueing to fetch message id ${messageId} from channel ${channel.id} (queue size: ${queue.length})`,
// );
// return queue.add(async () => {
// await sleep(3000);
// // tslint:disable-next-line:no-console
// console.log(`[${thisN}] Fetching message id ${messageId} from channel ${channel.id}`);
// return channel.messages.fetch(messageId);
// });
}