1
1
/**
2
- * Get serialized number
3
- * @param {Array<Object> } idList - An array containing objects about user identification.
4
- * @return {Array<String> } - Contains serialized phone numbers
2
+ * Get serialized phone number from a given array of users.
3
+ * @param {Contact[] } users - Whatsapp users.
4
+ * @see https://docs.wwebjs.dev/Contact.html
5
+ * @returns {string[] } - Serialized phone numbers.
5
6
*/
6
- function getSerialList ( idList ) {
7
+ function getSerialList ( users ) {
7
8
// eslint-disable-next-line no-underscore-dangle
8
- const serialList = idList . map ( ( id ) => id . id . _serialized ) ;
9
+ const serialList = users . map ( ( u ) => u . id . _serialized ) ;
9
10
return serialList ;
10
11
}
11
12
12
13
/**
13
- * Get serialized number of all members in group
14
- * @param {Object } chat - Object that represents the current chat
15
- * @return {Array<String> } - Contains serialized phone numbers of all members
14
+ * Get serialized phone number of all members from a given group.
15
+ * @param {Chat } chat - A whatsapp chat.
16
+ * @see https://docs.wwebjs.dev/Chat.html
17
+ * @returns {string[] } - Serialized phone numbers of all members.
16
18
*/
17
19
async function getMembersList ( chat ) {
18
20
const members = await chat . participants ;
@@ -21,9 +23,10 @@ async function getMembersList(chat) {
21
23
}
22
24
23
25
/**
24
- * Get serialized number of all administrators in group
25
- * @param {Object } chat - Object that represents the current chat
26
- * @return {Array<String> } - Contains serialized phone numbers of all administrators
26
+ * Get serialized phone number of all administrators from a given group.
27
+ * @param {Chat } chat - A whatsapp chat.
28
+ * @see https://docs.wwebjs.dev/Chat.html
29
+ * @returns {string[] } - Serialized phone numbers of all administrators.
27
30
*/
28
31
async function getAdmsList ( chat ) {
29
32
const members = await chat . participants ;
@@ -33,9 +36,10 @@ async function getAdmsList(chat) {
33
36
}
34
37
35
38
/**
36
- * Check if a message if from an adm
37
- * @param {Object } message - Object that represents the current message
38
- * @return {Boolean }
39
+ * Checks if a message is from an ADM.
40
+ * @param {Message } message - Message to check if is from an ADM.
41
+ * @see https://docs.wwebjs.dev/Message.html
42
+ * @returns {boolean }
39
43
*/
40
44
async function isAdm ( message ) {
41
45
const chat = await message . getChat ( ) ;
@@ -44,12 +48,17 @@ async function isAdm(message) {
44
48
return admList . includes ( author ) ;
45
49
}
46
50
47
- function userID ( targetNumber ) {
48
- if ( typeof targetNumber !== 'string' ) {
51
+ /**
52
+ * Get a whatsapp user id for a given phone number.
53
+ * @param {string } phoneNumber
54
+ * @returns {string }
55
+ */
56
+ function userID ( phoneNumber ) {
57
+ if ( typeof phoneNumber !== 'string' ) {
49
58
throw new Error ( 'you must pass the number as a string' ) ;
50
59
}
51
60
52
- const target = targetNumber . replace ( / \D / g, '' ) ;
61
+ const target = phoneNumber . replace ( / \D / g, '' ) ;
53
62
const regexp = / \d + / ;
54
63
const matches = target . match ( regexp ) ;
55
64
const pattern = matches [ 0 ] ;
0 commit comments