-
Notifications
You must be signed in to change notification settings - Fork 418
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
Attachment type #1358
Open
coolcalcacol
wants to merge
4
commits into
abalabahaha:dev
Choose a base branch
from
coolcalcacol:attachments-type
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+152
−38
Open
Attachment type #1358
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,80 @@ | ||
"use strict"; | ||
|
||
const Base = require("./Base"); | ||
|
||
/** | ||
* Represents an attachment | ||
* @prop {String?} contentType The attachment's media type | ||
* @prop {String?} description The description for the file (max 1024 characters) | ||
* @prop {Number?} durationSeconds The duration of the audio file (currently for voice messages) | ||
* @prop {Boolean?} ephemeral Whether the attachment is ephemeral | ||
* @prop {String} filename The name of file attached | ||
* @prop {Number?} flags The attachment flags combined as a bitfield | ||
* @prop {Number?} height The height of file (if image) | ||
* @prop {String} id The attachment ID | ||
* @prop {String} proxyURL The proxy URL of the attachment | ||
* @prop {Number} size The size of the file in bytes | ||
* @prop {String?} title The title of the file | ||
* @prop {String} url The source URL of the file | ||
* @prop {String?} waveform The base64 encoded bytearray representing a sampled waveform (currently for voice messages) | ||
* @prop {Number?} width The width of file (if image) | ||
*/ | ||
class Attachment extends Base { | ||
constructor(data) { | ||
super(data.id); | ||
|
||
this.filename = data.filename; | ||
this.proxyURL = data.proxy_url; | ||
this.size = data.size; | ||
this.url = data.url; | ||
|
||
if (data.content_type !== undefined) { | ||
this.contentType = data.content_type; | ||
} | ||
if (data.description !== undefined) { | ||
this.description = data.description; | ||
} | ||
if (data.duration_secs !== undefined) { | ||
this.durationSeconds = data.duration_secs; | ||
} | ||
if (data.ephemeral !== undefined) { | ||
this.ephemeral = data.ephemeral; | ||
} | ||
if (data.flags !== undefined) { | ||
this.flags = data.flags; | ||
} | ||
if (data.height !== undefined) { | ||
this.height = data.height; | ||
} | ||
if (data.title !== undefined) { | ||
this.title = data.title; | ||
} | ||
if (data.waveform !== undefined) { | ||
this.waveform = data.waveform; | ||
} | ||
if (data.width !== undefined) { | ||
this.width = data.width; | ||
} | ||
} | ||
|
||
toJSON(props = []) { | ||
return super.toJSON([ | ||
"contentType", | ||
"description", | ||
"durationSeconds", | ||
"ephemeral", | ||
"filename", | ||
"flags", | ||
"height", | ||
"proxyURL", | ||
"size", | ||
"title", | ||
"url", | ||
"waveform", | ||
"width", | ||
...props, | ||
]); | ||
} | ||
} | ||
|
||
module.exports = Attachment; |
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 |
---|---|---|
|
@@ -4,6 +4,8 @@ const Base = require("./Base"); | |
const Endpoints = require("../rest/Endpoints"); | ||
const { MessageFlags } = require("../Constants"); | ||
const User = require("./User"); | ||
const Attachment = require("./Attachment"); | ||
const Collection = require("../util/Collection"); | ||
|
||
/** | ||
* Represents a message | ||
|
@@ -61,6 +63,7 @@ class Message extends Base { | |
super(data.id); | ||
this._client = client; | ||
this.type = data.type || 0; | ||
this.attachments = new Collection(Attachment); | ||
this.timestamp = Date.parse(data.timestamp); | ||
this.channel = this._client.getChannel(data.channel_id) || { | ||
id: data.channel_id, | ||
|
@@ -166,6 +169,12 @@ class Message extends Base { | |
this.member = null; | ||
} | ||
|
||
if (data.attachments) { | ||
for (const attachment of data.attachments) { | ||
this.attachments.add(attachment, this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be able to update/delete, or overwrite completely |
||
} | ||
} | ||
|
||
this.update(data, client); | ||
} | ||
|
||
|
@@ -194,14 +203,21 @@ class Message extends Base { | |
if (data.pinned !== undefined) { | ||
this.pinned = !!data.pinned; | ||
} | ||
if (data.edited_timestamp != undefined) { | ||
if (data.edited_timestamp !== undefined) { | ||
this.editedTimestamp = Date.parse(data.edited_timestamp); | ||
} | ||
if (data.tts !== undefined) { | ||
this.tts = data.tts; | ||
} | ||
if (data.attachments !== undefined) { | ||
this.attachments = data.attachments; | ||
if (data.attachments) { | ||
for (const id of this.attachments.keys()) { | ||
if (!data.attachments.some((attachment) => attachment.id === id)) { | ||
this.attachments.delete(id); | ||
} | ||
} | ||
for (const attachment of data.attachments) { | ||
this.attachments.update(attachment, this); | ||
} | ||
} | ||
if (data.embeds !== undefined) { | ||
this.embeds = data.embeds; | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like some of these properties can be modified