resolveUser: return null if the passed value is not a valid id

This commit is contained in:
Dragory 2020-08-09 20:10:03 +03:00
parent 5215dd0738
commit a641312853
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
6 changed files with 21 additions and 4 deletions

View file

@ -12,6 +12,10 @@ export async function createCaseNote(pluginData: PluginData<CasesPluginType>, ar
}
const mod = await resolveUser(pluginData.client, args.modId);
if (!mod) {
throw new RecoverablePluginError(ERRORS.INVALID_USER);
}
const modName = `${mod.username}#${mod.discriminator}`;
let body = args.body;

View file

@ -35,6 +35,7 @@ export const UnmuteCmd = modActionsCommand({
async run({ pluginData, message: msg, args }) {
const user = await resolveUser(pluginData.client, args.user);
if (!user) return sendErrorMessage(pluginData, msg.channel, `User not found`);
const memberToUnmute = await resolveMember(pluginData.client, pluginData.guild, user.id);
const mutesPlugin = pluginData.getPlugin(MutesPlugin);
const hasMuteRole = memberToUnmute && mutesPlugin.hasMutedRole(memberToUnmute);

View file

@ -20,6 +20,12 @@ export async function banUserId(
): Promise<BanResult> {
const config = pluginData.config.get();
const user = await resolveUser(pluginData.client, userId);
if (!user) {
return {
status: "failed",
error: "Invalid user",
};
}
// Attempt to message the user *before* banning them, as doing it after may not be possible
let notifyResult: UserNotificationResult = { method: null, success: true };

View file

@ -41,6 +41,11 @@ export async function muteUser(
}
const user = await resolveUser(pluginData.client, userId);
if (!user) {
lock.unlock();
throw new RecoverablePluginError(ERRORS.INVALID_USER);
}
const member = await resolveMember(pluginData.client, pluginData.guild, user.id); // Grab the fresh member so we don't have stale role info
const config = pluginData.config.getMatchingConfig({ member, userId });