UNPKG

@getsolara/solara.js

Version:

A lightweight and modular Discord bot framework built on discord.js v14, with truly optional feature packages.

69 lines (61 loc) 4.48 kB
const { GatewayIntentBits, Partials, ApplicationCommandOptionType, ChannelType, ActivityType } = require('discord.js'); // Added ActivityType const intentMap = { guilds: GatewayIntentBits.Guilds, guildmembers: GatewayIntentBits.GuildMembers, guildmoderation: GatewayIntentBits.GuildModeration, guildemojisandstickers: GatewayIntentBits.GuildEmojisAndStickers, guildintegrations: GatewayIntentBits.GuildIntegrations, guildwebhooks: GatewayIntentBits.GuildWebhooks, guildinvites: GatewayIntentBits.GuildInvites, guildvoicestates: GatewayIntentBits.GuildVoiceStates, guildpresences: GatewayIntentBits.GuildPresences, guildmessages: GatewayIntentBits.GuildMessages, guildmessagereactions: GatewayIntentBits.GuildMessageReactions, guildmessagetyping: GatewayIntentBits.GuildMessageTyping, directmessages: GatewayIntentBits.DirectMessages, directmessagereactions: GatewayIntentBits.DirectMessageReactions, directmessagetyping: GatewayIntentBits.DirectMessageTyping, messagecontent: GatewayIntentBits.MessageContent, guildscheduledevents: GatewayIntentBits.GuildScheduledEvents, automoderationconfiguration: GatewayIntentBits.AutoModerationConfiguration, automoderationexecution: GatewayIntentBits.AutoModerationExecution, }; const partialMap = { user: Partials.User, channel: Partials.Channel, guildmember: Partials.GuildMember, message: Partials.Message, reaction: Partials.Reaction, guildscheduledevent: Partials.GuildScheduledEvent, threadmember: Partials.ThreadMember }; const optionTypeMap = { sub_command: ApplicationCommandOptionType.Subcommand, sub_command_group: ApplicationCommandOptionType.SubcommandGroup, string: ApplicationCommandOptionType.String, integer: ApplicationCommandOptionType.Integer, boolean: ApplicationCommandOptionType.Boolean, user: ApplicationCommandOptionType.User, channel: ApplicationCommandOptionType.Channel, role: ApplicationCommandOptionType.Role, mentionable: ApplicationCommandOptionType.Mentionable, number: ApplicationCommandOptionType.Number, attachment: ApplicationCommandOptionType.Attachment, }; const channelTypeMap = { 'text': ChannelType.GuildText, 'voice': ChannelType.GuildVoice, 'category': ChannelType.GuildCategory, 'news': ChannelType.GuildAnnouncement, 'stage': ChannelType.GuildStageVoice, 'forum': ChannelType.GuildForum, 'public_thread': ChannelType.PublicThread, 'private_thread': ChannelType.PrivateThread, 'news_thread': ChannelType.AnnouncementThread }; const activityTypeMap = { PLAYING: ActivityType.Playing, STREAMING: ActivityType.Streaming, LISTENING: ActivityType.Listening, WATCHING: ActivityType.Watching, COMPETING: ActivityType.Competing, CUSTOM: ActivityType.Custom, }; function mapIntents(intentStrings = []) { return intentStrings.map(str => { const lowerCaseStr = str.toLowerCase().replace(/_/g, ''); if (intentMap[lowerCaseStr]) return intentMap[lowerCaseStr]; console.warn(`Solara: Unknown intent string "${str}". Skipping.`); return null; }).filter(bit => bit !== null); } function mapPartials(partialStrings = []) { return partialStrings.map(str => { const lowerCaseStr = str.toLowerCase().replace(/_/g, ''); if (partialMap[lowerCaseStr]) return partialMap[lowerCaseStr]; console.warn(`Solara: Unknown partial string "${str}". Skipping.`); return null; }).filter(p => p !== null); } function mapOptionType(typeString) { return optionTypeMap[typeString?.toLowerCase()] || ApplicationCommandOptionType.String; } function mapChannelTypes(typeStrings = []) { return typeStrings .map(ct => channelTypeMap[ct?.toLowerCase()]) .filter(ct => ct !== undefined); } function mapActivityType(typeString) { if (typeof typeString !== 'string') { console.warn(`Solara Mappings: Activity type must be a string. Received: ${typeString}`); return undefined; } const upperType = typeString.toUpperCase(); if (activityTypeMap.hasOwnProperty(upperType)) { return activityTypeMap[upperType]; } console.warn(`Solara Mappings: Unknown activity type string "${typeString}". Valid types are: ${Object.keys(activityTypeMap).join(', ')}.`); return undefined; } module.exports = { mapIntents, mapPartials, mapOptionType, mapChannelTypes, mapActivityType, intentMap, partialMap, optionTypeMap, channelTypeMap, activityTypeMap, };