message: feat(Commands): resolve mentions into objects
diff: +import type { Client } from "../client/client.ts"
  +import type { Message } from '../structures/message.ts'
  +import type { Guild } from "../structures/guild.ts"
  +import type { Role } from "../structures/role.ts"
  +
  interface MentionToRegex {
  [key: string]: RegExp
  user: RegExp
  @@ -43,12 +48,13 @@ export type Args =
  | ContentArgument
  | RestArgument
  -export function parseArgs(
  +export async function parseArgs(
  commandArgs: Args[] | undefined,
  - messageArgs: string[]
  -): Record<string, string | number | boolean> | null {
  + message: Message,
  + client: Client,
  +): Promise<Record<string, Guild | Role | string | number | boolean> | null> {
  if (commandArgs === undefined) return null
  -
  + const messageArgs = message.content.split(" ")
  const messageArgsNullableCopy: Array<string | null> = [...messageArgs]
  const args: Record<string, string | number | boolean> = {}
  @@ -60,7 +66,7 @@ export function parseArgs(
  case 'user':
  case 'role':
  case 'channel':
  - parseMention(args, entry, messageArgsNullableCopy)
  + await parseMention(args, entry, messageArgsNullableCopy, client, message)
  break
  case 'content':
  parseContent(args, entry, messageArgs)
  @@ -76,7 +82,7 @@ export function parseArgs(
  function parseFlags(
  args: Record<string, unknown>,
  entry: FlagArgument,
  - argsNullable: Array<string | null>
  + argsNullable: Array<string | null>,
  ): void {
  for (let i = 0; i < argsNullable.length; i++) {
  if (entry.flag === argsNullable[i]) {
  @@ -87,20 +93,35 @@ function parseFlags(
  }
  }
  -function parseMention(
  +async function parseMention(
  args: Record<string, unknown>,
  entry: MentionArgument,
  - argsNullable: Array<string | null>
  -): void {
  + argsNullable: Array<string | null>,
  + client: Client,
  + message: Message
  +): Promise<void> {
  const regex = mentionToRegex[entry.match]
  const index = argsNullable.findIndex(
  (x) => typeof x === 'string' && regex.test(x)
  )
  const regexMatches = regex.exec(argsNullable[index]!)
  - args[entry.name] =
  - regexMatches !== null
  - ? regexMatches[0].replace(regex, '$1')
  - : entry.defaultValue
  + const tempValue = regexMatches !== null ? regexMatches[0].replace(regex, '$1') : null
  + let temp;
  + switch (entry.match) {
  + case "channel":
  + temp = tempValue ? await client.channels.get(tempValue) : entry.defaultValue
  + break
  +
  + case "user":
  + temp = tempValue ? await client.users.get(tempValue) : entry.defaultValue
  + break
  +
  + case "role":
  + temp = tempValue ? await message.guild?.roles.get(tempValue) : entry.defaultValue;
  + break
  + }
  +
  + args[entry.name] = temp;
  argsNullable[index] = null
  }
  