Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Widget): wrapper for widget.json (#5619)
Co-authored-by: monbrey <rsm999@uowmail.edu.au> Co-authored-by: BannerBomb <BannerBomb55@gmail.com> Co-authored-by: SpaceEEC <spaceeec@yahoo.com> Co-authored-by: Antonio Román <kyradiscord@gmail.com> Co-authored-by: Noel <icrawltogo@gmail.com>
- Loading branch information
1 parent
a6dae75
commit 038ee99
Showing
5 changed files
with
237 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
'use strict'; | ||
|
||
const Base = require('./Base'); | ||
const WidgetMember = require('./WidgetMember'); | ||
const Collection = require('../util/Collection'); | ||
|
||
/** | ||
* Represents a Widget. | ||
*/ | ||
class Widget extends Base { | ||
/** | ||
* @param {Client} client The instantiating client | ||
* @param {Object} data The raw data | ||
*/ | ||
constructor(client, data) { | ||
super(client); | ||
this._patch(data); | ||
} | ||
|
||
/** | ||
* Builds the widget with the provided data. | ||
* @param {*} data The raw data of the widget | ||
* @private | ||
*/ | ||
_patch(data) { | ||
/** | ||
* The id of the guild. | ||
* @type {Snowflake} | ||
*/ | ||
this.id = data.id; | ||
|
||
/** | ||
* The name of the guild. | ||
* @type {string} | ||
*/ | ||
this.name = data.name; | ||
|
||
/** | ||
* The invite of the guild. | ||
* @type {?string} | ||
*/ | ||
this.instantInvite = data.instant_invite; | ||
|
||
/** | ||
* The list of channels in the guild. | ||
* @type {Collection<Snowflake, WidgetChannel>} | ||
*/ | ||
this.channels = new Collection(); | ||
for (const channel of data.channels) { | ||
this.channels.set(channel.id, channel); | ||
} | ||
|
||
/** | ||
* The list of members in the guild. | ||
* These strings are just arbitrary numbers, they aren't Snowflakes. | ||
* @type {Collection<string, WidgetMember>} | ||
*/ | ||
this.members = new Collection(); | ||
for (const member of data.members) { | ||
this.members.set(member.id, new WidgetMember(this.client, member)); | ||
} | ||
|
||
/** | ||
* The number of the members online. | ||
* @type {number} | ||
*/ | ||
this.presenceCount = data.presence_count; | ||
} | ||
|
||
/** | ||
* Update the Widget. | ||
* @returns {Promise<Widget>} | ||
*/ | ||
async fetch() { | ||
const data = await this.client.api.guilds(this.id, 'widget.json').get(); | ||
this._patch(data); | ||
return this; | ||
} | ||
} | ||
|
||
module.exports = Widget; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
'use strict'; | ||
|
||
const Base = require('./Base'); | ||
|
||
/** | ||
* Represents a WidgetMember. | ||
*/ | ||
class WidgetMember extends Base { | ||
/** | ||
* Activity sent in a {@link WidgetMember}. | ||
* @typedef {Object} WidgetActivity | ||
* @property {string} name The name of the activity | ||
*/ | ||
|
||
/** | ||
* @param {Client} client The instantiating client | ||
* @param {Object} data The raw data | ||
*/ | ||
constructor(client, data) { | ||
super(client); | ||
|
||
/** | ||
* The id of the user. It's an arbitrary number. | ||
* @type {string} | ||
*/ | ||
this.id = data.id; | ||
|
||
/** | ||
* The username of the member. | ||
* @type {string} | ||
*/ | ||
this.username = data.username; | ||
|
||
/** | ||
* The discriminator of the member. | ||
* @type {string} | ||
*/ | ||
this.discriminator = data.discriminator; | ||
|
||
/** | ||
* The avatar of the member. | ||
* @type {?string} | ||
*/ | ||
this.avatar = data.avatar; | ||
|
||
/** | ||
* The status of the member. | ||
* @type {PresenceStatus} | ||
*/ | ||
this.status = data.status; | ||
|
||
/** | ||
* IIf the member is server deafened | ||
* @type {?boolean} | ||
*/ | ||
this.deaf = data.deaf; | ||
|
||
/** | ||
* If the member is server muted | ||
* @type {?boolean} | ||
*/ | ||
this.mute = data.mute; | ||
|
||
/** | ||
* If the member is self deafened | ||
* @type {?boolean} | ||
*/ | ||
this.selfDeaf = data.self_deaf; | ||
|
||
/** | ||
* If the member is self muted | ||
* @type {?boolean} | ||
*/ | ||
this.selfMute = data.self_mute; | ||
|
||
/** | ||
* If the member is suppressed | ||
* @type {?boolean} | ||
*/ | ||
this.suppress = data.suppress; | ||
|
||
/** | ||
* The id of the voice channel the member is in, if any | ||
* @type {?Snowflake} | ||
*/ | ||
this.channelID = data.channel_id; | ||
|
||
/** | ||
* The avatar URL of the member. | ||
* @type {string} | ||
*/ | ||
this.avatarURL = data.avatar_url; | ||
|
||
/** | ||
* The activity of the member. | ||
* @type {?WidgetActivity} | ||
*/ | ||
this.activity = data.activity; | ||
} | ||
} | ||
|
||
module.exports = WidgetMember; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters