mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
refactor: typings using ReturnType (#2105)
* fix: check new types idea * fix: type errors * fix: new style * fix: more cleanup * fix: more cleanup * fix: cleanup audit logs * fix: cleanup stickers * fix: cleanup integrations * fix: more cleanup * fix: organize into 1 place * fix: few errors * fix: some broken import fixes * fix: quite a lot of fixes across the board * fix: more fixes for broken imports * fix: more fixes for broken imports * fix: handler imports * fix: all remaining import errors * fix: more errors needing fixes * fix: clearing up transformers * fix: few moer types * fix: more cleanup of extra types * fix: fmt * fix: cleanup discordeno file * Nuke Base Types (#2102) * fix: cleanup snake stuff * convert camelCase to snake_case (#2103) * fix: add camelize * fix: finalize remaining errors * fix: imports in test Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com>
This commit is contained in:
co-authored by
LTS20050703
parent
da29ff294d
commit
a0a1554756
@@ -4,12 +4,12 @@ import { requireBotChannelPermissions } from "../permissions.ts";
|
||||
export default function editChannelOverwrite(bot: BotWithCache) {
|
||||
const editChannelOverwriteOld = bot.helpers.editChannelOverwrite;
|
||||
|
||||
bot.helpers.editChannelOverwrite = async function (channelId, overwriteId, options) {
|
||||
bot.helpers.editChannelOverwrite = async function (channelId, overwrite) {
|
||||
const channel = bot.channels.get(channelId);
|
||||
if (channel?.guildId) {
|
||||
requireBotChannelPermissions(bot, channelId, ["MANAGE_ROLES"]);
|
||||
}
|
||||
|
||||
return await editChannelOverwriteOld(channelId, overwriteId, options);
|
||||
return await editChannelOverwriteOld(channelId, overwrite);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Bot, ButtonStyles, MessageComponents, MessageComponentTypes } from "../deps.ts";
|
||||
import { Bot, ButtonStyles, Emoji, MessageComponents, MessageComponentTypes } from "../deps.ts";
|
||||
|
||||
export function validateComponents(bot: Bot, components: MessageComponents) {
|
||||
if (!components?.length) return;
|
||||
@@ -148,17 +148,23 @@ function makeEmojiFromString(
|
||||
emoji?:
|
||||
| string
|
||||
| {
|
||||
id?: string | undefined;
|
||||
id?: string | bigint | undefined;
|
||||
name?: string | undefined;
|
||||
animated?: boolean | undefined;
|
||||
},
|
||||
) {
|
||||
if (typeof emoji !== "string") return emoji;
|
||||
if (!emoji) return;
|
||||
|
||||
if (typeof emoji !== "string") return {
|
||||
id: emoji.id ? BigInt(emoji.id) : undefined,
|
||||
name: emoji.name,
|
||||
animated: emoji.animated,
|
||||
};
|
||||
|
||||
// A snowflake id was provided
|
||||
if (/^[0-9]+$/.test(emoji)) {
|
||||
emoji = {
|
||||
id: emoji,
|
||||
id: BigInt(emoji),
|
||||
};
|
||||
} else {
|
||||
// A unicode emoji was provided
|
||||
@@ -167,5 +173,5 @@ function makeEmojiFromString(
|
||||
};
|
||||
}
|
||||
|
||||
return emoji;
|
||||
return emoji as Emoji;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import {
|
||||
BitwisePermissionFlags,
|
||||
BotWithCache,
|
||||
DiscordenoChannel,
|
||||
DiscordenoGuild,
|
||||
DiscordenoMember,
|
||||
DiscordenoRole,
|
||||
Channel,
|
||||
Errors,
|
||||
Overwrite,
|
||||
Guild,
|
||||
Member,
|
||||
OverwriteReadable,
|
||||
PermissionStrings,
|
||||
Role,
|
||||
separateOverwrites,
|
||||
} from "../deps.ts";
|
||||
|
||||
/** Calculates the permissions this member has in the given guild */
|
||||
export function calculateBasePermissions(
|
||||
bot: BotWithCache,
|
||||
guildOrId: bigint | DiscordenoGuild,
|
||||
memberOrId: bigint | DiscordenoMember,
|
||||
guildOrId: bigint | Guild,
|
||||
memberOrId: bigint | Member,
|
||||
) {
|
||||
const guild = typeof guildOrId === "bigint" ? bot.guilds.get(guildOrId) : guildOrId;
|
||||
const member = typeof memberOrId === "bigint" ? bot.members.get(memberOrId) : memberOrId;
|
||||
@@ -42,8 +42,8 @@ export function calculateBasePermissions(
|
||||
/** Calculates the permissions this member has for the given Channel */
|
||||
export function calculateChannelOverwrites(
|
||||
bot: BotWithCache,
|
||||
channelOrId: bigint | DiscordenoChannel,
|
||||
memberOrId: bigint | DiscordenoMember,
|
||||
channelOrId: bigint | Channel,
|
||||
memberOrId: bigint | Member,
|
||||
) {
|
||||
const channel = typeof channelOrId === "bigint" ? bot.channels.get(channelOrId) : channelOrId;
|
||||
|
||||
@@ -126,8 +126,8 @@ export function validatePermissions(
|
||||
/** Checks if the given member has these permissions in the given guild */
|
||||
export function hasGuildPermissions(
|
||||
bot: BotWithCache,
|
||||
guild: bigint | DiscordenoGuild,
|
||||
member: bigint | DiscordenoMember,
|
||||
guild: bigint | Guild,
|
||||
member: bigint | Member,
|
||||
permissions: PermissionStrings[],
|
||||
) {
|
||||
// First we need the role permission bits this member has
|
||||
@@ -143,7 +143,7 @@ export function hasGuildPermissions(
|
||||
/** Checks if the bot has these permissions in the given guild */
|
||||
export function botHasGuildPermissions(
|
||||
bot: BotWithCache,
|
||||
guild: bigint | DiscordenoGuild,
|
||||
guild: bigint | Guild,
|
||||
permissions: PermissionStrings[],
|
||||
) {
|
||||
// Since Bot is a normal member we can use the hasRolePermissions() function
|
||||
@@ -153,8 +153,8 @@ export function botHasGuildPermissions(
|
||||
/** Checks if the given member has these permissions for the given channel */
|
||||
export function hasChannelPermissions(
|
||||
bot: BotWithCache,
|
||||
channel: bigint | DiscordenoChannel,
|
||||
member: bigint | DiscordenoMember,
|
||||
channel: bigint | Channel,
|
||||
member: bigint | Member,
|
||||
permissions: PermissionStrings[],
|
||||
) {
|
||||
// First we need the overwrite bits this member has
|
||||
@@ -170,7 +170,7 @@ export function hasChannelPermissions(
|
||||
/** Checks if the bot has these permissions f0r the given channel */
|
||||
export function botHasChannelPermissions(
|
||||
bot: BotWithCache,
|
||||
channel: bigint | DiscordenoChannel,
|
||||
channel: bigint | Channel,
|
||||
permissions: PermissionStrings[],
|
||||
) {
|
||||
// Since Bot is a normal member we can use the hasRolePermissions() function
|
||||
@@ -190,8 +190,8 @@ export function missingPermissions(
|
||||
/** Get the missing Guild permissions this member has */
|
||||
export function getMissingGuildPermissions(
|
||||
bot: BotWithCache,
|
||||
guild: bigint | DiscordenoGuild,
|
||||
member: bigint | DiscordenoMember,
|
||||
guild: bigint | Guild,
|
||||
member: bigint | Member,
|
||||
permissions: PermissionStrings[],
|
||||
) {
|
||||
// First we need the role permission bits this member has
|
||||
@@ -207,8 +207,8 @@ export function getMissingGuildPermissions(
|
||||
/** Get the missing Channel permissions this member has */
|
||||
export function getMissingChannelPermissions(
|
||||
bot: BotWithCache,
|
||||
channel: bigint | DiscordenoChannel,
|
||||
member: bigint | DiscordenoMember,
|
||||
channel: bigint | Channel,
|
||||
member: bigint | Member,
|
||||
permissions: PermissionStrings[],
|
||||
) {
|
||||
// First we need the role permissino bits this member has
|
||||
@@ -224,8 +224,8 @@ export function getMissingChannelPermissions(
|
||||
/** Throws an error if this member has not all of the given permissions */
|
||||
export function requireGuildPermissions(
|
||||
bot: BotWithCache,
|
||||
guild: bigint | DiscordenoGuild,
|
||||
member: bigint | DiscordenoMember,
|
||||
guild: bigint | Guild,
|
||||
member: bigint | Member,
|
||||
permissions: PermissionStrings[],
|
||||
) {
|
||||
const missing = getMissingGuildPermissions(
|
||||
@@ -243,7 +243,7 @@ export function requireGuildPermissions(
|
||||
/** Throws an error if the bot does not have all permissions */
|
||||
export function requireBotGuildPermissions(
|
||||
bot: BotWithCache,
|
||||
guild: bigint | DiscordenoGuild,
|
||||
guild: bigint | Guild,
|
||||
permissions: PermissionStrings[],
|
||||
) {
|
||||
// Since Bot is a normal member we can use the throwOnMissingGuildPermission() function
|
||||
@@ -253,8 +253,8 @@ export function requireBotGuildPermissions(
|
||||
/** Throws an error if this member has not all of the given permissions */
|
||||
export function requireChannelPermissions(
|
||||
bot: BotWithCache,
|
||||
channel: bigint | DiscordenoChannel,
|
||||
member: bigint | DiscordenoMember,
|
||||
channel: bigint | Channel,
|
||||
member: bigint | Member,
|
||||
permissions: PermissionStrings[],
|
||||
) {
|
||||
const missing = getMissingChannelPermissions(
|
||||
@@ -272,7 +272,7 @@ export function requireChannelPermissions(
|
||||
/** Throws an error if the bot has not all of the given channel permissions */
|
||||
export function requireBotChannelPermissions(
|
||||
bot: BotWithCache,
|
||||
channel: bigint | DiscordenoChannel,
|
||||
channel: bigint | Channel,
|
||||
permissions: PermissionStrings[],
|
||||
) {
|
||||
// Since Bot is a normal member we can use the throwOnMissingChannelPermission() function
|
||||
@@ -303,8 +303,8 @@ export function calculateBits(permissions: PermissionStrings[]) {
|
||||
/** Internal function to check if the bot has the permissions to set these overwrites */
|
||||
export function requireOverwritePermissions(
|
||||
bot: BotWithCache,
|
||||
guildOrId: bigint | DiscordenoGuild,
|
||||
overwrites: Overwrite[],
|
||||
guildOrId: bigint | Guild,
|
||||
overwrites: OverwriteReadable[],
|
||||
) {
|
||||
let requiredPerms: Set<PermissionStrings> = new Set(["MANAGE_CHANNELS"]);
|
||||
|
||||
@@ -330,8 +330,8 @@ export function requireOverwritePermissions(
|
||||
/** Gets the highest role from the member in this guild */
|
||||
export function highestRole(
|
||||
bot: BotWithCache,
|
||||
guildOrId: bigint | DiscordenoGuild,
|
||||
memberOrId: bigint | DiscordenoMember,
|
||||
guildOrId: bigint | Guild,
|
||||
memberOrId: bigint | Member,
|
||||
) {
|
||||
const guild = typeof guildOrId === "bigint" ? bot.guilds.get(guildOrId) : guildOrId;
|
||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||
@@ -342,7 +342,7 @@ export function highestRole(
|
||||
// This member has no roles so the highest one is the @everyone role
|
||||
if (!memberRoles) return guild.roles.get(guild.id)!;
|
||||
|
||||
let memberHighestRole: DiscordenoRole | undefined;
|
||||
let memberHighestRole: Role | undefined;
|
||||
|
||||
for (const roleId of memberRoles) {
|
||||
const role = guild.roles.get(roleId);
|
||||
@@ -367,7 +367,7 @@ export function highestRole(
|
||||
/** Checks if the first role is higher than the second role */
|
||||
export function higherRolePosition(
|
||||
bot: BotWithCache,
|
||||
guildOrId: bigint | DiscordenoGuild,
|
||||
guildOrId: bigint | Guild,
|
||||
roleId: bigint,
|
||||
otherRoleId: bigint,
|
||||
) {
|
||||
@@ -389,7 +389,7 @@ export function higherRolePosition(
|
||||
/** Checks if the member has a higher position than the given role */
|
||||
export function isHigherPosition(
|
||||
bot: BotWithCache,
|
||||
guildOrId: bigint | DiscordenoGuild,
|
||||
guildOrId: bigint | Guild,
|
||||
memberId: bigint,
|
||||
compareRoleId: bigint,
|
||||
) {
|
||||
|
||||
@@ -4,8 +4,9 @@ import { requireBotChannelPermissions } from "../permissions.ts";
|
||||
export default function editWebhook(bot: BotWithCache) {
|
||||
const editWebhookOld = bot.helpers.editWebhook;
|
||||
|
||||
bot.helpers.editWebhook = async function (channelId, webhookId, options) {
|
||||
requireBotChannelPermissions(bot, channelId, ["MANAGE_WEBHOOKS"]);
|
||||
bot.helpers.editWebhook = async function (webhookId, options) {
|
||||
if (options.channelId) requireBotChannelPermissions(bot, options.channelId, ["MANAGE_WEBHOOKS"]);
|
||||
|
||||
if (options.name) {
|
||||
if (
|
||||
// Specific usernames that discord does not allow
|
||||
@@ -18,6 +19,6 @@ export default function editWebhook(bot: BotWithCache) {
|
||||
}
|
||||
}
|
||||
|
||||
return await editWebhookOld(channelId, webhookId, options);
|
||||
return await editWebhookOld(webhookId, options);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user