From 20b617f6eb015cda897f8ef5a6ab40a3ea936966 Mon Sep 17 00:00:00 2001
From: DJj123dj <80536295+DJj123dj@users.noreply.github.com>
Date: Thu, 14 Dec 2023 21:37:29 +0100
Subject: [PATCH] v3.5.0 push 5
---
.github/CONTRIBUTING.md | 11 +--
.github/SECURITY.md | 26 +++---
commands/help.js | 5 +-
commands/stats.js | 142 +++++++++++++++++++++-----------
core/api/api.json | 6 +-
core/api/modules/events.js | 2 +-
core/slashSystem/slashEnable.js | 38 ++++++++-
core/statsManager.js | 2 +-
index.js | 2 +
9 files changed, 162 insertions(+), 72 deletions(-)
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index 875eca7..6a0bf0f 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/CONTRIBUTING.md
@@ -9,14 +9,15 @@ If there is translation missing & you can write json, then go to the next step!
### Step 2: translating
**RULES:**
-- Always upload to the [__`dev` branch!__](https://github.com/DJj123dj/open-ticket/tree/dev)
+- Always upload or create a pull request to the [__`dev` branch!__](https://github.com/DJj123dj/open-ticket/tree/dev)
- Don't change anything else, except the translation you are adding!
- Translations are checked before uploading, so don't write things that aren't specified in the json file
- Always start translating from `english.json` or `custom.json`! Never from another language.
-If you translate, you need to change 2 files! The first one is required, the other one is optional & will be added by us if you don't do it!
+If you translate, you need to change 2 files! The first one is required, the other 2 are optional & will be added by us if you don't do it!
1. add `yourlanguage.json` to the `/language/` directory
-2. (OPTIONAL) add your discord name & tag in the translator table in `README.md`
+2. add your username to the `_CREDITS` part of `yourlanguage.json`!
+3. add your discord username in the translator table in `README.md`
### Step 3: waiting
Translations will always be added in the **next version** of Open Ticket! They will never be added to the `main` branch directly without anything else! This means that it can take some time before your translation is in the official version!
@@ -28,10 +29,10 @@ But don't worry! You can already write some plugins!
**RULES:**
- Always specify the versions that the plugin is compatible with!
- If extra npm dependencies are needed, then they also need to be specified!
-- If there are errors while you write a plugin/edit the code in some way. Then we can't help you with fixing the bug. We only fix bugs that are part of an unedited version of Open Ticket!
+- If there are errors while you write a plugin/edit the code in some way. Then we can't help you with fixing the bug. We only fix bugs that are part of the original unedited version of Open Ticket!
## Other versions of contributing
-If you want to contribute in another way, feel free to join [our discord server](https://discord.dj-dj.be) & talk about how you are going to do it. We will always help you!
+If you want to contribute in another way, feel free to join [our discord server](https://discord.dj-dj.be) & talk about how you are going to do it. We will always help you further!
CONTRIBUTING GUIDELINES - Last updated: 23/3/2023
diff --git a/.github/SECURITY.md b/.github/SECURITY.md
index 9b71661..8945e33 100644
--- a/.github/SECURITY.md
+++ b/.github/SECURITY.md
@@ -2,7 +2,7 @@
## Supported Versions
-Support for Open Ticket is only available for the versions specified below!
+We only support Open Ticket versions listed below! With support, we mean bugs, errors & helping you further!
✅ Supported
🟧 Partially Supported
@@ -12,29 +12,29 @@ Support for Open Ticket is only available for the versions specified below!
|-----------|-------------------|
| 3.5.0 | ✅ |
| 3.4.4 | ✅ |
-| 3.4.3 | ✅ |
+| 3.4.3 | 🟧 |
| 3.4.2 | 🟧 |
| < 3.4.2 | ❌ |
## Reporting a Vulnerability
-You can report Vulnerabilities, errors & bugs in the following ways:
+You can report Vulnerabilities, Errors & Bugs using one of the methods below:
+- Create an issue on github
+- Create a ticket in our [discord server](https://discord.dj-dj.be)
+- Report the bug in DM on discord (djj123dj)
+- Email [support@dj-dj.be](mailto:support@dj-dj.be)
-- Creating an issue on github
-- Creating a ticket in our discord server
-- Reporting the bug in DM on discord (DJj123dj#1706)
-- Emailing support@dj-dj.be
-
-If your report an error, be clear about what is going on.
-Specify the version & language of the bot together with when the error happend. (for example: when I click the close button)
-Send screenshots from the error if possible, and send openticketdebug.txt (or a screenshot of it) to us.
-Don't just report the error and never reply again! It can be possible that we need you for more information!
+While reporting your problem, please be clear about what the problem is.
+We would like to know the issue in as much detail as possible.
+If possible, try to provide screenshots!
+The `openticketdebug.txt` file would also be handy to upload!
+**Always specify the version of open ticket that you are working with and if you have modified it or not!**
## Contributing
Visit [Contributing.md](/.github/CONTRIBUTING.md) for rules about translating & adding features!
-SECURITY POLICY - Last updated: 9/11/2023
+SECURITY POLICY - Last updated: 14/12/2023
© DJdj Development
Website: https://www.dj-dj.be
Discord: https://discord.dj-dj.be
diff --git a/commands/help.js b/commands/help.js
index 9038382..45c7c86 100644
--- a/commands/help.js
+++ b/commands/help.js
@@ -21,7 +21,8 @@ module.exports = () => {
const header = l.helpMenu.header2
helpEmbed.setDescription(header+"`"+prefix+msgName+" ` ➜ _"+l.helpMenu.msgCmd+"_\n\n`"+prefix+"rename ` ➜ _"+l.helpMenu.renameCmd+"_\n`"+prefix+"close [reason]` ➜ _"+l.helpMenu.closeCmd+"_\n`"+prefix+"delete` ➜ _"+l.helpMenu.deleteCmd+"_\n`"+prefix+"reopen` ➜ _"+l.helpMenu.reopenCmd+"_\n\n`"+prefix+"add ` ➜ _"+l.helpMenu.addCmd+"_\n`"+prefix+"remove ` ➜ _"+l.helpMenu.removeCmd+"_\n\n`"+prefix+"change ` ➜ _"+l.helpMenu.changeCmd+"_\n`"+prefix+"claim [user]` ➜ _"+l.helpMenu.claimCmd+"_\n`"+prefix+"unclaim` ➜ _"+l.helpMenu.unclaimCmd+"_")
helpEmbed.addFields([
- {name:"Autoclose",value:l.helpMenu.autocloseCmd+"\n`"+prefix+"autoclose enable `\n`"+prefix+"autoclose disable`"}
+ {name:"Autoclose",value:l.helpMenu.autocloseCmd+"\n`"+prefix+"autoclose enable `\n`"+prefix+"autoclose disable`"},
+ {name:"Stats",value:"Get statistics from the bot"+"\n`"+prefix+"stats global`\n`"+prefix+"stats ticket`\n`"+prefix+"stats user [user]`"}
])
var otherprefix = prefix.endsWith(" ") ? prefix.substring(0,prefix.length-1) : prefix
@@ -38,7 +39,7 @@ module.exports = () => {
}
if (args[1]){
- if (!args[1].startsWith("close") && !args[1].startsWith("delete") && !args[1].startsWith("remove") && !args[1].startsWith("add") && !args[1].startsWith("msg") && !args[1].startsWith("remove") && !args[1].startsWith("rename") && !args[1].startsWith("reopen") && !args[1].startsWith("change") && !args[1].startsWith("claim") && !args[1].startsWith("unclaim")){
+ if (!args[1].startsWith("close") && !args[1].startsWith("delete") && !args[1].startsWith("remove") && !args[1].startsWith("add") && !args[1].startsWith("msg") && !args[1].startsWith("remove") && !args[1].startsWith("rename") && !args[1].startsWith("reopen") && !args[1].startsWith("change") && !args[1].startsWith("claim") && !args[1].startsWith("unclaim") && !args[1].startsWith("stats")){
msg.channel.send({embeds:[helpEmbed]})
log("command","someone used the 'help' command",[{key:"user",value:msg.author.username}])
APIEvents.onCommand("help",true,msg.author,msg.channel,msg.guild,new Date())
diff --git a/commands/stats.js b/commands/stats.js
index 70fa147..fabd533 100644
--- a/commands/stats.js
+++ b/commands/stats.js
@@ -1,53 +1,103 @@
-/**
-!!! NEW !!!
-The /stats command
+const discord = require('discord.js')
+const bot = require('../index')
+const client = bot.client
+const config = bot.config
+const log = bot.errorLog.log
+const l = bot.language
+const permsChecker = require("../core/utils/permisssionChecker")
-(well, it's not finished yet 😉)
-=================================================
-client.on("messageCreate",async (msg) => {
- if (!msg.content.startsWith("!test global")) return
- msg.channel.send({
- content:"testing `GLOBAL_STATS`",
- embeds:[await createGlobalStatsEmbed()]
+const APIEvents = require("../core/api/modules/events")
+const DISABLE = require("../core/api/api.json").disable
+
+module.exports = () => {
+ bot.errorLog.log("debug","COMMANDS: loaded stats.js")
+
+ if (!DISABLE.commands.text.stats) client.on("messageCreate",async (msg) => {
+ if (!msg.content.startsWith(config.prefix+"stats global") && !msg.content.startsWith(config.prefix+"stats ticket") && !msg.content.startsWith(config.prefix+"stats user")) return
+ if (!msg.guild) return
+
+ /**@type {"global"|"ticket"|"user"} */
+ const mode = msg.content.split(config.prefix+"stats ")[1]
+
+ if (mode == "global"){
+ //send global stats
+ msg.channel.send({embeds:[await bot.statsManager.createGlobalStatsEmbed()]})
+
+ }else if (mode == "user"){
+ //send user stats
+ const mention = msg.mentions.users.first()
+ if (mention){
+ //get user from mention
+ if (!bot.statsManager.existStats("user","TICKETS_CREATED",mention.id)){
+ msg.channel.send({embeds:[bot.errorLog.serverError("This user can't be found in the stats database!")]})
+ return
+ }
+ msg.channel.send({embeds:[await bot.statsManager.createUserStatsEmbed(msg.guild,mention,msg.channel.id)]})
+ }else{
+ //use author as user
+ if (!bot.statsManager.existStats("user","TICKETS_CREATED",msg.author.id)){
+ msg.channel.send({embeds:[bot.errorLog.serverError("This user can't be found in the stats database!")]})
+ return
+ }
+ msg.channel.send({embeds:[await bot.statsManager.createUserStatsEmbed(msg.guild,msg.author,msg.channel.id)]})
+ }
+
+ }else if (mode == "ticket"){
+ //send ticket stats
+ if (!bot.statsManager.existStats("ticket","STATUS",msg.channel.id)){
+ msg.channel.send({embeds:[bot.errorLog.notInATicket]})
+ return
+ }
+ msg.channel.send({embeds:[await bot.statsManager.createTicketStatsEmbed(msg.guild,msg.channel.id)]})
+ }
+
+ log("command","someone used the 'stats' command",[{key:"user",value:msg.author.username},{key:"mode",value:mode}])
+ APIEvents.onCommand("stats",true,msg.author,msg.channel,msg.guild,new Date())
})
-})
-client.on("messageCreate",async (msg) => {
- if (!msg.content.startsWith("!test ticket")) return
- if (!existStats("ticket","STATUS",msg.channel.id)){
- msg.channel.send({embeds:[bot.errorLog.notInATicket]})
- return
- }
+ if (!DISABLE.commands.slash.stats) client.on("interactionCreate",async (interaction) => {
+ if (!interaction.isChatInputCommand()) return
+ if (interaction.commandName != "stats") return
+ if (!interaction.guild) return
- msg.channel.send({
- content:"testing `TICKET_STATS`",
- embeds:[await createTicketStatsEmbed(msg.guild,msg.channel.id)]
- })
-})
-client.on("messageCreate",async (msg) => {
- if (!msg.content.startsWith("!test user")) return
- const mention = msg.mentions.users.first()
+ /**@type {"global"|"ticket"|"user"} */
+ const mode = interaction.options.getSubcommand(true)
- if (mention){
- if (!existStats("user","TICKETS_CREATED",mention.id)){
- msg.channel.send({embeds:[bot.errorLog.serverError("This user can't be found in the stats database!")]})
- return
+ await interaction.deferReply()
+
+ if (mode == "global"){
+ //send global stats
+ interaction.editReply({embeds:[await bot.statsManager.createGlobalStatsEmbed()]})
+
+ }else if (mode == "user"){
+ //send user stats
+ const mention = interaction.options.getUser("user",false)
+ if (mention){
+ //get user from mention
+ if (!bot.statsManager.existStats("user","TICKETS_CREATED",mention.id)){
+ interaction.editReply({embeds:[bot.errorLog.serverError("This user can't be found in the stats database!")]})
+ return
+ }
+ interaction.editReply({embeds:[await bot.statsManager.createUserStatsEmbed(interaction.guild,mention,interaction.channel.id)]})
+ }else{
+ //use author as user
+ if (!bot.statsManager.existStats("user","TICKETS_CREATED",interaction.user.id)){
+ interaction.editReply({embeds:[bot.errorLog.serverError("This user can't be found in the stats database!")]})
+ return
+ }
+ interaction.editReply({embeds:[await bot.statsManager.createUserStatsEmbed(interaction.guild,interaction.user,interaction.channel.id)]})
+ }
+
+ }else if (mode == "ticket"){
+ //send ticket stats
+ if (!bot.statsManager.existStats("ticket","STATUS",interaction.channel.id)){
+ interaction.editReply({embeds:[bot.errorLog.notInATicket]})
+ return
+ }
+ interaction.editReply({embeds:[await bot.statsManager.createTicketStatsEmbed(interaction.guild,interaction.channel.id)]})
}
- msg.channel.send({
- content:"testing `USER_STATS`",
- embeds:[await createUserStatsEmbed(msg.guild,mention,msg.channel.id)]
- })
- }else{
- if (!existStats("user","TICKETS_CREATED",msg.author.id)){
- msg.channel.send({embeds:[bot.errorLog.serverError("This user can't be found in the stats database!")]})
- return
- }
-
- msg.channel.send({
- content:"testing `USER_STATS`",
- embeds:[await createUserStatsEmbed(msg.guild,msg.author,msg.channel.id)]
- })
- }
-})
- */
\ No newline at end of file
+ log("command","someone used the 'stats' command",[{key:"user",value:interaction.user.username},{key:"mode",value:mode}])
+ APIEvents.onCommand("stats",true,interaction.user,interaction.channel,interaction.guild,new Date())
+ })
+}
\ No newline at end of file
diff --git a/core/api/api.json b/core/api/api.json
index d82b261..96cd79d 100644
--- a/core/api/api.json
+++ b/core/api/api.json
@@ -30,7 +30,8 @@
"rename":false,
"claim":false,
"unclaim":false,
- "change":false
+ "change":false,
+ "stats":false
},
"slash":{
"help":false,
@@ -44,7 +45,8 @@
"rename":false,
"claim":false,
"unclaim":false,
- "change":false
+ "change":false,
+ "stats":false
}
},
"checkerjs":{
diff --git a/core/api/modules/events.js b/core/api/modules/events.js
index f51f503..7342b0a 100644
--- a/core/api/modules/events.js
+++ b/core/api/modules/events.js
@@ -229,7 +229,7 @@ exports.onTranscriptCreation = (messages,channel,guild,date) => {
}
-/**@typedef {"help"|"message"|"close"|"delete"|"reopen"|"rename"|"add"|"remove"|"claim"|"unclaim"|"change"} OTCommandType */
+/**@typedef {"help"|"message"|"close"|"delete"|"reopen"|"rename"|"add"|"remove"|"claim"|"unclaim"|"change"|"stats"} OTCommandType */
/**
*
diff --git a/core/slashSystem/slashEnable.js b/core/slashSystem/slashEnable.js
index 20e6f7d..1b3e77a 100644
--- a/core/slashSystem/slashEnable.js
+++ b/core/slashSystem/slashEnable.js
@@ -34,8 +34,8 @@ module.exports = async (invisible) => {
if (!invisible){
setInterval(() => {
if (process.stdout && process.stdout.cursorTo) process.stdout.cursorTo(0)
- process.stdout.write("[status] there are "+chalk.blue(readystats+" out of 13")+" commands ready! (this can take up to 40 seconds)")
- if (readystats >= 13){
+ process.stdout.write("[status] there are "+chalk.blue(readystats+" out of 14")+" commands ready! (this can take up to 40 seconds)")
+ if (readystats >= 14){
console.log(chalk.green("\nready!"))
console.log(chalk.blue("you can now start the bot with "+chalk.bgBlue("'npm start'")+"!"))
process.exit(1)
@@ -268,4 +268,38 @@ module.exports = async (invisible) => {
readystats++
})
+ //stats
+ client.application.commands.create({
+ name:"stats",
+ description:"See bot statistics!",
+ defaultPermission:true,
+ type:act.ChatInput,
+ options:[
+ {
+ type:acot.Subcommand,
+ name:"global",
+ description:"See the global bot stats!"
+ },
+ {
+ type:acot.Subcommand,
+ name:"ticket",
+ description:"See the stats of a ticket (use inside of ticket)!"
+ },
+ {
+ type:acot.Subcommand,
+ name:"user",
+ description:"See the stats from a user or yourself!",
+ options:[
+ {
+ type:acot.User,
+ name:"user",
+ required:false,
+ description:"See the stats from a specific user!"
+ }
+ ]
+ }
+ ]
+ },sid).then(() => {
+ readystats++
+ })
}
\ No newline at end of file
diff --git a/core/statsManager.js b/core/statsManager.js
index 213c8e7..1009b76 100644
--- a/core/statsManager.js
+++ b/core/statsManager.js
@@ -220,7 +220,7 @@ const getTicketStats = async (guild,channelid) => {
createdAt: (typeof createdAt == "undefined") ? new Date().getTime() : createdAt,
createdBy: (typeof createdBy == "undefined") ? 0 : createdBy,
messageAmount,
- participants:participants,
+ participants:participants.slice(0,50),
ticketName:channel.name,
status: (typeof status == "undefined") ? "open" : status
}
diff --git a/index.js b/index.js
index fe6a2a8..2406367 100644
--- a/index.js
+++ b/index.js
@@ -293,6 +293,8 @@ if (process.argv[2] && process.argv[2].startsWith("slash")){
require("./commands/claim")()
require("./commands/unclaim")()
require("./commands/change")()
+ require("./commands/stats")()
+
this.actionRecorder.push({
category:"ot.managers.loader",
file:"./index.js",