UNPKG

@sapphire/framework

Version:

Discord bot framework built for advanced and amazing bots.

1 lines 1.82 kB
{"version":3,"file":"guildChannel.mjs","names":[],"sources":["../../../../src/lib/resolvers/guildChannel.ts"],"sourcesContent":["import { ChannelMentionRegex, SnowflakeRegex } from '@sapphire/discord-utilities';\nimport type { GuildBasedChannelTypes } from '@sapphire/discord.js-utilities';\nimport { Result } from '@sapphire/result';\nimport type { Guild, Snowflake } from 'discord.js';\nimport { Identifiers } from '../errors/Identifiers';\n\nexport function resolveGuildChannel(parameter: string, guild: Guild): Result<GuildBasedChannelTypes, Identifiers.ArgumentGuildChannelError> {\n\tconst channel = resolveById(parameter, guild) ?? resolveByQuery(parameter, guild);\n\n\tif (channel) {\n\t\treturn Result.ok(channel);\n\t}\n\n\treturn Result.err(Identifiers.ArgumentGuildChannelError);\n}\n\nfunction resolveById(argument: string, guild: Guild): GuildBasedChannelTypes | null {\n\tconst channelId = ChannelMentionRegex.exec(argument) ?? SnowflakeRegex.exec(argument);\n\treturn channelId ? ((guild.channels.cache.get(channelId[1] as Snowflake) as GuildBasedChannelTypes) ?? null) : null;\n}\n\nfunction resolveByQuery(argument: string, guild: Guild): GuildBasedChannelTypes | null {\n\tconst lowerCaseArgument = argument.toLowerCase();\n\treturn (guild.channels.cache.find((channel) => channel.name.toLowerCase() === lowerCaseArgument) as GuildBasedChannelTypes) ?? null;\n}\n"],"mappings":";;;;;AAMA,SAAgB,oBAAoB,WAAmB,OAAqF;CAC3I,MAAM,UAAU,YAAY,WAAW,MAAM,IAAI,eAAe,WAAW,MAAM;AAEjF,KAAI,QACH,QAAO,OAAO,GAAG,QAAQ;AAG1B,QAAO,OAAO,IAAI,YAAY,0BAA0B;;AAGzD,SAAS,YAAY,UAAkB,OAA6C;CACnF,MAAM,YAAY,oBAAoB,KAAK,SAAS,IAAI,eAAe,KAAK,SAAS;AACrF,QAAO,YAAc,MAAM,SAAS,MAAM,IAAI,UAAU,GAAgB,IAA+B,OAAQ;;AAGhH,SAAS,eAAe,UAAkB,OAA6C;CACtF,MAAM,oBAAoB,SAAS,aAAa;AAChD,QAAQ,MAAM,SAAS,MAAM,MAAM,YAAY,QAAQ,KAAK,aAAa,KAAK,kBAAkB,IAA+B"}