Skip to content

Commit

Permalink
feat: mention for slash commands (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
acollierr17 committed Oct 8, 2022
1 parent 6ad2889 commit 294d0b5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
8 changes: 4 additions & 4 deletions packages/core/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ export namespace Components {
*/
"highlight": boolean;
/**
* The type of mention this should be. This will prepend the proper prefix character. Valid values: `user`, `channel`, `role`, `voice`, `locked`, `thread`, and `forum`.
* The type of mention this should be. This will prepend the proper prefix character. Valid values: `user`, `channel`, `role`, `voice`, `locked`, `thread`, `forum`, and `slash`.
*/
"type": 'user' | 'channel' | 'role' | 'voice' | 'locked' | 'thread' | 'forum';
"type": 'user' | 'channel' | 'role' | 'voice' | 'locked' | 'thread' | 'forum' | 'slash';
}
interface DiscordMessage {
/**
Expand Down Expand Up @@ -902,9 +902,9 @@ declare namespace LocalJSX {
*/
"highlight"?: boolean;
/**
* The type of mention this should be. This will prepend the proper prefix character. Valid values: `user`, `channel`, `role`, `voice`, `locked`, `thread`, and `forum`.
* The type of mention this should be. This will prepend the proper prefix character. Valid values: `user`, `channel`, `role`, `voice`, `locked`, `thread`, `forum`, and `slash`.
*/
"type"?: 'user' | 'channel' | 'role' | 'voice' | 'locked' | 'thread' | 'forum';
"type"?: 'user' | 'channel' | 'role' | 'voice' | 'locked' | 'thread' | 'forum' | 'slash';
}
interface DiscordMessage {
/**
Expand Down
13 changes: 9 additions & 4 deletions packages/core/src/components/discord-mention/discord-mention.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,19 @@ export class DiscordMention implements ComponentInterface {

/**
* The type of mention this should be. This will prepend the proper prefix character.
* Valid values: `user`, `channel`, `role`, `voice`, `locked`, `thread`, and `forum`.
* Valid values: `user`, `channel`, `role`, `voice`, `locked`, `thread`, `forum`, and `slash`.
*/
@Prop()
public type: 'user' | 'channel' | 'role' | 'voice' | 'locked' | 'thread' | 'forum' = 'user';
public type: 'user' | 'channel' | 'role' | 'voice' | 'locked' | 'thread' | 'forum' | 'slash' = 'user';

@Watch('type')
public handleType(value: string) {
if (typeof value !== 'string') {
throw new TypeError('DiscordMention `type` prop must be a string.');
} else if (!['user', 'channel', 'role', 'voice', 'locked', 'thread', 'forum'].includes(value)) {
throw new RangeError("DiscordMention `type` prop must be one of: 'user', 'channel', 'role', 'voice', 'locked', 'thread', 'forum'");
} else if (!['user', 'channel', 'role', 'voice', 'locked', 'thread', 'forum', 'slash'].includes(value)) {
throw new RangeError(
"DiscordMention `type` prop must be one of: 'user', 'channel', 'role', 'voice', 'locked', 'thread', 'forum', 'slash'"
);
}
}

Expand Down Expand Up @@ -101,6 +103,9 @@ export class DiscordMention implements ComponentInterface {
case 'forum':
mentionPrepend = <ChannnelForum class="discord-mention-icon" />;
break;
case 'slash':
mentionPrepend = '/';
break;
}

return (
Expand Down
10 changes: 5 additions & 5 deletions packages/core/src/components/discord-mention/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

## Properties

| Property | Attribute | Description | Type | Default |
| ----------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- | ----------- |
| `color` | `color` | The color to use for this mention. Only works for role mentions and must be in hex format. | `string` | `undefined` |
| `highlight` | `highlight` | Whether this entire message block should be highlighted (to emulate the "logged in user" being pinged). | `boolean` | `false` |
| `type` | `type` | The type of mention this should be. This will prepend the proper prefix character. Valid values: `user`, `channel`, `role`, `voice`, `locked`, `thread`, and `forum`. | `"channel" \| "forum" \| "locked" \| "role" \| "thread" \| "user" \| "voice"` | `'user'` |
| Property | Attribute | Description | Type | Default |
| ----------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------- | ----------- |
| `color` | `color` | The color to use for this mention. Only works for role mentions and must be in hex format. | `string` | `undefined` |
| `highlight` | `highlight` | Whether this entire message block should be highlighted (to emulate the "logged in user" being pinged). | `boolean` | `false` |
| `type` | `type` | The type of mention this should be. This will prepend the proper prefix character. Valid values: `user`, `channel`, `role`, `voice`, `locked`, `thread`, `forum`, and `slash`. | `"channel" \| "forum" \| "locked" \| "role" \| "slash" \| "thread" \| "user" \| "voice"` | `'user'` |

---

Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ <h3 class="title">Mentions</h3>
Hey there
<discord-mention highlight>Maximillian Osborn</discord-mention>, thanks! I will!
</discord-message>
<discord-message profile="maximillian">
Also, make sure to run <discord-mention type="slash">profile</discord-mention> to create your server profile!
</discord-message>
</discord-messages>
<h3 class="title">Custom Discord Emojis</h3>
<discord-messages>
Expand Down

0 comments on commit 294d0b5

Please sign in to comment.