mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 22:21:51 +00:00
Add proper types to sendSuccessMessage()
This commit is contained in:
parent
1a5fe949af
commit
6896afebfa
3 changed files with 20 additions and 7 deletions
|
@ -2,7 +2,7 @@
|
||||||
* @file Utility functions that are plugin-instance-specific (i.e. use PluginData)
|
* @file Utility functions that are plugin-instance-specific (i.e. use PluginData)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Member } from "eris";
|
import { GuildTextableChannel, Member, Message, TextableChannel } from "eris";
|
||||||
import { CommandContext, configUtils, ConfigValidationError, GuildPluginData, helpers, PluginOptions } from "knub";
|
import { CommandContext, configUtils, ConfigValidationError, GuildPluginData, helpers, PluginOptions } from "knub";
|
||||||
import { decodeAndValidateStrict, StrictValidationError, validate } from "./validatorUtils";
|
import { decodeAndValidateStrict, StrictValidationError, validate } from "./validatorUtils";
|
||||||
import { deepKeyIntersect, errorMessage, successMessage, tDeepPartial, tNullable } from "./utils";
|
import { deepKeyIntersect, errorMessage, successMessage, tDeepPartial, tNullable } from "./utils";
|
||||||
|
@ -137,17 +137,30 @@ export function getPluginConfigPreprocessor(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendSuccessMessage(pluginData: AnyPluginData<any>, channel, body) {
|
export function sendSuccessMessage(
|
||||||
|
pluginData: AnyPluginData<any>,
|
||||||
|
channel: TextableChannel,
|
||||||
|
body: string,
|
||||||
|
): Promise<Message | undefined> {
|
||||||
const emoji = pluginData.fullConfig.success_emoji || undefined;
|
const emoji = pluginData.fullConfig.success_emoji || undefined;
|
||||||
return channel.createMessage(successMessage(body, emoji)).catch(err => {
|
return channel.createMessage(successMessage(body, emoji)).catch(err => {
|
||||||
logger.warn(`Failed to send success message to ${channel.id} (${channel.guild?.id}): ${err.code} ${err.message}`);
|
logger.warn(
|
||||||
|
`Failed to send success message to ${channel.id} (${(channel as GuildTextableChannel).guild?.id}): ${err.code} ${
|
||||||
|
err.message
|
||||||
|
}`,
|
||||||
|
);
|
||||||
|
return undefined;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendErrorMessage(pluginData: AnyPluginData<any>, channel, body) {
|
export function sendErrorMessage(pluginData: AnyPluginData<any>, channel, body) {
|
||||||
const emoji = pluginData.fullConfig.error_emoji || undefined;
|
const emoji = pluginData.fullConfig.error_emoji || undefined;
|
||||||
return channel.createMessage(errorMessage(body, emoji)).catch(err => {
|
return channel.createMessage(errorMessage(body, emoji)).catch(err => {
|
||||||
logger.warn(`Failed to send error message to ${channel.id} (${channel.guild?.id}): ${err.code} ${err.message}`);
|
logger.warn(
|
||||||
|
`Failed to send error message to ${channel.id} (${(channel as GuildTextableChannel).guild?.id}): ${err.code} ${
|
||||||
|
err.message
|
||||||
|
}`,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,7 +148,7 @@ export const UtilityPlugin = zeppelinGuildPlugin<UtilityPluginType>()("utility",
|
||||||
state.lastReload = Date.now();
|
state.lastReload = Date.now();
|
||||||
|
|
||||||
if (activeReloads.has(guild.id)) {
|
if (activeReloads.has(guild.id)) {
|
||||||
sendSuccessMessage(pluginData, activeReloads.get(guild.id), "Reloaded!");
|
sendSuccessMessage(pluginData, activeReloads.get(guild.id)!, "Reloaded!");
|
||||||
activeReloads.delete(guild.id);
|
activeReloads.delete(guild.id);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -136,7 +136,7 @@ export const CleanCmd = utilityCmd({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let responseMsg: Message;
|
let responseMsg: Message | undefined;
|
||||||
if (messagesToClean.length > 0) {
|
if (messagesToClean.length > 0) {
|
||||||
const cleanResult = await cleanMessages(pluginData, targetChannel, messagesToClean, msg.author);
|
const cleanResult = await cleanMessages(pluginData, targetChannel, messagesToClean, msg.author);
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ export const CleanCmd = utilityCmd({
|
||||||
// (so as not to spam the cleaned channel with the command itself)
|
// (so as not to spam the cleaned channel with the command itself)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
msg.delete().catch(noop);
|
msg.delete().catch(noop);
|
||||||
responseMsg.delete().catch(noop);
|
responseMsg?.delete().catch(noop);
|
||||||
}, CLEAN_COMMAND_DELETE_DELAY);
|
}, CLEAN_COMMAND_DELETE_DELAY);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue