Repository navigation
Expand file tree
/
Copy pathshuffle.js
More file actions
143 lines (124 loc) · 4.27 KB
/
Copy pathshuffle.js
File metadata and controls
143 lines (124 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import { SlashCommandBuilder } from "@discordjs/builders";
import { fetchGuild, fetchRole, interactionReply } from "ewilib";
import { COMMONS } from "../classes/commons.js";
import { PERSONALITY } from "../classes/personality.js";
export const shuffleParam = {
status: PERSONALITY.getPersonality().shuffle.startstop.stop,
interval: null,
waitingTime: 10 * 60 * 1000,
};
const colorList = [
"#e74c3c",
"#f1c40f",
"#3498db",
"#2ecc71",
"#9b59b6",
"#1abc9c",
]; //Orange, yellow, blue, green, purple, cyan
const shuffleRoleColor = async (client) => {
const server =
process.env.DEBUG === "yes" ? COMMONS.getTest() : COMMONS.getProd(); //get commons data
const roles = Object.values(server.roles); // list of roles
const guild = await fetchGuild(client, server.guildId);
let colorToApply = colorList;
roles.forEach(async (roleData) => {
const role = await fetchRole(guild.roles, roleData.roleId);
const rd = Math.round((colorToApply.length - 1) * Math.random());
role.setColors({ primaryColor: colorToApply[rd] });
colorToApply = [
...colorToApply.slice(0, rd),
...colorToApply.slice(rd + 1),
];
});
};
const startInterval = (client) => {
shuffleParam.interval = setInterval(
async (client) => {
await shuffleRoleColor(client);
},
shuffleParam.waitingTime,
client,
);
};
const action = async (interaction) => {
const options = interaction.options;
const client = interaction.client;
const subcommand = options.getSubcommand();
const perso = PERSONALITY.getPersonality().shuffle;
const server =
process.env.DEBUG === "yes" ? COMMONS.getTest() : COMMONS.getProd(); //get commons data
if (subcommand === perso.startstop.name) {
//startstop
const ststPerso = perso.startstop;
let newStatus;
if (shuffleParam.status === ststPerso.stop) {
//start shuffle
newStatus = ststPerso.start;
shuffleParam.status = newStatus;
startInterval(client);
interactionReply(interaction, ststPerso.started);
} else if (shuffleParam.status === ststPerso.start) {
//stop shuffle
newStatus = ststPerso.stop;
//clear interval
clearInterval(shuffleParam.interval);
shuffleParam.interval = null;
//reset colors
const roles = Object.values(server.roles); // list of roles
const guild = await fetchGuild(client, server.guildId);
roles.forEach(async (roleData) => {
const role = await fetchRole(guild.roles, roleData.roleId);
role.setColors({ primaryColor: roleData.color });
});
setTimeout(() => {
shuffleParam.status = newStatus; //reset param status after API update
}, 10000);
interactionReply(interaction, ststPerso.stoped);
}
} else if (subcommand === perso.set.name) {
const setPerso = perso.set;
const newWaitingTime = options.getNumber(setPerso.numberOption.name);
shuffleParam.waitingTime = newWaitingTime;
interactionReply(interaction, setPerso.changed);
if (shuffleParam.interval) {
clearInterval(shuffleParam.interval);
startInterval(client);
}
}
};
const command = new SlashCommandBuilder()
.setName(PERSONALITY.getPersonality().shuffle.name)
.setDescription(PERSONALITY.getPersonality().shuffle.description)
.setDefaultMemberPermissions(0x0000010000000000)
.addSubcommand((subcommand) =>
subcommand
.setName(PERSONALITY.getPersonality().shuffle.startstop.name)
.setDescription(
PERSONALITY.getPersonality().shuffle.startstop.description,
),
)
.addSubcommand((subcommand) =>
subcommand
.setName(PERSONALITY.getPersonality().shuffle.set.name)
.setDescription(PERSONALITY.getPersonality().shuffle.set.description)
.addNumberOption((option) =>
option
.setName(PERSONALITY.getPersonality().shuffle.set.numberOption.name)
.setDescription(
PERSONALITY.getPersonality().shuffle.set.numberOption.description,
)
.setRequired(true),
),
);
const shuffle = {
command: command,
action,
help: (interaction) => {
const content = PERSONALITY.getPersonality().shuffle.help;
interactionReply(interaction, content);
},
admin: true,
releaseDate: null, //dayjs("01-01-2023", "MM-DD-YYYY"),
sentinelle: false,
};
export default shuffle;