forked from IanMitchell/aquarius
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregex.js
More file actions
89 lines (73 loc) · 2.04 KB
/
Copy pathregex.js
File metadata and controls
89 lines (73 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Discord Regex Helpers
* See: https://discordapp.com/developers/docs/reference#message-formatting
*/
/**
* Matches a generic mention. Captures the `id` of the mentioned object.
*/
export const MENTION = /<(?:(?:@[!&]?)|#)(?<id>\d+)>/i;
/**
* Matches a mentioned User. Captures the `id` of the User.
*/
export const MENTION_USER = /<@!?(?<id>\d+)>/i;
/**
* Matches an ID-mentioned User. Captures the `id` of the User.
*/
export const MENTION_USER_ID = /<@(?<id>\d+)>/i;
/**
* Matches a nickname-mentioned User. Captures the `id` of the User.
*/
export const MENTION_USER_NICKNAME = /<@!(?<id>\d+)>/i;
/**
* Matches a mentioned Channel. Captures the `id` of the Channel.
*/
export const MENTION_CHANNEL = /<#(?<id>\d+)>/i;
/**
* Matches a mentioned Role. Captures the `id` of the Role.
*/
export const MENTION_ROLE = /<@&(?<id>\d+)>/i;
/**
* Matches Emojis. Captures the `name` and `id` of the Emoji.
*/
export const EMOJI = /<a?:(?<name>.+):(?<id>.+):>/i;
/**
* Matches Custom Emojis. Captures the `name` and `id` of the Emoji.
*/
export const CUSTOM_EMOJI = /<:(?<name>.+):(?<id>.+)>/i;
/**
* Matches Animated Emojis. Captures the `name` and `id` of the Emoji.
*/
export const ANIMATED_EMOJI = /<a:(?<name>.+):(?<id>.+)>/i;
/**
* Custom Regex Helpers
*/
/**
* Matches [[Bracket String]] syntax. Captures the text as `name`
*/
export const BRACKET = /\[\[(?<name>.+?)\]\]/i;
/**
* The different types of Discord mentions
* @enum {string}
*/
export const MENTION_TYPES = {
USER: 'user',
CHANNEL: 'channel',
ROLE: 'role',
};
/**
* Determines what kind of mention it is based on the markup of the Snowflake ID
* @param {string} mention - The mention to check. Must be the formatted block, not an ID.
* @returns {?MENTION_TYPES} The type of mention
*/
export function getMentionType(mention) {
if (MENTION_USER.test(mention)) {
return MENTION_TYPES.USER;
}
if (MENTION_CHANNEL.test(mention)) {
return MENTION_TYPES.CHANNEL;
}
if (MENTION_ROLE.test(mention)) {
return MENTION_TYPES.ROLE;
}
return null;
}