From f2c322909bf09e98a3170dcb3069747c8cbaa1d4 Mon Sep 17 00:00:00 2001 From: SwayUser Date: Thu, 9 Jan 2020 08:50:54 +0100 Subject: [PATCH 01/12] Add the ability to delete from multiple channels --- deleteDiscordMessages.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/deleteDiscordMessages.js b/deleteDiscordMessages.js index ac90e7e4..9dca4200 100644 --- a/deleteDiscordMessages.js +++ b/deleteDiscordMessages.js @@ -54,7 +54,7 @@ const authToken = popup.document.querySelector('input#authToken').value.trim(); const authorId = popup.document.querySelector('input#authorId').value.trim(); const guildId = popup.document.querySelector('input#guildId').value.trim(); - const channelId = popup.document.querySelector('input#channelId').value.trim(); + const channelIds = popup.document.querySelector('input#channelId').value.trim().split(";"); const afterMessageId = popup.document.querySelector('input#afterMessageId').value.trim(); const beforeMessageId = popup.document.querySelector('input#beforeMessageId').value.trim(); const content = popup.document.querySelector('input#content').value.trim(); @@ -62,7 +62,7 @@ const hasFile = popup.document.querySelector('input#hasFile').checked; const includeNsfw = popup.document.querySelector('input#includeNsfw').checked; stop = stopBtn.disabled = !(startBtn.disabled = true); - deleteMessages(authToken, authorId, guildId, channelId, afterMessageId, beforeMessageId, content, hasLink, hasFile, includeNsfw, logger, () => !(stop === true || popup.closed)).then(() => { + deleteMessages(authToken, authorId, guildId, channelIds, afterMessageId, beforeMessageId, content, hasLink, hasFile, includeNsfw, logger, () => !(stop === true || popup.closed)).then(() => { stop = stopBtn.disabled = !(startBtn.disabled = false); }); }; @@ -97,7 +97,7 @@ * @param {string} authToken Your authorization token * @param {string} authorId Author of the messages you want to delete * @param {string} guildId Server were the messages are located - * @param {string} channelId Channel were the messages are located + * @param {string[]} channelIds List of channels where the messages are located * @param {string} afterMessageId Only delete messages after this, leave blank do delete all * @param {string} beforeMessageId Only delete messages before this, leave blank do delete all * @param {string} content Filter messages that contains this text content @@ -109,7 +109,7 @@ * @author Victornpb * @see https://github.com/victornpb/deleteDiscordMessages */ - async function deleteMessages(authToken, authorId, guildId, channelId, afterMessageId, beforeMessageId, content,hasLink, hasFile, includeNsfw, extLogger, stopHndl) { + async function deleteMessages(authToken, authorId, guildId, channelIds, afterMessageId, beforeMessageId, content,hasLink, hasFile, includeNsfw, extLogger, stopHndl) { const start = new Date(); let deleteDelay = 100; let searchDelay = 100; @@ -122,6 +122,11 @@ let throttledTotalTime = 0; let offset = 0; let iterations = -1; + + if (channelIds.length == 0) { + return; + } + let channelId = channelIds[0]; const wait = async ms => new Promise(done => setTimeout(done, ms)); const msToHMS = s => `${s / 3.6e6 | 0}h ${(s % 3.6e6) / 6e4 | 0}m ${(s % 6e4) / 1000 | 0}s`; @@ -295,7 +300,10 @@ return await recurse(); } else { if (total - offset > 0) log.warn('Ended because API returned an empty page.'); - return end(); + end(); + channelIds.shift(); + await wait(searchDelay); + return deleteMessages(authToken, authorId, guildId, channelIds, afterMessageId, beforeMessageId, content,hasLink, hasFile, includeNsfw, extLogger, stopHndl); } } From c323c15f7a8bc52e4cc249c54a17832bb1033b78 Mon Sep 17 00:00:00 2001 From: SwayUser Date: Thu, 9 Jan 2020 09:35:52 +0100 Subject: [PATCH 02/12] Add ability to import a JSON file --- deleteDiscordMessages.js | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/deleteDiscordMessages.js b/deleteDiscordMessages.js index 9dca4200..e6942359 100644 --- a/deleteDiscordMessages.js +++ b/deleteDiscordMessages.js @@ -3,15 +3,16 @@ (function () { let stop; let popup; - popup = window.open('', '', `top=0,left=${screen.width-800},width=800,height=${screen.height}`); + popup = window.open('', '', `top=0,left=${screen.width-800},width=830,height=${screen.height}`); if (!popup) return console.error('Popup blocked! Please allow popups and try again.'); popup.document.write(/*html*/` Delete Discord Messages
@@ -21,7 +22,9 @@ Author ?
Guild/Channel ? -
+ + +


Range ?
@@ -50,6 +53,22 @@ const startBtn = popup.document.querySelector('button#start'); const stopBtn = popup.document.querySelector('button#stop'); const autoScroll = popup.document.querySelector('#autoScroll'); + const fileSelection = popup.document.querySelector("input#file"); + fileSelection.addEventListener("change", () => { + const files = fileSelection.files; + const channelIdField = popup.document.querySelector('input#channelId'); + if (files.length > 0) { + const file = files[0]; + file.text().then(text => { + let json = JSON.parse(text); + let channels = [] + Object.keys(json).forEach(k => { + channels.push(k); + }) + channelIdField.value = channels.join(";"); + }); + } + }, false); startBtn.onclick = e => { const authToken = popup.document.querySelector('input#authToken').value.trim(); const authorId = popup.document.querySelector('input#authorId').value.trim(); From 5cd265d247855b9e747e0983ae79b288750ae4f7 Mon Sep 17 00:00:00 2001 From: SwayUser Date: Thu, 9 Jan 2020 09:49:07 +0100 Subject: [PATCH 03/12] Add documentation --- help/channelId.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/help/channelId.md b/help/channelId.md index 74db7a32..27bcf7f4 100644 --- a/help/channelId.md +++ b/help/channelId.md @@ -10,16 +10,25 @@ ## The manual way ### For public channels: -- Right click a channel, [Copy ID](./developerMode.md) +- Right click a channel, [Copy ID](./developerMode.md) ### For a DM/Direct messages: -- copy the number after /@me/ in the URL) +- copy the number after /@me/ in the URL) +--- + +## Deleting all messages by using the "Request a Copy of your Data" option + +To delete all message from every (user) channel do following: +1. Go to "User Settings -> Privacy and Safety" and click on "Request all my Data." +2. You should receive an email within the next 30 days +3. Click on the "Import JSON" button the right JSON file is called "index.json" and is located in the messages folder (messages/index.json). +4. The channel IDs will be imported separated by a semi-colon. ----- -> If the `Copy ID` doesn't show up, you need to enable [Developer mode](./developerMode.md) first. \ No newline at end of file +> If the `Copy ID` doesn't show up, you need to enable [Developer mode](./developerMode.md) first. You can target multiple channels at once by separating them with a semi-colon (;). From 4e382f56930da2468f576bdb670f69a676d692f6 Mon Sep 17 00:00:00 2001 From: Matt Moran <15150339+DarkMatterMatt@users.noreply.github.com> Date: Tue, 9 Jun 2020 21:46:41 +1200 Subject: [PATCH 04/12] Add option to include/exclude pinned messages --- deleteDiscordMessages.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/deleteDiscordMessages.js b/deleteDiscordMessages.js index 1e130380..36a683b3 100644 --- a/deleteDiscordMessages.js +++ b/deleteDiscordMessages.js @@ -32,7 +32,8 @@


- +
+
@@ -61,8 +62,9 @@ const hasLink = popup.document.querySelector('input#hasLink').checked; const hasFile = popup.document.querySelector('input#hasFile').checked; const includeNsfw = popup.document.querySelector('input#includeNsfw').checked; + const includePinned = popup.document.querySelector('input#includePinned').checked; stop = stopBtn.disabled = !(startBtn.disabled = true); - deleteMessages(authToken, authorId, guildId, channelId, afterMessageId, beforeMessageId, content, hasLink, hasFile, includeNsfw, logger, () => !(stop === true || popup.closed)).then(() => { + deleteMessages(authToken, authorId, guildId, channelId, afterMessageId, beforeMessageId, content, hasLink, hasFile, includeNsfw, includePinned, logger, () => !(stop === true || popup.closed)).then(() => { stop = stopBtn.disabled = !(startBtn.disabled = false); }); }; @@ -109,7 +111,7 @@ * @author Victornpb * @see https://github.com/victornpb/deleteDiscordMessages */ - async function deleteMessages(authToken, authorId, guildId, channelId, afterMessageId, beforeMessageId, content,hasLink, hasFile, includeNsfw, extLogger, stopHndl) { + async function deleteMessages(authToken, authorId, guildId, channelId, afterMessageId, beforeMessageId, content,hasLink, hasFile, includeNsfw, includePinned, extLogger, stopHndl) { const start = new Date(); let deleteDelay = 100; let searchDelay = 100; @@ -211,6 +213,10 @@ const myMessages = data.messages.map(convo => convo.find(message => message.hit===true)); const systemMessages = myMessages.filter(msg => msg.type !== 0); // https://discord.com/developers/docs/resources/channel#message-object-message-types const deletableMessages = myMessages.filter(msg => msg.type === 0); + const messagesToDelete = deletableMessages.filter(msg => { + if (!includePinned && msg.pinned) return false; + return true; + }); const end = () => { log.success(`Ended at ${new Date().toLocaleString()}! Total time: ${msToHMS(Date.now() - start.getTime())}`); printDelayStats(); @@ -224,18 +230,18 @@ log.verb(`Estimated time remaining: ${etr}`) - if (myMessages.length > 0) { + if (messagesToDelete.length > 0) { if (iterations < 1) { log.verb(`Waiting for your confirmation...`); if (!await ask(`Do you want to delete ~${total} messages?\nEstimated time: ${etr}\n\n---- Preview ----\n` + - myMessages.map(m => `${m.author.username}#${m.author.discriminator}: ${m.attachments.length ? '[ATTACHMENTS]' : m.content}`).join('\n'))) + messagesToDelete.map(m => `${m.author.username}#${m.author.discriminator}: ${m.attachments.length ? '[ATTACHMENTS]' : m.content}`).join('\n'))) return end(log.error('Aborted by you!')); log.verb(`OK`); } - for (let i = 0; i < deletableMessages.length; i++) { - const message = deletableMessages[i]; + for (let i = 0; i < messagesToDelete.length; i++) { + const message = messagesToDelete[i]; if (stopHndl && stopHndl()===false) return end(log.error('Stopped by you!')); log.debug(`${((delCount + 1) / grandTotal * 100).toFixed(2)}% (${delCount + 1}/${grandTotal})`, From 4e2b05b368380e951b9e7176992eafd28bf789fd Mon Sep 17 00:00:00 2001 From: victornpb <3372598+victornpb@users.noreply.github.com> Date: Sat, 4 Jul 2020 17:20:16 -0300 Subject: [PATCH 05/12] shortening code --- deleteDiscordMessages.js | 49 +++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/deleteDiscordMessages.js b/deleteDiscordMessages.js index 5a46946c..2a6d2b49 100644 --- a/deleteDiscordMessages.js +++ b/deleteDiscordMessages.js @@ -46,41 +46,44 @@ Issues or help `); - const logArea = popup.document.querySelector('pre'); - const startBtn = popup.document.querySelector('button#start'); - const stopBtn = popup.document.querySelector('button#stop'); - const autoScroll = popup.document.querySelector('#autoScroll'); + const $ = s => popup.document.querySelector(s); + const logArea = $('pre'); + const startBtn = $('button#start'); + const stopBtn = $('button#stop'); + const autoScroll = $('#autoScroll'); startBtn.onclick = e => { - const authToken = popup.document.querySelector('input#authToken').value.trim(); - const authorId = popup.document.querySelector('input#authorId').value.trim(); - const guildId = popup.document.querySelector('input#guildId').value.trim(); - const channelId = popup.document.querySelector('input#channelId').value.trim(); - const afterMessageId = popup.document.querySelector('input#afterMessageId').value.trim(); - const beforeMessageId = popup.document.querySelector('input#beforeMessageId').value.trim(); - const content = popup.document.querySelector('input#content').value.trim(); - const hasLink = popup.document.querySelector('input#hasLink').checked; - const hasFile = popup.document.querySelector('input#hasFile').checked; - const includeNsfw = popup.document.querySelector('input#includeNsfw').checked; + const authToken = $('input#authToken').value.trim(); + const authorId = $('input#authorId').value.trim(); + const guildId = $('input#guildId').value.trim(); + const channelId = $('input#channelId').value.trim(); + const afterMessageId = $('input#afterMessageId').value.trim(); + const beforeMessageId = $('input#beforeMessageId').value.trim(); + const minId = $('input#minId').value.trim(); + const maxId = $('input#maxId').value.trim(); + const content = $('input#content').value.trim(); + const hasLink = $('input#hasLink').checked; + const hasFile = $('input#hasFile').checked; + const includeNsfw = $('input#includeNsfw').checked; stop = stopBtn.disabled = !(startBtn.disabled = true); deleteMessages(authToken, authorId, guildId, channelId, afterMessageId, beforeMessageId, content, hasLink, hasFile, includeNsfw, logger, () => !(stop === true || popup.closed)).then(() => { stop = stopBtn.disabled = !(startBtn.disabled = false); }); }; stopBtn.onclick = e => stop = stopBtn.disabled = !(startBtn.disabled = false); - popup.document.querySelector('button#clear').onclick = e => { logArea.innerHTML = ''; }; - popup.document.querySelector('button#getToken').onclick = e => { + $('button#clear').onclick = e => { logArea.innerHTML = ''; }; + $('button#getToken').onclick = e => { window.dispatchEvent(new Event('beforeunload')); - popup.document.querySelector('input#authToken').value = JSON.parse(popup.localStorage.token); + $('input#authToken').value = JSON.parse(popup.localStorage.token); }; - popup.document.querySelector('button#getAuthor').onclick = e => { - popup.document.querySelector('input#authorId').value = JSON.parse(popup.localStorage.user_id_cache); + $('button#getAuthor').onclick = e => { + $('input#authorId').value = JSON.parse(popup.localStorage.user_id_cache); }; - popup.document.querySelector('button#getGuildAndChannel').onclick = e => { + $('button#getGuildAndChannel').onclick = e => { const m = location.href.match(/channels\/([\w@]+)\/(\d+)/); - popup.document.querySelector('input#guildId').value = m[1]; - popup.document.querySelector('input#channelId').value = m[2]; + $('input#guildId').value = m[1]; + $('input#channelId').value = m[2]; }; - popup.document.querySelector('#redact').onchange = e => { + $('#redact').onchange = e => { popup.document.body.classList.toggle('redact') && popup.alert('This will attempt to hide personal information, but make sure to double check before sharing screenshots.'); }; From 7112e615bf745fc157d732245a478bc2f1ff9139 Mon Sep 17 00:00:00 2001 From: victornpb <3372598+victornpb@users.noreply.github.com> Date: Sat, 4 Jul 2020 17:20:36 -0300 Subject: [PATCH 06/12] renamed checkbox --- deleteDiscordMessages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deleteDiscordMessages.js b/deleteDiscordMessages.js index 2a6d2b49..53da3634 100644 --- a/deleteDiscordMessages.js +++ b/deleteDiscordMessages.js @@ -32,7 +32,7 @@


- +
From d805cfe81050914888b3ffdef25d32f1fc5bc87d Mon Sep 17 00:00:00 2001 From: victornpb <3372598+victornpb@users.noreply.github.com> Date: Sat, 4 Jul 2020 17:20:54 -0300 Subject: [PATCH 07/12] check for popupblockers --- deleteDiscordMessages.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deleteDiscordMessages.js b/deleteDiscordMessages.js index 53da3634..4e4ecc97 100644 --- a/deleteDiscordMessages.js +++ b/deleteDiscordMessages.js @@ -3,8 +3,8 @@ (function () { let stop; let popup; - popup = window.open('', '', `top=0,left=${screen.width-800},width=800,height=${screen.height}`); - if (!popup) return console.error('Popup blocked! Please allow popups and try again.'); + if (popup && popup.document && popup.document.write) popup = window.open('', '', `top=0,left=${screen.width-800},width=980,height=${screen.height}`); + else return console.error('Popup blocked! Please allow popups and try again.'); popup.document.write(/*html*/` Delete Discord Messages
@@ -22,23 +22,23 @@ Author ?
Guild/Channel ? - - -
+

-

+
+

+ +
Range ?
+
+


-
-
Filter ?



- - +
@@ -46,6 +46,8 @@ + +
         
Star this project on github.com/victornpb/deleteDiscordMessages!\n\n @@ -71,6 +73,7 @@ const hasFile = $('input#hasFile').checked; const includeNsfw = $('input#includeNsfw').checked; const includePinned = $('input#includePinned').checked; + const progress = $('#progress'); const fileSelection = $("input#file"); fileSelection.addEventListener("change", () => { @@ -98,7 +101,7 @@ stop = stopBtn.disabled = !(startBtn.disabled = true); for (let i = 0; i < channelIds.length; i++) { await deleteMessages(authToken, authorId, guildId, channelIds[i], afterMessageId, beforeMessageId, content, hasLink, hasFile, includeNsfw, includePinned, logger, stopHndl, onProg); - stop = stopBtn.disabled = !(startBtn.disabled = false); + stop = stopBtn.disabled = !(startBtn.disabled = false); } }; stopBtn.onclick = e => stop = stopBtn.disabled = !(startBtn.disabled = false); @@ -241,13 +244,12 @@ const data = await resp.json(); const total = data.total_results; if (!grandTotal) grandTotal = total; - const myMessages = data.messages.map(convo => convo.find(message => message.hit===true)); - const systemMessages = myMessages.filter(msg => msg.type !== 0); // https://discord.com/developers/docs/resources/channel#message-object-message-types - const deletableMessages = myMessages.filter(msg => msg.type === 0 || msg.type === 6); - const messagesToDelete = deletableMessages.filter(msg => { - if (!includePinned && msg.pinned) return false; - return true; + const discoveredMessages = data.messages.map(convo => convo.find(message => message.hit===true)); + const messagesToDelete = discoveredMessages.filter(msg => { + return msg.type === 0 || msg.type === 6 || (msg.pinned && includePinned); }); + const skippedMessages = discoveredMessages.filter(msg=>!messagesToDelete.find(m=> m.id===msg.id)); + const end = () => { log.success(`Ended at ${new Date().toLocaleString()}! Total time: ${msToHMS(Date.now() - start.getTime())}`); printDelayStats(); @@ -256,7 +258,7 @@ } const etr = msToHMS((searchDelay * Math.round(total / 25)) + ((deleteDelay + avgPing) * total)); - log.info(`Total messages found: ${data.total_results}`, `(Messages in current page: ${data.messages.length}, Author: ${deletableMessages.length}, System: ${systemMessages.length})`, `offset: ${offset}`); + log.info(`Total messages found: ${data.total_results}`, `(Messages in current page: ${data.messages.length}, To be deleted: ${messagesToDelete.length}, System: ${skippedMessages.length})`, `offset: ${offset}`); printDelayStats(); log.verb(`Estimated time remaining: ${etr}`) @@ -319,10 +321,10 @@ await wait(deleteDelay); } - if (systemMessages.length > 0) { - grandTotal -= systemMessages.length; - offset += systemMessages.length; - log.verb(`Found ${systemMessages.length} system messages! Decreasing grandTotal to ${grandTotal} and increasing offset to ${offset}.`); + if (skippedMessages.length > 0) { + grandTotal -= skippedMessages.length; + offset += skippedMessages.length; + log.verb(`Found ${skippedMessages.length} system messages! Decreasing grandTotal to ${grandTotal} and increasing offset to ${offset}.`); } log.verb(`Searching next messages in ${searchDelay}ms...`, (offset ? `(offset: ${offset})` : '') ); From 2eab9147b675af895bdb3adfadffc49026ce22ba Mon Sep 17 00:00:00 2001 From: victornpb <3372598+victornpb@users.noreply.github.com> Date: Sat, 4 Jul 2020 21:08:41 -0300 Subject: [PATCH 12/12] Implemented range of dates and some minor layout tweaks --- deleteDiscordMessages.js | 59 ++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/deleteDiscordMessages.js b/deleteDiscordMessages.js index 2e95dbbb..8dffd289 100644 --- a/deleteDiscordMessages.js +++ b/deleteDiscordMessages.js @@ -3,53 +3,53 @@ (function () { let stop; let popup; - popup = window.open('', '', `top=0,left=${screen.width-800},width=980,height=${screen.height}`); + popup = window.open('', '', `top=0,left=${screen.width-800},width=850,height=${screen.height}`); if(!popup || !popup.document || !popup.document.write) return console.error('Popup blocked! Please allow popups and try again.'); popup.document.write(/*html*/` Delete Discord Messages -
- Authorization ? -
+ Authorization ?
*
- Author ? -
+ Author ? +
Guild/Channel ? -
+




- +

Range ?
-
-
-
-
+
+
+
+
- Filter ?
+ Search messages ?



+
- - + +
-
+    
         
Star this project on github.com/victornpb/deleteDiscordMessages!\n\n Issues or help
`); @@ -64,10 +64,10 @@ const authorId = $('input#authorId').value.trim(); const guildId = $('input#guildId').value.trim(); const channelIds = $('input#channelId').value.trim().split(/\s*,\s*/); - const afterMessageId = $('input#afterMessageId').value.trim(); - const beforeMessageId = $('input#beforeMessageId').value.trim(); const minId = $('input#minId').value.trim(); const maxId = $('input#maxId').value.trim(); + const minDate = $('input#minDate').value.trim(); + const maxDate = $('input#maxDate').value.trim(); const content = $('input#content').value.trim(); const hasLink = $('input#hasLink').checked; const hasFile = $('input#hasFile').checked; @@ -100,7 +100,7 @@ stop = stopBtn.disabled = !(startBtn.disabled = true); for (let i = 0; i < channelIds.length; i++) { - await deleteMessages(authToken, authorId, guildId, channelIds[i], afterMessageId, beforeMessageId, content, hasLink, hasFile, includeNsfw, includePinned, logger, stopHndl, onProg); + await deleteMessages(authToken, authorId, guildId, channelIds[i], minId || minDate, maxId || maxDate, content, hasLink, hasFile, includeNsfw, includePinned, logger, stopHndl, onProg); stop = stopBtn.disabled = !(startBtn.disabled = false); } }; @@ -136,8 +136,8 @@ * @param {string} authorId Author of the messages you want to delete * @param {string} guildId Server were the messages are located * @param {string} channelId Channel were the messages are located - * @param {string} afterMessageId Only delete messages after this, leave blank do delete all - * @param {string} beforeMessageId Only delete messages before this, leave blank do delete all + * @param {string} minId Only delete messages after this, leave blank do delete all + * @param {string} maxId Only delete messages before this, leave blank do delete all * @param {string} content Filter messages that contains this text content * @param {boolean} hasLink Filter messages that contains link * @param {boolean} hasFile Filter messages that contains file @@ -147,7 +147,7 @@ * @author Victornpb * @see https://github.com/victornpb/deleteDiscordMessages */ - async function deleteMessages(authToken, authorId, guildId, channelId, afterMessageId, beforeMessageId, content,hasLink, hasFile, includeNsfw, includePinned, extLogger, stopHndl, onProgress) { + async function deleteMessages(authToken, authorId, guildId, channelId, minId, maxId, content,hasLink, hasFile, includeNsfw, includePinned, extLogger, stopHndl, onProgress) { const start = new Date(); let deleteDelay = 100; let searchDelay = 100; @@ -168,7 +168,8 @@ const queryString = params => params.filter(p => p[1] !== undefined).map(p => p[0] + '=' + encodeURIComponent(p[1])).join('&'); const ask = async msg => new Promise(resolve => setTimeout(() => resolve(popup.confirm(msg)), 10)); const printDelayStats = () => log.verb(`Delete delay: ${deleteDelay}ms, Search delay: ${searchDelay}ms`, `Last Ping: ${lastPing}ms, Average Ping: ${avgPing|0}ms`); - + const toSnowflake = (date) => /:/.test(date) ? ((new Date(date).getTime() - 1420070400000) * Math.pow(2, 22)) : date; + const log = { debug() { extLogger ? extLogger('debug', arguments) : console.debug.apply(console, arguments); }, info() { extLogger ? extLogger('info', arguments) : console.info.apply(console, arguments); }, @@ -197,8 +198,8 @@ resp = await fetch(API_SEARCH_URL + 'search?' + queryString([ [ 'author_id', authorId || undefined ], [ 'channel_id', (guildId !== '@me' ? channelId : undefined) || undefined ], - [ 'min_id', afterMessageId || undefined ], - [ 'max_id', beforeMessageId || undefined ], + [ 'min_id', minId ? toSnowflake(minId) : undefined ], + [ 'max_id', maxId ? toSnowflake(maxId) : undefined ], [ 'sort_by', 'timestamp' ], [ 'sort_order', 'desc' ], [ 'offset', offset ], @@ -340,7 +341,7 @@ } log.success(`\nStarted at ${start.toLocaleString()}`); - log.debug(`authorId="${redact(authorId)}" guildId="${redact(guildId)}" channelId="${redact(channelId)}" afterMessageId="${redact(afterMessageId)}" beforeMessageId="${redact(beforeMessageId)}" hasLink=${!!hasLink} hasFile=${!!hasFile}`); + log.debug(`authorId="${redact(authorId)}" guildId="${redact(guildId)}" channelId="${redact(channelId)}" minId="${redact(minId)}" maxId="${redact(maxId)}" hasLink=${!!hasLink} hasFile=${!!hasFile}`); if (onProgress) onProgress(null, 1); return await recurse(); }