Skip to content

Commit

Permalink
Updated node versions for workflows and other additions
Browse files Browse the repository at this point in the history
  • Loading branch information
fowled committed Apr 19, 2024
1 parent 3aae1ba commit 69313d1
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 151 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [16.6.x]
node-version: [20.x.x]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/server.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
node-version: [16.6.x]
node-version: [20.x.x]

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"cors": "^2.8.5",
"cross-env": "^7.0.3",
"dayjs": "^1.11.7",
"discord.js": "^14.8.0",
"discord.js": "^14.14.1",
"dotenv": "^16.0.3",
"eslint": "^8.36.0",
"express": "^4.18.2",
Expand Down
75 changes: 38 additions & 37 deletions app/src/events/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,70 +10,71 @@ module.exports = {
once: true,

async execute(Client: Discord.Client) {
let currentStatus = 0;

switchStatuses();

setInterval(switchStatuses, 10 * 60000);
Client.user.setActivity("/help • bot.fowled.dev", { type: Discord.ActivityType.Custom });

log(`${chalk.yellow("logged in")} as ${chalk.magentaBright(Client.user.username)}`);

await bootupChecks();

function switchStatuses() {
const statuses = [
{ name: "/help", type: Discord.ActivityType.Watching },
{
name: `${Client.guilds.cache.size.toString()} guilds`,
type: Discord.ActivityType.Competing,
},
];

Client.user.setActivity(statuses[currentStatus].name, {
type: statuses[currentStatus].type as Discord.ActivityType.Competing | Discord.ActivityType.Watching,
});

currentStatus === 0 ? currentStatus++ : currentStatus--;
}

async function bootupChecks() {
const fetchCurrentGuilds = await supabase.from("guilds").select("guild_id");
const fetchUsers = await supabase.from("users").select();

const addedGuilds = Client.guilds.cache.map(guild => guild.id).filter(x => !fetchCurrentGuilds.data.map(guild => guild.guild_id).includes(x));
const removedGuilds = fetchCurrentGuilds.data.map(guild => guild.guild_id).filter(x => !Client.guilds.cache.map(guild => guild.id).includes(x));
const addedGuilds = Client.guilds.cache
.map((guild) => guild.id)
.filter((x) => !fetchCurrentGuilds.data.map((guild) => guild.guild_id).includes(x));

const removedGuilds = fetchCurrentGuilds.data
.map((guild) => guild.guild_id)
.filter((x) => !Client.guilds.cache.map((guild) => guild.id).includes(x));

if (!addedGuilds.length && !removedGuilds.length) return;

for (const guild of addedGuilds) { // not using Parallel.all() here to avoid rate limits (needs to fetch a large amount of users)
for (const guild of addedGuilds) {
// not using Parallel.all() here to avoid rate limits (needs to fetch a large amount of users)
const fetchGuild = Client.guilds.cache.get(guild);

for (const user of fetchUsers.data) {
const fetchMutualGuilds = await supabase.from("users").select("guilds").like("user_id", user.user_id).single();
const fetchMutualGuilds = await supabase
.from("users")
.select("guilds")
.like("user_id", user.user_id)
.single();

try {
await fetchGuild.members.fetch({ user: user.user_id });

await supabase.from("users").update({ guilds: [...fetchMutualGuilds.data.guilds, guild] }).like("user_id", user.user_id);
} catch { };
await supabase
.from("users")
.update({ guilds: [...fetchMutualGuilds.data.guilds, guild] })
.like("user_id", user.user_id);
} catch {}
}

await supabase.from("guilds").insert({ guild_id: guild });
}

await Promise.all(removedGuilds.map(async (guild) => {
const findPeopleInGuild = await supabase.from("users").select().contains("guilds", [guild]);
await Promise.all(
removedGuilds.map(async (guild) => {
const findPeopleInGuild = await supabase.from("users").select().contains("guilds", [guild]);

await Promise.all(findPeopleInGuild.data.map(async (user) => {
const removeGuild = user.guilds.filter(item => item !== guild);
await Promise.all(
findPeopleInGuild.data.map(async (user) => {
const removeGuild = user.guilds.filter((item) => item !== guild);

await supabase.from("users").update({ guilds: removeGuild }).like("user_id", user.user_id);
}));
await supabase.from("users").update({ guilds: removeGuild }).like("user_id", user.user_id);
}),
);

await supabase.from("guilds").delete().like("guild_id", guild);
}));
await supabase.from("guilds").delete().like("guild_id", guild);
}),
);

return log(`${chalk.greenBright("joined")} ${chalk.yellow(addedGuilds.length)} ${chalk.blueBright("guild(s)")} and ${chalk.red("left")} ${chalk.yellow(removedGuilds.length)} ${chalk.blueBright("guild(s)")}`);
return log(
`${chalk.greenBright("joined")} ${chalk.yellow(addedGuilds.length)} ${chalk.blueBright(
"guild(s)",
)} and ${chalk.red("left")} ${chalk.yellow(removedGuilds.length)} ${chalk.blueBright("guild(s)")}`,
);
}
},
};
};
4 changes: 4 additions & 0 deletions app/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ function httpServer() {

app.use(cors({ origin: process.env.CLIENT_URL }));

app.get("/", async (_req, res) => {
return res.send("Hello world");
});

app.get("/stats", async (_req, res) => {
return res.send({ guilds: client.guilds.cache.size, users: await getUsersCount(client) });
});
Expand Down
Loading

0 comments on commit 69313d1

Please sign in to comment.