Archived
changed TargetID and simplified CommandInteractionData
This commit is contained in:
1 parent
2c8bcd33e1
commit
4d2507e3e6
2 files changed
+28
-15
No files matched your search
@@ -8,7 +8,7 @@ import { TargetID } from "structures/Parameter.js";
|
|||||||
|
|
||||||
export type CommandResolvable = BaseCommand | ChatCommand | MessageCommand | UserCommand;
|
export type CommandResolvable = BaseCommand | ChatCommand | MessageCommand | UserCommand;
|
||||||
|
|
||||||
export interface CommandInteractionData<T extends Interaction | Message> {
|
export interface CommandInteractionData {
|
||||||
command: T extends Interaction ? BaseCommand : ChatCommand;
|
command: BaseCommand;
|
||||||
parameters: ReadonlyMap<string, ParameterResolvable> | TargetID;
|
parameters: ReadonlyMap<string, ParameterResolvable> | TargetID;
|
||||||
}
|
}
|
||||||
+26
-13
@@ -1,4 +1,4 @@
|
|||||||
import { CategoryChannel, Guild, GuildMember, Message, NewsChannel, Role, StageChannel, StoreChannel, TextChannel, VoiceChannel } from "discord.js";
|
import { CategoryChannel, DMChannel, Guild, GuildMember, Message, NewsChannel, Role, StageChannel, StoreChannel, TextChannel, VoiceChannel } from "discord.js";
|
||||||
import { ParameterType, ParameterResolvable, ParameterSchema } from "./types/Parameter.js";
|
import { ParameterType, ParameterResolvable, ParameterSchema } from "./types/Parameter.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -163,24 +163,37 @@ export class NullParameter extends InputParameter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TargetParameter extends InputParameter {
|
// export class TargetParameter extends InputParameter {
|
||||||
constructor(parameter: Parameter, targetId: TargetID) {
|
// constructor(parameter: Parameter, targetId: TargetID) {
|
||||||
super(parameter, targetId);
|
// super(parameter, targetId);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
export class TargetID {
|
export class TargetID {
|
||||||
public readonly id: string;
|
public readonly id: string;
|
||||||
|
private readonly type: "MESSAGE" | "USER";
|
||||||
|
|
||||||
constructor(id: string) {
|
constructor(id: string, type: "MESSAGE" | "USER") {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
toMessage(c: TextChannel) {
|
toObject(r: Guild): GuildMember | null;
|
||||||
return c.messages.cache.get(this.id.toString() || "");
|
toObject(r: TextChannel | DMChannel): Message | null;
|
||||||
}
|
toObject(r: Guild | TextChannel | DMChannel): GuildMember | Message | null {
|
||||||
|
switch (this.type) {
|
||||||
async toUser(g: Guild) {
|
case "MESSAGE":
|
||||||
return await g.members.fetch({ query: this.id.toString() });
|
if (r instanceof TextChannel || r instanceof DMChannel) {
|
||||||
|
return r.messages.cache.get(this.id) || null;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
case "USER":
|
||||||
|
if (r instanceof Guild) {
|
||||||
|
return r.members.cache.get(this.id) || null;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user