diff --git a/src/index.ts b/src/index.ts index d7a2ade..ef451ca 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,48 +1,22 @@ -import axios from "axios"; +import "json-bigint-patch"; +import moment from "moment"; import fs from "node:fs/promises"; +import { deleteMessage } from "service/axios"; +import { getUserIdFromToken } from "utils/discordId"; +import { wait } from "utils/wait"; import { ChannelData } from "./interfaces/channelData"; import { MessageData } from "./interfaces/messageData"; -import moment from "moment"; -import "json-bigint-patch"; const secondsDelay = 2, token = process.argv[2], debugMode = process.argv[3] == "debug"; -const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); - let totalMessages = 0, totalDeleted = 0; const CHANNELS_DATA: ChannelData[] = [], MESSAGES_DATA: { [key: string]: MessageData[] } = {}; -function getUserIdFromToken(token: string): string { - const tokenParts = token.split("."); - const payload = tokenParts[0]; - return Buffer.from(payload, "base64").toString("utf-8"); -} - -const axiosInstance = axios.create({ - baseURL: "https://discord.com/api/v9", - headers: { - authorization: token, - accept: "*/*", - "accept-language": "fr,fr-FR;q=0.9", - "content-type": "application/json", - "sec-ch-ua": '"Not;A Brand";v="99", "Chromium";v="90"', - "sec-ch-ua-mobile": "?0", - "sec-fetch-dest": "empty", - "sec-fetch-mode": "cors", - "sec-fetch-site": "same-origin", - "x-debug-options": "bugReporterEnabled", - }, -}); - -const deleteMessage = async (channelId: string, messageId: bigint) => { - return await axiosInstance.delete(`/channels/${channelId}/messages/${messageId.toString()}`); -}; - async function main() { const myId = getUserIdFromToken(token); console.log(`My ID: ${myId}`); diff --git a/src/service/axios.ts b/src/service/axios.ts new file mode 100644 index 0000000..2ef0c4f --- /dev/null +++ b/src/service/axios.ts @@ -0,0 +1,21 @@ +import axios from "axios"; + +export const AxiosInstance = axios.create({ + baseURL: "https://discord.com/api/v9", + headers: { + authorization: process.argv[2], + accept: "*/*", + "accept-language": "fr,fr-FR;q=0.9", + "content-type": "application/json", + "sec-ch-ua": '"Not;A Brand";v="99", "Chromium";v="90"', + "sec-ch-ua-mobile": "?0", + "sec-fetch-dest": "empty", + "sec-fetch-mode": "cors", + "sec-fetch-site": "same-origin", + "x-debug-options": "bugReporterEnabled", + }, +}); + +export const deleteMessage = async (channelId: string, messageId: bigint) => { + return await AxiosInstance.delete(`/channels/${channelId}/messages/${messageId.toString()}`); +}; diff --git a/src/utils/discordId.ts b/src/utils/discordId.ts new file mode 100644 index 0000000..586a1c6 --- /dev/null +++ b/src/utils/discordId.ts @@ -0,0 +1,5 @@ +export const getUserIdFromToken = (token: string): string => { + const tokenParts = token.split("."); + const payload = tokenParts[0]; + return Buffer.from(payload, "base64").toString("utf-8"); +}; diff --git a/src/utils/wait.ts b/src/utils/wait.ts new file mode 100644 index 0000000..3b7662b --- /dev/null +++ b/src/utils/wait.ts @@ -0,0 +1 @@ +export const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));