Skip to content

Commit

Permalink
Add multi-queue + remove CI
Browse files Browse the repository at this point in the history
  • Loading branch information
KwikKill committed Aug 11, 2024
1 parent 836e9cd commit dbff9bf
Show file tree
Hide file tree
Showing 9 changed files with 346 additions and 227 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/deploy.yml

This file was deleted.

101 changes: 64 additions & 37 deletions commands/adminlol.js
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,17 @@ module.exports = {
} else if (interaction.options.getSubcommand() === "add") {
await interaction.editReply("loading summoners...");
const resp = await client.pg.query("SELECT player, SPLIT_PART(puuid, '_', 1) AS region FROM matchs WHERE player IN (SELECT player FROM matchs GROUP BY player ORDER BY count(*) ASC, RANDOM() LIMIT 30)");

for (const summoner of resp.rows) {
client.lol.queue["updates"].push({
"type": "sum",
"puuid": summoner.player,
"region": summoner.region,
"matchs": []
});
const route = client.lol.reverse_routes[summoner.region];
if (route !== undefined && client.lol.services[route] !== undefined) {
client.lol.services[route]["queue"]["updates"].push({
"type": "sum",
"puuid": summoner.player,
"region": summoner.region,
"matchs": []
});
}
}
interaction.editReply("Adding " + resp.rows.length + " summoners to the queue, please wait");
await client.lol.main();
Expand Down Expand Up @@ -584,6 +588,17 @@ module.exports = {
if (username !== undefined && region !== "null" && username !== "null" && username !== null && region !== undefined && region !== null && username.includes("#") && currents.length < limit) {
const resp = await client.pg.query("SELECT puuid FROM summoners WHERE gamename = $1 AND tagline = $2 AND region = $3", [username.split("#")[0], username.split("#")[1], region]);
if (resp.rows.length === 0) {
// If not already in the two arrays
for (const current of currents) {
if (current[0] === username && current[1] === region) {
continue;
}
}
for (const summoner of summoners) {
if (summoner[0] === username && summoner[1] === region) {
continue;
}
}
summoners.push([username, region]);
currents.push([username, region]);
}
Expand All @@ -594,19 +609,24 @@ module.exports = {
}

for (const summoner of summoners) {
client.lol.queue["updates"].push({
"type": "population",
"region": summoner[1],
"gamename": summoner[0].split("#")[0],
"tagline": summoner[0].split("#")[1],
"add": account,
"discordid": "503109625772507136"
});
const route = client.lol.reverse_routes[summoner[1]];
if (route !== undefined && client.lol.services[route] !== undefined) {
client.lol.services[route]["queue"]["updates"].push({
"type": "population",
"region": summoner[1],
"gamename": summoner[0].split("#")[0],
"tagline": summoner[0].split("#")[1],
"add": account,
"discordid": "503109625772507136"
});
}
}

const end = Date.now();
const time = (end - start) / 1000;
await interaction.editReply(summoners.length + " summoners added to the queue in " + time + "s");

await client.lol.main(true);
}
} else if (interaction.options.getSubcommandGroup() === "analyze") {
const TOP = interaction.options.getString("top");
Expand Down Expand Up @@ -704,14 +724,17 @@ module.exports = {

const debug = interaction.options.getBoolean("debug");

client.lol.queue["updates"].push({
"type": "match",
"matchid": matchid,
"region": region,
"puuid": "noone",
"first": true,
"debug": debug
});
const route = client.lol.reverse_routes[region];
if (route !== undefined && client.lol.services[route] !== undefined) {
client.lol.services[route]["queue"]["updates"].push({
"type": "match",
"matchid": matchid,
"region": region,
"puuid": "noone",
"first": true,
"debug": debug
});
}

await interaction.editReply({ content: "Match added!", ephemeral: true });
client.lol.main();
Expand Down Expand Up @@ -773,26 +796,30 @@ async function update(client, debug = false, first = false) {
const query = "SELECT DISTINCT puuid, id, gamename, tagline, discordid, region, priority FROM summoners ORDER BY priority DESC;";
const result = await client.pg.query(query);

const prio = [];
const prio = {};

for (let i = 0; i < result.rows.length; i++) {
let found = false;
for (let j = 0; j < client.lol.queue["updates"].length; j++) {
if (client.lol.queue["updates"][j].puuid === result.rows[i].puuid) {
found = true;
break;
}
const route = client.lol.reverse_routes[result.rows[i].region];
if (client.lol.services[route]["running"] === true) {
continue;
}

if (!prio[route]) {
prio[route] = [];
}
if (!found) {
if (result.rows[i].priority > 0) {
prio.push({ "puuid": result.rows[i].puuid, "discordid": result.rows[i].discordid, "id": result.rows[i].id, "gamename": result.rows[i].gamename, "tagline": result.rows[i].tagline, "matchs": [], "total": 0, "count": 0, "region": result.rows[i].region, "first": first, "rank": false });
} else {
client.lol.queue["updates"].push({ "puuid": result.rows[i].puuid, "discordid": result.rows[i].discordid, "id": result.rows[i].id, "gamename": result.rows[i].gamename, "tagline": result.rows[i].tagline, "matchs": [], "total": 0, "count": 0, "region": result.rows[i].region, "first": first, "rank": false });

if (route !== undefined && client.lol.services[route] !== undefined) {
let found = false;
for (let j = 0; j < client.lol.services[route]["queue"]["updates"].length; j++) {
if (client.lol.services[route]["queue"]["updates"][j].puuid === result.rows[i].puuid) {
found = true;
break;
}
}
if (!found) {
client.lol.services[route]["queue"]["updates"].push({ "puuid": result.rows[i].puuid, "discordid": result.rows[i].discordid, "id": result.rows[i].id, "gamename": result.rows[i].gamename, "tagline": result.rows[i].tagline, "matchs": [], "total": 0, "count": 0, "region": result.rows[i].region, "first": first, "rank": false });
}
}
}
for (let i = prio.length - 1; i >= 0; i--) {
client.lol.queue["updates"].splice(1, 0, prio[i]);
}
await client.lol.main(debug);
}
58 changes: 42 additions & 16 deletions commands/lol.js
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,9 @@ module.exports = {
* @returns {Promise<void>}
*/
async function addSumoner(client, gamename, tagline, interaction, region) {
client.lol.queue["summoners"].push({ "gamename": gamename, "tagline": tagline, "discordid": interaction.user.id, "interaction": interaction, "region": region, "priority": 0, "first": true });
const route = client.lol.reverse_routes[region];

client.lol.services[route]["queue"]["summoners"].push({ "gamename": gamename, "tagline": tagline, "discordid": interaction.user.id, "interaction": interaction, "region": region, "priority": 0, "first": true });
await client.lol.main();
}

Expand All @@ -1010,7 +1012,9 @@ async function addSumoner(client, gamename, tagline, interaction, region) {
* @returns {Promise<void>}
*/
async function add_summoner_manual(client, gamename, tagline, discordid, region, priority = 0) {
client.lol.queue["summoners"].push({ "gamename": gamename, "tagline": tagline, "discordid": discordid, "interaction": undefined, "region": region, "priority": priority, "first": true });
const route = client.lol.reverse_routes[region];

client.lol.services[route]["queue"]["summoners"].push({ "gamename": gamename, "tagline": tagline, "discordid": discordid, "interaction": undefined, "region": region, "priority": priority, "first": true });
await client.lol.main();
}

Expand Down Expand Up @@ -1041,12 +1045,14 @@ async function account_add(client, interaction, gamename, tagline, region) {
interaction.guild ? interaction.guild.id : interaction.user.id
]
});
const route = client.lol.reverse_routes[region];

const response = await client.pg.query("SELECT * FROM summoners where discordid=$1 AND gamename=$2 AND tagline=$3 AND region=$4;", [interaction.user.id, gamename, tagline, region]);
if (!client.lol.queue["summoners"].includes({ "gamename": gamename, "tagline": tagline, "discordid": interaction.user.id, "region": region }) && response.rows.length === 0) {
if (!client.lol.services[route]["queue"]["summoners"].includes({ "gamename": gamename, "tagline": tagline, "discordid": interaction.user.id, "region": region }) && response.rows.length === 0) {
const response2 = await client.pg.query("SELECT * FROM summoners where discordid=$1;", [interaction.user.id]);
let number = response2.rows.length;
for (let i = 0; i < client.lol.queue["summoners"].length; i++) {
if (client.lol.queue["summoners"][i].discordid === interaction.user.id) {
for (let i = 0; i < client.lol.services[route]["queue"]["summoners"].length; i++) {
if (client.lol.services[route]["queue"]["summoners"][i].discordid === interaction.user.id) {
number++;
}
}
Expand Down Expand Up @@ -1179,31 +1185,51 @@ async function queue(client, interaction) {
})
.setTimestamp();
let step = "";
if (client.lol.queue["updates"].length > 0) {
if (client.lol.queue["updates"][0]["count"] === 0) {

const queue = {
"summoners": [],
"updates": [],
"add": []
};

for(const route in client.lol.services) {
for (let i = 0; i < client.lol.services[route]["queue"]["summoners"].length; i++) {
queue["summoners"].push(client.lol.services[route]["queue"]["summoners"][i]);
}
for (let i = 0; i < client.lol.services[route]["queue"]["updates"].length; i++) {
queue["updates"].push(client.lol.services[route]["queue"]["updates"][i]);
}
for (let i = 0; i < client.lol.services[route]["queue"]["add"].length; i++) {
queue["add"].push(client.lol.services[route]["queue"]["add"][i]);
}
}


if (queue["updates"].length > 0) {
if (queue["updates"][0]["count"] === 0) {
step = //"- Step : 1/2 (Fetching game list)" +
"- Current : <@" + client.lol.queue["updates"][0]["discordid"] + "> (" + client.lol.queue["updates"][0]["gamename"] + "#" + client.lol.queue["updates"][0]["tagline"] + ") : Fetching match list";
"- Current : <@" + queue["updates"][0]["discordid"] + "> (" + queue["updates"][0]["gamename"] + "#" + queue["updates"][0]["tagline"] + ") : Fetching match list";
} else {
step = //"- Step : 2/2 (Fetching matchs details)\n" +
"- Current : <@" + client.lol.queue["updates"][0]["discordid"] + "> (" + client.lol.queue["updates"][0]["gamename"] + "#" + client.lol.queue["updates"][0]["tagline"] + ") : " + client.lol.queue["updates"][0]["count"] + "/" + client.lol.queue["updates"][0]["total"] + " matchs";
"- Current : <@" + queue["updates"][0]["discordid"] + "> (" + queue["updates"][0]["gamename"] + "#" + queue["updates"][0]["tagline"] + ") : " + queue["updates"][0]["count"] + "/" + queue["updates"][0]["total"] + " matchs";
}
embed.addFields(
{
name: "Queued updates :",
value: "- size : " + client.lol.queue["updates"].length + " Summoners\n" +
value: "- size : " + queue["updates"].length + " Summoners\n" +
step + "\n"
}
);
const pos = [];
for (let i = 1; i < client.lol.queue["updates"].length; i++) {
if (client.lol.queue["updates"][i]["discordid"] === interaction.user.id) {
pos.push([i, client.lol.queue["updates"][i]["gamename"] + "#" + client.lol.queue["updates"][i]["tagline"]]);
for (let i = 1; i < queue["updates"].length; i++) {
if (queue["updates"][i]["discordid"] === interaction.user.id) {
pos.push([i, queue["updates"][i]["gamename"] + "#" + queue["updates"][i]["tagline"]]);
break;
}
}
let text = "";
for (let i = 0; i < pos.length; i++) {
text += "- " + pos[i][1] + " : " + pos[i][0] + "/" + client.lol.queue["updates"].length + "\n";
text += "- " + pos[i][1] + " : " + pos[i][0] + "/" + queue["updates"].length + "\n";
}
if (text !== "") {
embed.addFields(
Expand All @@ -1221,14 +1247,14 @@ async function queue(client, interaction) {
}
);
}
if (interaction.user.id === "297409548703105035") {
/*if (interaction.user.id === "297409548703105035") {
embed.addFields(
{
name: "Api limit reached :",
value: "" + client.lol.api_limit
}
);
}
}*/
return await interaction.editReply({ embeds: [embed] });
}

Expand Down
8 changes: 6 additions & 2 deletions listeners/commandInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ module.exports = {
options: undefined,
async run(client, interaction) {
if (client.softbans.includes(interaction.user.id)) {
logger.info(`softban ${interaction.user.id} on command ${interaction.commandName}`);
return;
// softban mean 4/5 commands are blocked
const random = Math.floor(Math.random() * 5);
if (random !== 0) {
logger.info(`softban ${interaction.user.id} on command ${interaction.commandName}`);
return;
}
}
if (interaction.isCommand()) {

Expand Down
Loading

0 comments on commit dbff9bf

Please sign in to comment.