mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 01:10:07 +00:00
fmt
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { Collection, createNewProp, Guild } from "../../mod.ts";
|
||||
import { cacheHandlers } from "../controllers/cache.ts";
|
||||
import { ChannelCreatePayload, ChannelType, RawOverwrite, Unpromise } from "../types/types.ts";
|
||||
import {
|
||||
ChannelCreatePayload,
|
||||
ChannelType,
|
||||
RawOverwrite,
|
||||
Unpromise,
|
||||
} from "../types/types.ts";
|
||||
import { cache } from "../utils/cache.ts";
|
||||
import { Message } from "./message.ts";
|
||||
|
||||
@@ -9,11 +14,11 @@ const baseChannel: any = {
|
||||
return cache.guilds.get(this.guildID);
|
||||
},
|
||||
get messages() {
|
||||
return cache.messages.filter(m => m.channelID === this.id);
|
||||
return cache.messages.filter((m) => m.channelID === this.id);
|
||||
},
|
||||
get mention() {
|
||||
return `<#${this.id}>`;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
export async function createChannel(
|
||||
@@ -45,7 +50,9 @@ export async function createChannel(
|
||||
userLimit: createNewProp(userLimit),
|
||||
rateLimitPerUser: createNewProp(rateLimitPerUser),
|
||||
parentID: createNewProp(parentID || undefined),
|
||||
lastPinTimestamp: createNewProp(lastPinTimestamp ? Date.parse(lastPinTimestamp) : undefined),
|
||||
lastPinTimestamp: createNewProp(
|
||||
lastPinTimestamp ? Date.parse(lastPinTimestamp) : undefined,
|
||||
),
|
||||
permissionOverwrites: createNewProp(permission_overwrites || []),
|
||||
nsfw: createNewProp(data.nsfw || false),
|
||||
});
|
||||
@@ -83,7 +90,7 @@ export interface Channel {
|
||||
permissionOverwrites: RawOverwrite[];
|
||||
/** Whether this channel is nsfw or not */
|
||||
nsfw: boolean;
|
||||
|
||||
|
||||
// GETTERS
|
||||
|
||||
/**
|
||||
@@ -100,4 +107,4 @@ export interface Channel {
|
||||
messages: Collection<string, Message>;
|
||||
/** The mention of the channel */
|
||||
mention: string;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,21 @@
|
||||
import { MessageCreateOptions, Unpromise } from "../types/types.ts";
|
||||
import { cache } from "../utils/cache.ts";
|
||||
|
||||
const baseMessage: any = {
|
||||
get guild() {
|
||||
return cache.guilds.get(this.guildID);
|
||||
},
|
||||
get member() {
|
||||
return cache.members.get(this.authorID);
|
||||
},
|
||||
get guildMember() {
|
||||
return this.member.guilds.get(this.guildID);
|
||||
},
|
||||
get link() {
|
||||
return `https://discord.com/channels/${this.guildID ||
|
||||
"@me"}/${this.channelID}/${this.id}`;
|
||||
},
|
||||
};
|
||||
|
||||
export async function createMessage(data: MessageCreateOptions) {
|
||||
const {
|
||||
|
||||
@@ -8,33 +8,42 @@ import { Member } from "./member.ts";
|
||||
|
||||
const baseRole: Partial<Role> = {
|
||||
get guild() {
|
||||
return cache.guilds.find(g => g.roles.has(this.id));
|
||||
return cache.guilds.find((g) => g.roles.has(this.id));
|
||||
},
|
||||
get hexColor() {
|
||||
return this.color!.toString(16);
|
||||
},
|
||||
get members() {
|
||||
return cache.members.filter(m => m.guilds.some(g => g.roles.includes(this.id)));
|
||||
return cache.members.filter((m) =>
|
||||
m.guilds.some((g) => g.roles.includes(this.id))
|
||||
);
|
||||
},
|
||||
get mention() {
|
||||
return `<@&${this.id}>`;
|
||||
},
|
||||
|
||||
|
||||
// METHODS
|
||||
delete: function (guildID?: string) {
|
||||
// If not guild id was provided try and find one
|
||||
if (!guildID) guildID = guildID || this.guild?.id;
|
||||
// If a guild id is still not available error out
|
||||
if (!guildID) throw new Error("role.delete() did not find a valid guild in cache. Please provide the guildID like role.delete(guildID)")
|
||||
|
||||
if (!guildID) {
|
||||
throw new Error(
|
||||
"role.delete() did not find a valid guild in cache. Please provide the guildID like role.delete(guildID)",
|
||||
);
|
||||
}
|
||||
|
||||
return deleteRole(guildID, this.id!).catch(console.error);
|
||||
},
|
||||
edit(options: CreateRoleOptions, guildID?: string) {
|
||||
// If not guild id was provided try and find one
|
||||
if (!guildID) guildID = guildID || this.guild?.id;
|
||||
// If a guild id is still not available error out
|
||||
if (!guildID) throw new Error("role.edit() did not find a valid guild in cache. Please provide the guildID like role.edit({}, guildID)")
|
||||
if (!guildID) {
|
||||
throw new Error(
|
||||
"role.edit() did not find a valid guild in cache. Please provide the guildID like role.edit({}, guildID)",
|
||||
);
|
||||
}
|
||||
|
||||
return editRole(guildID, this.id!, options);
|
||||
},
|
||||
@@ -42,17 +51,20 @@ const baseRole: Partial<Role> = {
|
||||
// If no position try and find one from cache
|
||||
if (!position) position = this.guild?.roles.get(roleID)?.position;
|
||||
// If still none error out.
|
||||
if (!position) throw new Error("role.higherThanRoleID() did not have a position provided and the role or guild was not found in cache. Please provide a position like role.higherThanRoleID(roleID, position)")
|
||||
|
||||
if (!position) {
|
||||
throw new Error(
|
||||
"role.higherThanRoleID() did not have a position provided and the role or guild was not found in cache. Please provide a position like role.higherThanRoleID(roleID, position)",
|
||||
);
|
||||
}
|
||||
|
||||
// Rare edge case handling
|
||||
if (this.position === position) {
|
||||
return this.id! < roleID
|
||||
return this.id! < roleID;
|
||||
}
|
||||
|
||||
return this.position! > position;
|
||||
},
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
export async function createRole(data: RoleData) {
|
||||
const { tags, ...rest } = data;
|
||||
@@ -68,7 +80,7 @@ export async function createRole(data: RoleData) {
|
||||
botID: createNewProp(tags?.bot_id),
|
||||
isNitroBoostRole: createNewProp("premium_subscriber" in (tags ?? {})),
|
||||
integrationID: createNewProp(tags?.integration_id),
|
||||
})
|
||||
});
|
||||
|
||||
return role as Role;
|
||||
}
|
||||
|
||||
@@ -35,5 +35,5 @@ export async function urlToBase64(url: string) {
|
||||
|
||||
/** Allows easy way to add a prop to a base object when needing to use complicated getters solution. */
|
||||
export function createNewProp(value: any) {
|
||||
return { configurable: true, enumerable: true, writable: true, value }
|
||||
}
|
||||
return { configurable: true, enumerable: true, writable: true, value };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user