Skip to content

Commit 518f42a

Browse files
committed
[4.9.2] Návrat eventu
- Návrat a úpravy /event příkazu - Aktualizace IDs a obrázků - Aktualizace dependencies
1 parent 4e9b182 commit 518f42a

File tree

8 files changed

+247
-28
lines changed

8 files changed

+247
-28
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
*Český Discord bot pro Law Enforcement Agencies na GTA V FiveM roleplay serveru [RefreshRP by Nolimit](https://nlmt.cc/).*
1515

16-
*Aktuálně podporuje sbory LSPD <img src="https://i.imgur.com/gfL0fGf.png" width="15" height="15"/> a LSCSO <img src="https://i.imgur.com/X3cH2iu.png" width="15" height="15"/>.*
16+
*Aktuálně podporuje sbory LSPD <img src="https://i.imgur.com/gfL0fGf.png" width="15" height="15"/> a LSCSO <img src="https://i.imgur.com/Hex0MQF.png" width="15" height="15"/>.*
1717

1818
Funkce:
1919
- zápis služeb zaměstnanců

db/event/0.txt

Whitespace-only changes.

db/event/000000000000000001.json

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "Will Smith",
3+
"stats": {
4+
"value": 15000,
5+
"invoices": 1
6+
},
7+
"invoices": [
8+
{
9+
"value": 15000,
10+
"shared": "31. 12. 2023",
11+
"reason": "Nelegální akce",
12+
"name": "John Wick",
13+
"id": 1
14+
}
15+
]
16+
}

index.js

+3-8
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,7 @@ bot.LEA = {
4646
LSPD: "https://i.imgur.com/gfL0fGf.png",
4747
SAHP: "https://i.imgur.com/xgFoKuX.png",
4848
LSSD: "https://i.imgur.com/X3cH2iu.png",
49-
LSCSO: "https://i.imgur.com/Hex0MQF.png",
50-
event: [
51-
"https://i.imgur.com/pkEErJp.png",
52-
"https://i.imgur.com/Dj4dvsr.png",
53-
"https://imgur.com/NARTJhy.png"
54-
]
49+
LSCSO: "https://i.imgur.com/Hex0MQF.png"
5550
},
5651
e: {
5752
LSPD: "<:LSPD:1178108366514565181>",
@@ -61,10 +56,10 @@ bot.LEA = {
6156
},
6257
g: {
6358
LSPD: [
64-
"1154446248934387828", "1203275468544151583"
59+
"1154446248934387828"
6560
],
6661
LSCSO: [
67-
"1139266097921675345", "1174843772446703718", "714147774299373629"
62+
"1139266097921675345"
6863
]
6964
}
7065
};

package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lea-bot",
3-
"version": "4.9.1",
3+
"version": "4.9.2",
44
"description": "RefreshRP (FiveM GTA V roleplay) Discord bot for LEA - making internal police department actions easier.",
55
"type": "module",
66
"main": "index.js",
@@ -29,9 +29,9 @@
2929
"node": ">=16.11.0"
3030
},
3131
"dependencies": {
32-
"discord.js": "^14.15.3",
32+
"discord.js": "^14.16.2",
3333
"dotenv": "^16.4.5",
34-
"express": "^4.19.2",
34+
"express": "^4.21.0",
3535
"node-fetch": "^3.3.2",
3636
"ws": "^8.18.0"
3737
}

src/commands/event.js

+152
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
import { SlashCommandBuilder } from "discord.js";
2+
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, InteractionType, ModalBuilder, TextInputBuilder, TextInputStyle } from "discord.js";
3+
import fs from "fs";
4+
import path from "path";
5+
import { checkEVENT, getServer } from "../../src/functions/db.js";
6+
7+
export const slash = new SlashCommandBuilder()
8+
.setName("event")
9+
.setDescription(`Správa a informace o eventu`)
10+
.addSubcommand(subcommand =>
11+
subcommand
12+
.setName('faktura')
13+
.setDescription("Zápis faktury do eventu")
14+
)
15+
.addSubcommand(subcommand =>
16+
subcommand
17+
.setName('souhrn')
18+
.setDescription("Souhrn účastníka eventu")
19+
.addUserOption(option =>
20+
option.setName("účastník")
21+
.setDescription("Vyber účastníka")
22+
.setRequired(true))
23+
)
24+
.addSubcommand(subcommand =>
25+
subcommand
26+
.setName('žebříček')
27+
.setDescription("Žěbříček účastníků eventu")
28+
)
29+
.setDMPermission(false)
30+
.setNSFW(false);
31+
32+
export default async function run(bot, i) {
33+
const sub = i.options._subcommand;
34+
const user = i.options.getUser("účastník");
35+
36+
let passed = false;
37+
i.guild.fetch();
38+
const admin = i.member;
39+
if (admin.id === "411436203330502658") passed = true; //PetyXbron / b1ngo
40+
if (bot.LEA.g.LSCSO.includes(i.guild.id) && !passed) {
41+
if (admin.roles.cache.has("1139267137651884072")) passed = true; //Leadership
42+
}
43+
44+
if (!bot.LEA.g.LSCSO.includes(i.guild.id)) return i.reply({
45+
content: "> 🛑 **Příkazy /event nejsou aktuálně dostupné pro " + i.guild.name + ".**",
46+
ephemeral: true
47+
});
48+
49+
if (sub === "faktura") { //Faktura
50+
const modal = new ModalBuilder()
51+
.setCustomId("fakturaModal")
52+
.setTitle("EVENT | Zápis faktury");
53+
54+
const nameInput = new TextInputBuilder()
55+
.setCustomId("name")
56+
.setLabel("Jméno občana")
57+
.setStyle(TextInputStyle.Short)
58+
.setPlaceholder("Will Smith")
59+
.setRequired(true);
60+
61+
const birthInput = new TextInputBuilder()
62+
.setCustomId("reason")
63+
.setLabel("Popis faktury")
64+
.setStyle(TextInputStyle.Paragraph)
65+
.setPlaceholder("Nelegální akce")
66+
.setRequired(true);
67+
68+
const moneyInput = new TextInputBuilder()
69+
.setCustomId("money")
70+
.setLabel("Čáska faktury")
71+
.setStyle(TextInputStyle.Short)
72+
.setPlaceholder("15 000")
73+
.setMinLength(4)
74+
.setRequired(true);
75+
76+
const actionRow0 = new ActionRowBuilder().addComponents(nameInput);
77+
const actionRow1 = new ActionRowBuilder().addComponents(birthInput);
78+
const actionRow2 = new ActionRowBuilder().addComponents(moneyInput);
79+
80+
modal.addComponents(actionRow0, actionRow1, actionRow2);
81+
82+
await i.showModal(modal);
83+
} else if (sub === "souhrn") { //Souhrn
84+
if (user.id !== i.user.id && !passed) return i.reply({ content: "> 🛑 **Můžeš zobrazit pouze svoje faktury.**", ephemeral: true });
85+
if (!(checkEVENT(user.id, i))) return i.reply({ content: "> 🛑 **<@" + user.id + "> ještě nesoutěží.**", ephemeral: true });
86+
87+
const eventer = JSON.parse(fs.readFileSync((path.resolve("./db/event") + "/" + user.id + ".json"), "utf-8"));
88+
const member = await i.guild.members.fetch(user.id);
89+
90+
let invoices = [], values = [];
91+
for (const inv of eventer.invoices) {
92+
invoices.push(`> **ID** \`${inv.id}\` (${inv.shared})\n> \`${inv.value} $\``);
93+
values.push(inv.value);
94+
}
95+
96+
const summaryEmbed = new EmbedBuilder()
97+
.setAuthor({ name: member.displayName, iconURL: member.displayAvatarURL() })
98+
.setTitle("EVENT | Souhrn " + eventer.name)
99+
.addFields([
100+
{
101+
name: "Faktury", inline: false,
102+
value: invoices.join("\n\n")
103+
},
104+
{
105+
name: "Statistika", inline: false,
106+
value:
107+
`> **Dohromady faktur:** \`${eventer.invoices.length}\`\n`
108+
+ `> **Dohromady zadáno:** \`${eventer.stats.value} $\`\n`
109+
+ `> **Průměrně zadáno:** \`${values.reduce((a, c) => a + c, 0) / values.length} $\``
110+
}
111+
])
112+
.setThumbnail("https://i.imgur.com/bGCFY6I.png")
113+
.setColor(bot.LEA.c.event)
114+
.setFooter(getServer(i).footer);
115+
116+
console.log(" < [EVE/Souhrn] > " + i.member.displayName + " zobrazil(a) souhrn " + member.displayName);
117+
118+
return i.reply({ embeds: [summaryEmbed], ephemeral: true });
119+
} else if (sub === "žebříček") { //Žěbříček
120+
//if (!passed) return i.reply({ content: "> 🛑 **Žebříček je už skrytý! To je napětí...**", ephemeral: true });
121+
122+
let users = [];
123+
const eventDB = fs.readdirSync(path.resolve("./db/event")).filter(file => file.endsWith(".json") && file !== "000000000000000001.json");
124+
for (const file of eventDB) {
125+
const eventer = JSON.parse(fs.readFileSync((path.resolve("./db/event") + "/" + file), "utf-8"));
126+
const user = {
127+
id: file.split(".")[0],
128+
name: eventer.name,
129+
invoices: eventer.invoices.length,
130+
value: eventer.stats.value
131+
};
132+
users.push(user);
133+
}
134+
users = users.sort((a, b) => b.value - a.value);
135+
users = users.slice(0, 5);
136+
137+
users.forEach((user, i) => {
138+
users[i] = `> ### ${i + 1}. <@${user.id}>\n> **Faktur:** \`${user.invoices.toLocaleString()}\`\n> **Hodnota:** \`${user.value.toLocaleString()} $\``;
139+
});
140+
141+
const topEmbed = new EmbedBuilder()
142+
.setTitle("EVENT | Žebříček (Top 5)")
143+
.setDescription(users.length ? users.join("\n\n") : "Nikdo ještě fakturu nezapsal!")
144+
.setThumbnail("https://i.imgur.com/bGCFY6I.png")
145+
.setColor(bot.LEA.c.event)
146+
.setFooter(getServer(i).footer);
147+
148+
console.log(" < [EVE/Žěbříček] > " + i.member.displayName + " zobrazil(a) žebříček");
149+
150+
return i.reply({ embeds: [topEmbed], ephemeral: true });
151+
}
152+
};

src/events/interactionCreate.js

+71-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, EmbedBuilder, InteractionType, ModalBuilder, TextInputBuilder, TextInputStyle, time } from "discord.js";
22
import fs from "fs";
33
import path from "path";
4-
import { getDB, checkDB, getServer } from "../../src/functions/db.js";
4+
import { checkDB, checkEVENT, getDB, getServer } from "../../src/functions/db.js";
55
import { dcLog, simpleLog } from "../../src/functions/logSystem.js";
66
import { findWorker } from "../../src/functions/profiles.js";
77
import { live } from "../../src/functions/liveTables.js";
88
import { generateFooter } from "../../src/functions/other.js";
9+
import { dg } from "../../src/functions/logSystem.js";
910

1011
export default async function (bot, i) {
1112
if (
@@ -1324,6 +1325,75 @@ export default async function (bot, i) {
13241325
console.log(" < [DB/OW/Apology] > " + i.member.displayName + ` přepsal(a) omluvenku [${content.radio}] ${content.name} (${index})`);
13251326

13261327
i.editReply({ content: "✅ **Přepsáno!**", ephemeral: true });
1328+
} else if (i.customId === "fakturaModal") {
1329+
if (!checkDB(i.user.id))
1330+
return i.reply({ content: "> 🛑 **Před zapsáním __faktury__ tě musí admin přilásit do DB.**\nZalož si vlastní složku v <#1139311793555116172> a počkej na správce DB.", ephemeral: true });
1331+
1332+
if (!checkEVENT(i.user.id)) {
1333+
const worker = getDB(i.user.id).data;
1334+
1335+
const content = {
1336+
name: worker.name,
1337+
stats: {
1338+
value: 0,
1339+
invoices: 0
1340+
},
1341+
invoices: []
1342+
};
1343+
1344+
fs.writeFileSync(
1345+
(path.resolve("./db/event") + "/" + i.user.id + ".json"),
1346+
JSON.stringify(content, null, 4)
1347+
);
1348+
}
1349+
1350+
const user = JSON.parse(fs.readFileSync((path.resolve("./db/event") + "/" + i.user.id + ".json"), "utf-8"));
1351+
1352+
const idFile = fs.readdirSync(path.resolve("./db/event")).filter(f => f.endsWith(".txt"))[0];
1353+
const id = parseInt(idFile.split(".")[0]) + 1;
1354+
1355+
const invoiceEmbed = new EmbedBuilder()
1356+
.setAuthor({ name: i.member.displayName, iconURL: i.member.displayAvatarURL() })
1357+
.setTitle("EVENT | Zápis faktury")
1358+
.setDescription("Faktura byla zapsána do soutěže!")
1359+
.addFields([
1360+
{
1361+
name: `Faktura #` + id.toString(), inline: false,
1362+
value:
1363+
`> **Jméno:** \`${i.fields.getTextInputValue("name")}\`\n`
1364+
+ `> **Důvod:** \`\`\`${i.fields.getTextInputValue("reason")}\`\`\`\n`
1365+
+ `> **Částka:** \`${parseInt(i.fields.getTextInputValue("money").split(" ").join("")).toLocaleString()} $\``
1366+
}
1367+
])
1368+
.setThumbnail("https://i.imgur.com/bGCFY6I.png")
1369+
.setColor(bot.LEA.c.event)
1370+
.setFooter(getServer(i).footer);
1371+
1372+
const today = new Date();
1373+
1374+
const day = dg(today, "Date") + ". " + dg(today, "Month") + ". " + dg(today, "FullYear");
1375+
const time = dg(today, "Hours") + ":" + dg(today, "Minutes") + ":" + dg(today, "Seconds");
1376+
1377+
user.invoices.push({
1378+
"value": parseInt(i.fields.getTextInputValue("money").split(" ").join("")),
1379+
"shared": day + " " + time,
1380+
"reason": i.fields.getTextInputValue("reason"),
1381+
"name": i.fields.getTextInputValue("name"),
1382+
"id": id
1383+
});
1384+
user.stats.value = user.stats.value + parseInt(i.fields.getTextInputValue("money").split(" ").join(""));
1385+
user.stats.invoices = user.invoices.length;
1386+
1387+
fs.writeFileSync(
1388+
(path.resolve("./db/event") + "/" + i.user.id + ".json"),
1389+
JSON.stringify(user, null, 4)
1390+
);
1391+
1392+
fs.renameSync(path.resolve("./db/event") + "/" + idFile, path.resolve("./db/event") + "/" + id.toString() + ".txt");
1393+
1394+
console.log(" < [EVE/Faktura] > " + i.member.displayName + " si zapsal fakturu s ID " + id);
1395+
1396+
return i.reply({ embeds: [invoiceEmbed], ephemeral: true });
13271397
}
13281398
}
13291399
}

src/functions/other.js

+1-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
11
export function generateFooter() {
2-
return `LEA Bot v${process.env.version} | Vytvořil b1ngo 🎈`
3-
/*const footers = [
4-
"3 roky fungovali zbory bez toho...",
5-
"dá sa nahradiť za 27 sekúnd...",
6-
"uľahčenie roboty o 3 minúty...",
7-
"je strašne smutné, že nebudú mať nejakú prijebanú stránku...",
8-
"jediné, čo je použiteľné, sú tabuľky...",
9-
"proste pičoviny...",
10-
"to robíš, lebo sa nudíš...",
11-
"to nie je, že by ti to pomohlo...",
12-
"to je proste detail...",
13-
"nie si nič, čo by sa nedalo nahradiť...",
14-
"tam jebnem hocikoho a bude to isté..."
15-
];
16-
return footers[Math.floor(Math.random() * footers.length)];*/
2+
return `LEA Bot v${process.env.version} | Vytvořil b1ngo 🎈`;
173
}

0 commit comments

Comments
 (0)