Skip to content

Commit

Permalink
🐛 Bug fixes and improvements +updated connections
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Hanania committed Apr 2, 2023
1 parent c83c988 commit 82e071f
Show file tree
Hide file tree
Showing 5 changed files with 342 additions and 159 deletions.
281 changes: 267 additions & 14 deletions components/Data.tsx

Large diffs are not rendered by default.

149 changes: 30 additions & 119 deletions components/Upload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ export default function Upload(): ReactElement {
userInformationData.settings.settings.appearance;
}

// deprecated => Discord does not give accurate folder data.

// if (options.settings.folderCount) {
// if (
// userInformationData.settings.settings.guildFolders &&
Expand Down Expand Up @@ -2104,129 +2106,38 @@ export default function Upload(): ReactElement {
"Loading Messages|||Calculating your top hours on Discord"
);

const hourlyMessages = [];
for (let i = 0; i < 24; i++) {
hourlyMessages.push(
channels
.map((c) => c.messages)
.flat()
.filter((m) => {
if (!m.timestamp) return false;
const date: any = new Date(m.timestamp).getHours();
if (date && date !== "Invalid Date") {
return date === i;
} else {
const date_: any = moment(m.timestamp).format("HH");
if (date_) {
return date_ == i;
} else {
return false;
}
}
}).length
);
}

const dailyMessages = [];
for (let i = 0; i < 7; i++) {
dailyMessages.push(
channels
.map((c) => c.messages)
.flat()
.filter((m) => {
if (!m.timestamp) return false;
const date: any = new Date(m.timestamp).getDay();
if (date && date !== "Invalid Date") {
return parseInt(date) == i;
} else {
const date_: any = moment(m.timestamp).format("d");
if (date_) {
return date_ == i;
} else {
return false;
}
}
}).length
);
}

const dates2: any = [];
const monthlyMessages = [];
for (let i = 0; i < 12; i++) {
monthlyMessages.push(
channels
.map((c) => c.messages)
.flat()
.filter((m) => {
if (!m.timestamp) return false;
const date: any = new Date(m.timestamp).getMonth();
if (!dates2.includes(date)) dates2.push(date);

if (date && date !== "Invalid Date") {
return parseInt(date) == i;
} else {
const date_: any = parseInt(
moment(m.timestamp).format("M")
);
if (date_) {
return date_ == i + 1;
} else {
return false;
}
}
}).length
);
}

const yearlyMessages: any = [];
const years: any = [];
channels
.map((c) => c.messages)
.flat()
.forEach((m) => {
if (!m.timestamp) return false;
const date: any = new Date(m.timestamp).getFullYear();
if (date && date !== "Invalid Date") {
if (!years.includes(date)) {
years.push(date);
}
} else {
const date_: any = moment(m.timestamp).format("YYYY");
if (date_) {
if (!years.includes(date_)) {
years.push(date_);
}
}
}
/**
* @Info Removed moment support for IOS devices because its way too slow.
* @author @peterhanania
*/

const messagesByHour = Array.from({ length: 24 }, () => 0);
const messagesByDay = Array.from({ length: 7 }, () => 0);
const messagesByMonth = Array.from({ length: 12 }, () => 0);
const messagesByYear: any = {};

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

const date = new Date(message.timestamp);
messagesByHour[date.getHours()]++;
messagesByDay[date.getDay()]++;
messagesByMonth[date.getMonth()]++;

const year = date.getFullYear();
if (!messagesByYear[year]) messagesByYear[year] = 0;
messagesByYear[year]++;
});

years.forEach((year: any) => {
yearlyMessages.unshift(
channels
.map((c) => c.messages)
.flat()
.filter((m) => {
if (!m.timestamp) return false;
const date: any = new Date(m.timestamp).getFullYear();
if (date && date !== "Invalid Date") {
return date === year;
} else {
const date_: any = moment(m.timestamp).format("YYYY");
if (date_) {
return date_ == year;
} else {
return false;
}
}
}).length
);
});

data.messages.hoursValues = {
hourly: hourlyMessages,
daily: dailyMessages,
monthly: monthlyMessages,
yearly: yearlyMessages,
hourly: messagesByHour,
daily: messagesByDay,
monthly: messagesByMonth,
yearly: Object.values(messagesByYear),
};

if (isDebug) {
Expand Down
18 changes: 10 additions & 8 deletions components/error/errorBoundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import React from "react";
class ErrorBoundary extends React.Component<any> {
state: {
hasError: boolean;
error: string;
};
constructor(props: { children: any }) {
super(props);

this.state = { hasError: false };
this.state = { hasError: false, error: "" };
}
static getDerivedStateFromError(error: any) {
console.log(error);

return { hasError: true };
return { hasError: true, error: error.message };
}
componentDidCatch(error: any, errorInfo: any) {
console.log({ error, errorInfo });
Expand Down Expand Up @@ -51,16 +52,17 @@ class ErrorBoundary extends React.Component<any> {
</h1>
<p className="pb-8 text-2xl dark:text-white text-gray-800 max-w-lg">
An error has just occured, please report this issue to the
discord server! Click the button below to join the Discord,
go to this browser&apos;s console, take a screenshot and
send it to channel
<code className="ml-1">
discord server! However, before doing so, try pressing on
the &apos;retry&apos; button, if it does not work, click the
button below to join the Discord, take a screenshot of the
error below and send it to channel
<code className="mx-1">
<u>#bug-reports</u>
</code>
.
and we will try to fix it as soon as possible.
</p>
<div className="pb-8 text-2xl font-bold text-red-500 max-w-lg">
Look at the console for more details
{this.state.error}
</div>
<a
onClick={() => {
Expand Down
26 changes: 25 additions & 1 deletion components/json/Connections.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,29 @@
"github": { "link": "https://github.com/", "name": "GitHub" },
"facebook": { "link": null, "name": "Facebook" },
"epicgames": { "link": null, "name": "Epic Games" },
"battlenet": { "link": null, "name": "Battle.net" }
"battlenet": { "link": null, "name": "Battle.net" },
"ebay": {
"link": "https://www.ebay.com/str/",
"name": "eBay"
},
"instagram": {
"link": "https://www.instagram.com/",
"name": "Instagram"
},
"leagueoflegends": {
"link": null,
"name": "League of Legends"
},
"paypal": {
"link": null,
"name": "PayPal"
},
"riotgames": {
"link": null,
"name": "Riot Games"
},
"tiktok": {
"link": "https://www.tiktok.com/@",
"name": "TikTok"
}
}
27 changes: 10 additions & 17 deletions components/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import randomWords from "random-words";
import curseWords from "../json/demo/curse.json";
import Events from "../json/events.json";
import currencies from "../json/other/currencies.json";
import connectionsJSON from "../json/connections.json";

class Utils {
static getMostUsedCurrency(transactions) {
if(transactions == null) { return; }
if (transactions == null) {
return;
}

const currenciesUsed = {};
transactions.forEach((a) => {
Expand Down Expand Up @@ -140,6 +143,9 @@ class Utils {
item = words[index];
if (!item) continue;

// ignore words with less or equal than 3 characters
if (item.length <= 3) continue;

if (!object[item]) object[item] = 1;
else ++object[item];
}
Expand Down Expand Up @@ -438,22 +444,8 @@ class Utils {
}))
.sort((a, b) => b.count - a.count);

const connectionsPossible = [
"youtube",
"xbox",
"twitter",
"twitch",
"steam",
"spotify",
"reddit",
"playstation",
"github",
"facebook",
"epicgames",
"battlenet",
];

const connectionsRand = Math.floor(Math.random() * 5) + 1;
const connectionsPossible = Object.keys(connectionsJSON);
const connectionsRand = Math.floor(Math.random() * connectionsPossible.length) + 1;
const connectionsArray = [];
for (let i = 0; i < connectionsRand; i++) {
const connectionsArray_ =
Expand All @@ -464,6 +456,7 @@ class Utils {
if (!connectionsArray.includes(connectionsArray_))
connectionsArray.push(connectionsArray_);
}

const connections = connectionsArray.map((connection) => ({
type: connection,
name: username + Math.floor(Math.random() * 10) + 1,
Expand Down

0 comments on commit 82e071f

Please sign in to comment.