Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] feat(interaction): added user option to command options #32

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lizclipse
Copy link

@lizclipse lizclipse commented Aug 9, 2023

Adds a UserOption to allow slash commands to select and target users.

This is a draft currently, as (a) I'm still ramping up on Swift (making a Discord bot is my first real use of it), and (b) while this functions, it is less than ideal, as the interaction data provides all of the user information but this currently only gives the ID to consuming code. Ideally, it should pull out the user data and make it available to users of the package nicely, but for now it's working as an MVP so I can actually use it.

As to why I've opened the PR, mostly it's so I can get a 'no don't do that' early on if I'm going down the wrong path, and possibly to look at expanding it out to adding more of the options as well.

I've also tweaked the BotMessage class as well, since there's a lot of useful info in the Message that seems to get thrown away (e.g. I want access to the author ID, as I want to filter out messages created by the bot itself when using the createChannelMsg method). If this isn't wanted, I'll revert it, not exactly attached to it.

For future reference (mostly for myself), this is an example interaction object (with all sensitive values stripped out):

Interaction Object
{
  "t": "INTERACTION_CREATE",
  "s": 3,
  "op": 0,
  "d": {
    "version": 1,
    "type": 2,
    "token": "(string)",
    "member": {
      "user": {
        "username": "(string)",
        "public_flags": 0,
        "id": "(snowflake)",
        "global_name": "(string)",
        "discriminator": "0",
        "avatar_decoration": null,
        "avatar": "(string)"
      },
      "unusual_dm_activity_until": null,
      "roles": [
        "(snowflake)",
        "(snowflake)",
        "(snowflake)",
        "(snowflake)",
        "(snowflake)",
        "(snowflake)"
      ],
      "premium_since": null,
      "permissions": "(stringified int)",
      "pending": false,
      "nick": "(string)",
      "mute": false,
      "joined_at": "(ISO datetime)",
      "flags": 0,
      "deaf": false,
      "communication_disabled_until": null,
      "avatar": null
    },
    "locale": "en-GB",
    "id": "(snowflake)",
    "guild_locale": "ru",
    "guild_id": "(snowflake)",
    "guild": {
      "locale": "ru",
      "id": "(snowflake)",
      "features": [
        "THREE_DAY_THREAD_ARCHIVE",
        "SEVEN_DAY_THREAD_ARCHIVE",
        "MEMBER_PROFILES",
        "BANNER",
        "ROLE_ICONS",
        "PRIVATE_THREADS",
        "INVITE_SPLASH",
        "ANIMATED_ICON"
      ]
    },
    "entitlements": [],
    "entitlement_sku_ids": [],
    "data": {
      "type": 1,
      "resolved": {
        "users": {
          "(snowflake#1)": {
            "username": "(string)",
            "public_flags": 64,
            "id": "(snowflake#1)",
            "global_name": "(string)",
            "discriminator": "0",
            "avatar_decoration": null,
            "avatar": "(string)"
          }
        },
        "members": {
          "(snowflake#1)": {
            "unusual_dm_activity_until": null,
            "roles": [
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)",
              "(snowflake)"
            ],
            "premium_since": null,
            "permissions": "(stringified int)",
            "pending": false,
            "nick": "(string)",
            "joined_at": "(ISO datetime)",
            "flags": 0,
            "communication_disabled_until": null,
            "avatar": null
          }
        }
      },
      "options": [
        { "value": "(snowflake#1)", "type": 6, "name": "target" }
      ],
      "name": "(string:command name)",
      "id": "(snowflake)",
      "guild_id": "(snowflake)"
    },
    "channel_id": "(snowflake)",
    "channel": {
      "type": 0,
      "topic": "(string)",
      "rate_limit_per_user": 0,
      "position": 46,
      "permissions": "(stringified int)",
      "parent_id": "(snowflake)",
      "nsfw": true,
      "name": "(string)",
      "last_pin_timestamp": "(ISO datetime)",
      "last_message_id": "(snowflake)",
      "id": "(snowflake)",
      "guild_id": "(snowflake)",
      "flags": 0
    },
    "application_id": "(snowflake)",
    "app_permissions": "(stringified int)"
  }
}

@lizclipse lizclipse changed the title feat(interaction): added user option to command options [DRAFT] feat(interaction): added user option to command options Aug 9, 2023
@cryptoAlgorithm
Copy link
Member

You're off to a great start! I feel that including the API message struct within BotMessage is a great addition, as that makes referencing new properties from the original message struct simple.

@lizclipse
Copy link
Author

lizclipse commented Nov 12, 2024

I stopped working on this because I stopped working on the bot I have (it's just a for-fun one), but I'm back at it and will try to update this a bit more. Will want to actually try out the interaction changes before marking the PR as ready, tho.

Just as an aside, does this project have any formatter set up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants