added bad ui
This commit is contained in:
parent
e7b79056e9
commit
f9e7a2fc92
1 changed files with 77 additions and 13 deletions
68
index.tsx
68
index.tsx
|
@ -1,8 +1,11 @@
|
||||||
|
|
||||||
|
|
||||||
import { DataStore } from "@api/index";
|
import { DataStore } from "@api/index";
|
||||||
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import { Devs } from "@utils/constants";
|
import { Devs } from "@utils/constants";
|
||||||
import definePlugin from "@utils/types";
|
import definePlugin, { OptionType } from "@utils/types";
|
||||||
import { cache } from "@webpack";
|
import { cache } from "@webpack";
|
||||||
import { Constants, MessageStore, RestAPI, UserStore } from "@webpack/common";
|
import { Constants, Forms, MessageStore, Parser, RestAPI, useEffect, UserStore, useState } from "@webpack/common";
|
||||||
import { Message } from "discord-types/general";
|
import { Message } from "discord-types/general";
|
||||||
|
|
||||||
const DATA_STORE_KEY = "huskchart";
|
const DATA_STORE_KEY = "huskchart";
|
||||||
|
@ -11,6 +14,10 @@ type Husk = {
|
||||||
channelId: string;
|
channelId: string;
|
||||||
messageId: string;
|
messageId: string;
|
||||||
};
|
};
|
||||||
|
type SortedHusk = {
|
||||||
|
id: string;
|
||||||
|
count: number;
|
||||||
|
};
|
||||||
const messageCache = new Map<string, {
|
const messageCache = new Map<string, {
|
||||||
message?: Message;
|
message?: Message;
|
||||||
fetched: boolean;
|
fetched: boolean;
|
||||||
|
@ -45,12 +52,53 @@ async function getMessage(channelId: string, messageId: string): Promise<Message
|
||||||
return apiMessage.body[0];
|
return apiMessage.body[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const UserData = () => {
|
||||||
|
// powered by generative ai, idk react :trolley:
|
||||||
|
const [data, setData] = useState([]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const fetchData = async () => {
|
||||||
|
const rawHusks: Husk[] = await DataStore.get(DATA_STORE_KEY) || [];
|
||||||
|
const unsortedHuskCountPerUser: SortedHusk[] = [];
|
||||||
|
for (const husk of rawHusks) {
|
||||||
|
let shouldAddInitialHusk = true;
|
||||||
|
for (const [i, hc] of unsortedHuskCountPerUser.entries()) {
|
||||||
|
const unsortedHusker: SortedHusk = hc;
|
||||||
|
if (unsortedHusker.id == husk.userId) {
|
||||||
|
unsortedHuskCountPerUser[i].count++;
|
||||||
|
shouldAddInitialHusk = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!shouldAddInitialHusk) continue;
|
||||||
|
unsortedHuskCountPerUser.push({ id: husk.userId, count: 1 });
|
||||||
|
}
|
||||||
|
const sortedHuskers = unsortedHuskCountPerUser.sort((a, b) => b.count - a.count);
|
||||||
|
// @ts-ignore EXPLODEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
|
||||||
|
setData(sortedHuskers);
|
||||||
|
};
|
||||||
|
fetchData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{
|
||||||
|
data && data.map(user => <>
|
||||||
|
<div>
|
||||||
|
{/* @ts-ignore */}
|
||||||
|
{Parser.parse(`<@${user.id}>`)} <Forms.FormText>with {user.count} husks</Forms.FormText>
|
||||||
|
</div>
|
||||||
|
</>)
|
||||||
|
}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
export default definePlugin({
|
export default definePlugin({
|
||||||
name: "HuskChart",
|
name: "HuskChart",
|
||||||
description: "See how much you've been husked, and by who",
|
description: "See how much you've been husked, and by who",
|
||||||
authors: [Devs.nin0dev],
|
authors: [Devs.nin0dev],
|
||||||
flux: {
|
flux: {
|
||||||
async MESSAGE_REACTION_ADD(event) {
|
async MESSAGE_REACTION_ADD(event) {
|
||||||
|
try {
|
||||||
const msg = await getMessage(event.channelId, event.messageId);
|
const msg = await getMessage(event.channelId, event.messageId);
|
||||||
if (msg!.author.id !== UserStore.getCurrentUser().id) return;
|
if (msg!.author.id !== UserStore.getCurrentUser().id) return;
|
||||||
if (!event.emoji.name.includes("husk")) return;
|
if (!event.emoji.name.includes("husk")) return;
|
||||||
|
@ -62,5 +110,21 @@ export default definePlugin({
|
||||||
});
|
});
|
||||||
DataStore.set(DATA_STORE_KEY, husks);
|
DataStore.set(DATA_STORE_KEY, husks);
|
||||||
}
|
}
|
||||||
|
catch {
|
||||||
|
// explode
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
settings: definePluginSettings({
|
||||||
|
buttons: {
|
||||||
|
type: OptionType.COMPONENT,
|
||||||
|
description: "User stats",
|
||||||
|
component: (aaa) => (
|
||||||
|
<>
|
||||||
|
<Forms.FormText style={{ fontSize: "1.07rem", fontWeight: "500" }}>User stats</Forms.FormText>
|
||||||
|
<UserData />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue