mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-29 00:46:26 -08:00
work a bit on DiscordAPI
This commit is contained in:
parent
412a117e15
commit
c14ddf8397
|
@ -51,12 +51,28 @@ export class Client {
|
||||||
// https://discord.com/developers/docs/resources/channel#bulk-delete-messages
|
// https://discord.com/developers/docs/resources/channel#bulk-delete-messages
|
||||||
// "This endpoint will not delete messages older than 2 weeks" so we need to check each id
|
// "This endpoint will not delete messages older than 2 weeks" so we need to check each id
|
||||||
async deleteMessages(ids: string[]) {
|
async deleteMessages(ids: string[]) {
|
||||||
// TODO check if any are older than two weeks
|
|
||||||
await this.rest.fetch(`/channels/${this.targetChannel}/messages/bulk-delete`, {method: "POST",body: JSON.stringify({messages: ids})})
|
// Remove bulk deletable messages
|
||||||
ids.forEach(Map.prototype.delete.bind(this.messageCache))
|
|
||||||
|
let bulkDeletable = ids.filter(e => convertSnowflakeToDate(e).valueOf() < 2 * 7 * 24 * 60 * 60 * 1000)
|
||||||
|
await this.rest.fetch(`/channels/${this.targetChannel}/messages/bulk-delete`, {method: "POST",body: JSON.stringify({messages: bulkDeletable})})
|
||||||
|
bulkDeletable.forEach(Map.prototype.delete.bind(this.messageCache))
|
||||||
|
|
||||||
|
// everything else, we can do manually...
|
||||||
|
// there's probably a better way to do this @Jack5079
|
||||||
|
// fix for me if possible
|
||||||
|
await Promise.all(ids.map(async e => {
|
||||||
|
if (convertSnowflakeToDate(e).valueOf() >= 2 * 7 * 24 * 60 * 60 * 1000) {
|
||||||
|
return await this.deleteMessage(e)
|
||||||
|
}
|
||||||
|
}).filter(Boolean)) // filter based on whether or not it's undefined
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendDataMessage(formData: FormData) {
|
async sendDataMessage(formData: FormData) {
|
||||||
|
this.rest.fetch(`/channels/${this.targetChannel}/messages`, {
|
||||||
|
method: "POST",
|
||||||
|
body: formData
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue