mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-18 15:45:03 +00:00
Add custom argument types for deep-resolved users/members, use these in some places. Deprecate unknownUser (constant) and replace with instances of UnknownUser (class).
This commit is contained in:
parent
4acf1b3ad4
commit
ba7fbd87a7
6 changed files with 151 additions and 111 deletions
40
src/customArgumentTypes.ts
Normal file
40
src/customArgumentTypes.ts
Normal file
|
@ -0,0 +1,40 @@
|
|||
import { convertDelayStringToMS, resolveMember, resolveUser, UnknownUser } from "./utils";
|
||||
import { CommandArgumentTypeError } from "knub";
|
||||
import { Client, GuildChannel, Message } from "eris";
|
||||
|
||||
export const customArgumentTypes = {
|
||||
delay(value) {
|
||||
const result = convertDelayStringToMS(value);
|
||||
if (result == null) {
|
||||
throw new CommandArgumentTypeError(`Could not convert ${value} to a delay`);
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
async resolvedUser(value, msg, bot: Client) {
|
||||
const result = resolveUser(bot, value);
|
||||
if (result == null || result instanceof UnknownUser) {
|
||||
throw new CommandArgumentTypeError(`User \`${value}\` was not found`);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
async resolvedUserLoose(value, msg, bot: Client) {
|
||||
const result = resolveUser(bot, value);
|
||||
if (result == null) {
|
||||
throw new CommandArgumentTypeError(`Invalid user: ${value}`);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
async resolvedMember(value, msg: Message, bot: Client) {
|
||||
if (!(msg.channel instanceof GuildChannel)) return null;
|
||||
|
||||
const result = await resolveMember(bot, msg.channel.guild, value);
|
||||
if (result == null) {
|
||||
throw new CommandArgumentTypeError(`Member \`${value}\` was not found or they have left the server`);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue