Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Update V3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Bluzzi committed Jun 13, 2022
1 parent f8e4002 commit 3dcd947
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "3.1.5",
"version": "3.2.0",
"main": "./build/src/Index.js",
"scripts": {
"start": "node .",
Expand Down
5 changes: 5 additions & 0 deletions resources/config/tier.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"max": 1,
"min": 5,
"upDownPercent": 30
}
1 change: 1 addition & 0 deletions resources/graphql/types/Member.gql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type Member {
}

type DiscordActivity {
tier: Int!
voiceMinute: Int!
monthVoiceMinute: Int!
messages: DiscordMessageActivity!
Expand Down
3 changes: 3 additions & 0 deletions src/database/collections/Member.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import database from "../Database";
import tier from "../../../resources/config/tier.json";

export interface ChannelMessageCount {
channelId: string;
messageCount: number;
}

export interface DiscordActivity {
tier: number;
voiceMinute: number;
monthVoiceMinute: number;
messages: {
Expand Down Expand Up @@ -51,6 +53,7 @@ export async function createMember(
isOnServer: isOnServer,

activity: {
tier: tier.min,
voiceMinute: 0,
monthVoiceMinute: 0,
messages: {
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/ClientSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export type DiscordActivity = {
__typename?: 'DiscordActivity';
messages: DiscordMessageActivity;
monthVoiceMinute: Scalars['Int'];
tier: Scalars['Int'];
voiceMinute: Scalars['Int'];
};

Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/ServerSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type DiscordActivity = {
__typename?: 'DiscordActivity';
messages: DiscordMessageActivity;
monthVoiceMinute: Scalars['Int'];
tier: Scalars['Int'];
voiceMinute: Scalars['Int'];
};

Expand Down Expand Up @@ -306,6 +307,7 @@ export interface DateScalarConfig extends GraphQLScalarTypeConfig<ResolversTypes
export type DiscordActivityResolvers<ContextType = any, ParentType extends ResolversParentTypes['DiscordActivity'] = ResolversParentTypes['DiscordActivity']> = {
messages?: Resolver<ResolversTypes['DiscordMessageActivity'], ParentType, ContextType>;
monthVoiceMinute?: Resolver<ResolversTypes['Int'], ParentType, ContextType>;
tier?: Resolver<ResolversTypes['Int'], ParentType, ContextType>;
voiceMinute?: Resolver<ResolversTypes['Int'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};
Expand Down
30 changes: 30 additions & 0 deletions src/tasks/MonthUpdate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import memberCollection from "../database/collections/Member";
import tier from "../../resources/config/tier.json";

setInterval(async() => {
const date = new Date();

if (date.getDate() === 1 && date.getHours() === 0 && date.getMinutes() === 0) {
// Update member tiers :
const members = (await memberCollection.find({ isOnServer: true }).toArray()).sort((a, b) => {
const aActivity = a.activity.messages.monthCount + a.activity.monthVoiceMinute;
const bActivity = b.activity.messages.monthCount + b.activity.monthVoiceMinute;

return aActivity < bActivity ? 1 : -1;
});

const up = members.slice(0, Math.floor(members.length * tier.upDownPercent / 100));
const down = members.slice(members.length - Math.floor(members.length * tier.upDownPercent / 100), members.length);

for (const member of up) {
if (member.activity.tier !== tier.max) await memberCollection.updateOne({ _id: member._id }, { $inc: { "activity.tier": -1 } });
}

for (const member of down) {
if (member.activity.tier !== tier.min) await memberCollection.updateOne({ _id: member._id }, { $inc: { "activity.tier": 1 } });
}

// Reset member activity :
memberCollection.updateMany({}, { $set: { "activity.messages.monthCount": 0, "activity.monthVoiceMinute": 0 } });
}
}, 5000); // 60_000
9 changes: 0 additions & 9 deletions src/tasks/ResetMonthMessage.ts

This file was deleted.

0 comments on commit 3dcd947

Please sign in to comment.