Skip to content

Commit

Permalink
Fix: Discord package update
Browse files Browse the repository at this point in the history
Discord updated their .CSV to .JSON, this update will allow JSON data.
  • Loading branch information
peterhanania committed Mar 13, 2024
1 parent 115e22c commit 518607e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 14 deletions.
42 changes: 35 additions & 7 deletions components/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,33 @@ export default function Upload(): ReactElement {
` ${chalk.yellow(`Started message scan`)}`
);

// Discord Updated their message system in March of 2024
// They Replaced .CSV files with normal .JSON files

let extension = "csv";

const firstChannelID = channelsIDs[0];
const firstChannelMessagesPath = `messages/${
isOldPackage ? "" : "c"
}${firstChannelID}/messages.json`;

const firstChannelMessages = await Utils.readFile(
firstChannelMessagesPath,
files
);

if (firstChannelMessages) {
extension = "json";
}

if (isDebug) {
console.log(
chalk.bold.blue(`[DEBUG] `) +
chalk.bold.cyan(`[${moment(Date.now()).format("h:mm:ss a")}]`) +
` ${chalk.yellow(`Picked file extension: ${extension}`)}`
);
}

await Promise.all(
channelsIDs.map((channelID: any): any => {
return new Promise((resolve) => {
Expand All @@ -808,7 +835,7 @@ export default function Upload(): ReactElement {
}${channelID}/channel.json`;
const channelMessagesPath = `messages/${
isOldPackage ? "" : "c"
}${channelID}/messages.csv`;
}${channelID}/messages.${extension}`;

Promise.all([
Utils.readFile(channelDataPath, files),
Expand All @@ -819,8 +846,11 @@ export default function Upload(): ReactElement {
} else messagesRead++;

const data_ = JSON.parse(rawData);
const messages = Utils.parseCSV(rawMessages);
const name = userMessages[data_.id];
const messages =
extension === "csv"
? Utils.parseCSV(rawMessages)
: Utils.parseJSON(rawMessages);
const name = userMessages[data_.id].replace("#0", "");
const isDM =
data_.recipients && data_.recipients.length === 2;
const dmUserID = isDM
Expand Down Expand Up @@ -2117,9 +2147,7 @@ export default function Upload(): ReactElement {
const messagesByYear: any = {};

channels.forEach((channel) => {
channel.messages.forEach((message: {
timestamp: number;
}) => {
channel.messages.forEach((message: { timestamp: number }) => {
if (!message.timestamp) return;

const date = new Date(message.timestamp);
Expand Down Expand Up @@ -3515,4 +3543,4 @@ The close button breaks stuff
</div>
</div>
</Tippy>
*/
*/
6 changes: 6 additions & 0 deletions components/json/alerts/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@
"id": "alert_3",
"url": "/discord",
"button": "Join the Discord"
},
{
"title": "Welcome to Discord Package, report bugs to @peterhanania.",
"id": "alert_4",
"url": "/discord",
"button": "Join the Discord"
}
]
23 changes: 16 additions & 7 deletions components/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Utils {

// {amount}{symbol}
if (currency.right) return `${amount}${currency.symbol}`;

// {symbol}{amount}
else return `${currency.symbol}${amount}`;
}
Expand Down Expand Up @@ -75,6 +74,17 @@ class Utils {
}));
}

static parseJSON(input) {
return JSON.parse(input)
.filter((m) => m.Contents)
.map((m) => ({
id: m.ID,
timestamp: m.Timestamp,
length: m.Contents.length,
words: m.Contents.split(" "),
}));
}

static perDay(value, userID) {
return parseInt(
value /
Expand Down Expand Up @@ -293,7 +303,9 @@ class Utils {
static generateRandomData() {
const id = Math.random().toString(36).substring(7);
const username = names[Math.floor(Math.random() * names.length)];
const discriminator = Math.floor(Math.random() * (9999 - 1000 + 1)) + 1000;

// Deprecated
// const discriminator = Math.floor(Math.random() * (9999 - 1000 + 1)) + 1000;

const isNitroUser = Math.random() > 0.5 ? true : false;
let avs;
Expand Down Expand Up @@ -626,10 +638,7 @@ class Utils {
i++
) {
topDMs.push({
user_tag:
names[Math.floor(Math.random() * names.length)] +
"#" +
Math.floor(Math.random() * (9999 - 1000 + 1)),
user_tag: names[Math.floor(Math.random() * names.length)],
// eslint-disable-next-line no-loss-of-precision
user_id: (
Math.floor(
Expand Down Expand Up @@ -970,7 +979,7 @@ class Utils {
user: {
id,
username,
discriminator,
discriminator: "",
avatar,
premium_until: isNitroUser
? Date.now() +
Expand Down

0 comments on commit 518607e

Please sign in to comment.