Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Remove all discord messages
(async () => {
const ONE_OUR = 3.6e6;
const ONE_DAY = ONE_OUR * 24;
const ONE_WEEK = ONE_DAY * 7;
const ONE_MONTH = ONE_DAY * 30;
const MY_ACC = '450630799713370122';
const AUTH_HEADERS = {
authorization:
'NDUwNjMwNzk5NzEzMzcwMTIy.D1nm-A.-Y4FVlVUPvpa5iOhFPcV8wHezn4',
'x-fingerprint': '550955708544319502._NRVO3hY6wEg0MGkbkaV_blfirs',
'x-super-properties':
'eyJvcyI6Ikxpbn4IiwiYnJvd3NlciI6IkNocm9tZSIsImRldmljZSI6IiIsImJyb3dzZXJfdXNlcl9hZ2VudCI6Ik1vemlsbGEvNS4wIChYMTE7IExpbnV4IHg4Nl82NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lLzcyLjAuMzYyNi4xMjEgU2FmYXJpLzUzNy4zNiIsImJyb3dzZXJfdmVyc2lvbiI6IjcyLjAuMzYyNi4xMjEiLCJvc192ZXJzaW9uIjoiIiwicmVmZXJyZXIiOiIiLCJyZWZlcnJpbmdfZG9tYWluIjoiIiwicmVmZXJyZXJfY3VycmVudCI6IiIsInJlZmVycmluZ19kb21haW5fY3VycmVudCI6IiIsInJlbGVhc2VfY2hhbm5lbCI6InN0YWJsZSIsImNsaWVudF9idWlsZF9udW1iZXIiOjMzMjI2LCJjbGllbnRfZXZlbnRfc291cmNlIjpudWxsfQ==',
};
const CHANNELS = [
[`450974014484250626`, { diff: ONE_WEEK * 2, name: 'esentai-general' }],
`451020131724689410`,
`450974100299448320`,
`595215731084492800`,// denis
`602806550855155732`,//olga disgner
`450952526544502785`,// frontend
`452001224020066305`, // anton
`452103278373896212`,//nikita
`544864430106607639`,
`479542166939631616`,
`458558350251261962`,
`456010831197372437`,
`459649540002414592`,
`494814740594556939`,
`480000062756225035`,
`502082865220026368`,
`481741406009032725`,
`453878260124614667`,
`468689808072638464`,
`509270329613615116`,
`499491433041100801`,
`457144116149747721`,
//`533209904425467915`, Fan
`538299010012938240`,
//`452072464722165771`, Tim
`458934968610062336`,
`501345599338184704`,
[`479515975192936450`, { diff: ONE_WEEK * 2, name: 'olga' }],
[`471497008218243095`, { diff: ONE_MONTH, name: 'ESIK APP daily' }],
[`471496287582158854`, { diff: ONE_MONTH, name: 'ESIK APP general' }],
[`471497369540624384`, { diff: ONE_MONTH, name: 'ESIK APP design' }],
[`471497394257920062`, { diff: ONE_MONTH, name: 'ESIK APP tech' }],
`568782468652597288`, // senegeto general
`573874850406465556`, // syner geto fe
];
const checkDate = (timeStr, diff) => {
const d = Date.now() - new Date(timeStr).getTime();
return d > diff;
};
const delay = ms =>
new Promise(ok => {
setTimeout(ok, ms, true);
});
async function removeMessagess({ ch, ids }) {
for (const id of ids) {
await delay(500);
await fetch(
`https://discordapp.com/api/v6/channels/${ch}/messages/${id}`,
{
headers: AUTH_HEADERS,
method: 'DELETE',
},
).then(() => {}, () => console.warn(`Opss... ${id}`));
}
}
async function fetchMessages({ ch, needTimeFilter }) {
let before = null;
const ids = [];
while (true) {
const res = await fetch(
`https://discordapp.com/api/v6/channels/${ch}/messages?${
before ? `before=${before}&` : ''
}limit=100`,
{
headers: AUTH_HEADERS,
method: 'GET',
},
);
const json = await res.json();
if (!Array.isArray(json) || json.length === 0) {
break;
}
before = json[json.length - 1].id;
ids.push(
...json
.filter(({ author }) => author.id === MY_ACC)
.filter(({ timestamp }) => {
if (needTimeFilter) {
return checkDate(timestamp, needTimeFilter);
}
return true;
})
.map(({ id }) => id),
);
}
return ids;
}
async function processChannel({ ch, needTimeFilter }) {
const ids = await fetchMessages({ ch, needTimeFilter });
await removeMessagess({ ch, ids });
}
for (let channel of CHANNELS) {
let needTimeFilter = false;
if (Array.isArray(channel)) {
needTimeFilter = channel[1].diff;
channel = channel[0];
}
await processChannel({
ch: channel,
needTimeFilter,
});
console.log(channel, 'Done...');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment