v3.5.0 push 3

This commit is contained in:
DJj123dj
2023-12-13 12:27:01 +01:00
parent 3447a37603
commit d51511fdb5
9 changed files with 105 additions and 24 deletions
+68 -4
View File
@@ -5,11 +5,11 @@ const log = bot.errorLog.log
const l = bot.language
/**@typedef {"TICKETS_CREATED"|"TICKETS_CLOSED"|"TICKETS_DELETED"|"TICKETS_REOPENED"|"TICKETS_AUTOCLOSED"|"TRANSCRIPTS_CREATED"|"TIME_SINCE_UPDATE"} OTGlobalStatsType */
/**@typedef {"TICKET_AGE"} OTTicketStatsType */
/**@typedef {"TICKETS_CREATED"} OTUserStatsType */
/**@typedef {"TICKET_AGE"|"CREATED_BY"} OTTicketStatsType */
/**@typedef {"TICKETS_CREATED"|"TICKETS_CLOSED"|"TICKETS_DELETED"|"TICKETS_REOPENED"} OTUserStatsType */
/**
* @callback OTStatsCallback
* @param {Boolean|Number|String} current
* @param {Boolean|Number|String|undefined} current
* @returns {Boolean|Number|String|undefined}
*/
@@ -63,9 +63,73 @@ const removeStats = (scope,type,id) => {
bot.statsStorage.delete(newScope,type)
}
/**
*
* @param {"global"|"ticket"|"user"} scope
* @param {OTGlobalStatsType|OTTicketStatsType|OTUserStatsType} type
* @param {String} [id]
*/
const existStats = (scope,type,id) => {
const newScope = (scope == "global") ? scope : scope+"_"+id
return (typeof bot.statsStorage.get(newScope,type) == "undefined") ? false : true
}
/**
*
* @param {"global"|"ticket"|"user"} scope
* @param {OTGlobalStatsType|OTTicketStatsType|OTUserStatsType} type
* @param {String} [id]
*/
const getStats = (scope,type,id) => {
const newScope = (scope == "global") ? scope : scope+"_"+id
return bot.statsStorage.get(newScope,type)
}
const startupStatsManager = () => {
if (!existStats("global","TIME_SINCE_UPDATE")){
updateGlobalStats("TIME_SINCE_UPDATE",(current) => {
return new Date().getTime()
})
}
if (!existStats("global","TICKETS_CREATED")){
updateGlobalStats("TICKETS_CREATED",(current) => {
return 0
})
}
if (!existStats("global","TICKETS_CLOSED")){
updateGlobalStats("TICKETS_CLOSED",(current) => {
return 0
})
}
if (!existStats("global","TICKETS_DELETED")){
updateGlobalStats("TICKETS_DELETED",(current) => {
return 0
})
}
if (!existStats("global","TICKETS_AUTOCLOSED")){
updateGlobalStats("TICKETS_AUTOCLOSED",(current) => {
return 0
})
}
if (!existStats("global","TICKETS_REOPENED")){
updateGlobalStats("TICKETS_REOPENED",(current) => {
return 0
})
}if (!existStats("global","TRANSCRIPTS_CREATED")){
updateGlobalStats("TRANSCRIPTS_CREATED",(current) => {
return 0
})
}
}
module.exports = {
updateGlobalStats,
updateTicketStats,
updateUserStats,
removeStats
removeStats,
existStats,
getStats,
startupStatsManager
}