(message, commandData, args)
| 50 | } |
| 51 | |
| 52 | export function createMockInteraction(message, commandData, args) { |
| 53 | const options = mapArgumentsToOptions(args, commandData); |
| 54 | const commandStartTime = Date.now(); |
| 55 | |
| 56 | const mockInteraction = { |
| 57 | user: message.author, |
| 58 | member: message.member, |
| 59 | get memberPermissions() { |
| 60 | return message.member?.permissions ?? null; |
| 61 | }, |
| 62 | |
| 63 | channel: message.channel, |
| 64 | guild: message.guild, |
| 65 | guildId: message.guild?.id, |
| 66 | |
| 67 | commandName: commandData?.name || null, |
| 68 | commandId: message.id, |
| 69 | id: message.id, |
| 70 | |
| 71 | options: { |
| 72 | get: (name) => options.get(name), |
| 73 | getString: (name) => options.getString(name), |
| 74 | getUser: (name) => { |
| 75 | const userId = options.getUser(name); |
| 76 | if (!userId || !message.guild) return null; |
| 77 | |
| 78 | const mentionMatch = userId.match(/<@!?(\d+)>/); |
| 79 | const id = mentionMatch ? mentionMatch[1] : userId; |
| 80 | |
| 81 | const cachedMember = message.guild.members.cache.get(id); |
| 82 | if (cachedMember) { |
| 83 | return cachedMember.user; |
| 84 | } |
| 85 | |
| 86 | return { |
| 87 | id, |
| 88 | username: 'Unknown', |
| 89 | bot: false, |
| 90 | tag: 'Unknown#0000', |
| 91 | }; |
| 92 | }, |
| 93 | getMember: (name) => { |
| 94 | const userId = options.getUser(name); |
| 95 | if (!userId || !message.guild) return null; |
| 96 | |
| 97 | const mentionMatch = userId.match(/<@!?(\d+)>/); |
| 98 | const id = mentionMatch ? mentionMatch[1] : userId; |
| 99 | |
| 100 | return message.guild.members.cache.get(id) ?? null; |
| 101 | }, |
| 102 | getChannel: (name) => { |
| 103 | const channelId = options.getString(name); |
| 104 | if (!channelId || !message.guild) return null; |
| 105 | |
| 106 | const mentionMatch = channelId.match(/<#(\d+)>/); |
| 107 | const id = mentionMatch ? mentionMatch[1] : channelId; |
| 108 | |
| 109 | return message.guild.channels.fetch(id).catch(() => null); |
no test coverage detected