v3.5.0 push 2
This commit is contained in:
@@ -16,6 +16,12 @@ function setData(data){
|
|||||||
fs.writeFileSync(location,JSON.stringify(data,null,"\t"))
|
fs.writeFileSync(location,JSON.stringify(data,null,"\t"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {String} category
|
||||||
|
* @param {String} key
|
||||||
|
* @param {String|Boolean|Number} value
|
||||||
|
* @returns {Boolean} exists?
|
||||||
|
*/
|
||||||
exports.set = (category,key,value) => {
|
exports.set = (category,key,value) => {
|
||||||
const currentData = getData()
|
const currentData = getData()
|
||||||
const exists = currentData.find((d) => (d.category == category) && (d.key == key)) ? true : false
|
const exists = currentData.find((d) => (d.category == category) && (d.key == key)) ? true : false
|
||||||
@@ -39,18 +45,17 @@ exports.set = (category,key,value) => {
|
|||||||
/**
|
/**
|
||||||
* @param {String} category
|
* @param {String} category
|
||||||
* @param {String} key
|
* @param {String} key
|
||||||
* @returns {String|false}
|
* @returns {String|Boolean|Number|undefined}
|
||||||
*/
|
*/
|
||||||
exports.get = (category,key) => {
|
exports.get = (category,key) => {
|
||||||
const currentData = getData()
|
const currentData = getData()
|
||||||
const tempresult = currentData.find((d) => (d.category == category) && (d.key == key))
|
const result = currentData.find((d) => (d.category == category) && (d.key == key))
|
||||||
const result = tempresult ? tempresult.value : false
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {String} category
|
* @param {String} category
|
||||||
* @returns {[{key:String,value:String}]|false}
|
* @returns {[{key:String,value:String|Boolean|Number}]|false}
|
||||||
*/
|
*/
|
||||||
exports.getCategory = (category) => {
|
exports.getCategory = (category) => {
|
||||||
const currentData = getData()
|
const currentData = getData()
|
||||||
@@ -61,7 +66,7 @@ exports.getCategory = (category) => {
|
|||||||
/**
|
/**
|
||||||
* @param {String} category
|
* @param {String} category
|
||||||
* @param {String} key
|
* @param {String} key
|
||||||
* @param {String} value
|
* @returns {Boolean} exists?
|
||||||
*/
|
*/
|
||||||
exports.delete = (category,key) => {
|
exports.delete = (category,key) => {
|
||||||
const currentData = getData()
|
const currentData = getData()
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
const bot = require('../index')
|
||||||
|
const client = bot.client
|
||||||
|
const config = bot.config
|
||||||
|
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 */
|
||||||
|
/**
|
||||||
|
* @callback OTStatsCallback
|
||||||
|
* @param {Boolean|Number|String} current
|
||||||
|
* @returns {Boolean|Number|String|undefined}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OTGlobalStatsType} type
|
||||||
|
* @param {OTStatsCallback} callback
|
||||||
|
*/
|
||||||
|
const updateGlobalStats = (type,callback) => {
|
||||||
|
const currentstat = bot.statsStorage.get("global",type)
|
||||||
|
const newstat = callback(currentstat)
|
||||||
|
if (["string","number","boolean"].includes(typeof newstat)){
|
||||||
|
bot.statsStorage.set("global",type,newstat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OTTicketStatsType} type
|
||||||
|
* @param {String} id
|
||||||
|
* @param {OTStatsCallback} callback
|
||||||
|
*/
|
||||||
|
const updateTicketStats = (type,id,callback) => {
|
||||||
|
const currentstat = bot.statsStorage.get("ticket_"+id,type)
|
||||||
|
const newstat = callback(currentstat)
|
||||||
|
if (["string","number","boolean"].includes(typeof newstat)){
|
||||||
|
bot.statsStorage.set("ticket"+id,type,newstat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {OTUserStatsType} type
|
||||||
|
* @param {String} id
|
||||||
|
* @param {OTStatsCallback} callback
|
||||||
|
*/
|
||||||
|
const updateUserStats = (type,id,callback) => {
|
||||||
|
const currentstat = bot.statsStorage.get("user"+id,type)
|
||||||
|
const newstat = callback(currentstat)
|
||||||
|
if (["string","number","boolean"].includes(typeof newstat)){
|
||||||
|
bot.statsStorage.set("user"+id,type,newstat)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {"global"|"ticket"|"user"} scope
|
||||||
|
* @param {OTGlobalStatsType|OTTicketStatsType|OTUserStatsType} type
|
||||||
|
* @param {String} [id]
|
||||||
|
*/
|
||||||
|
const removeStats = (scope,type,id) => {
|
||||||
|
const newScope = (scope == "global") ? scope : scope+"_"+id
|
||||||
|
bot.statsStorage.delete(newScope,type)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
updateGlobalStats,
|
||||||
|
updateTicketStats,
|
||||||
|
updateUserStats,
|
||||||
|
removeStats
|
||||||
|
}
|
||||||
+1
-1
@@ -13,7 +13,7 @@
|
|||||||
"author": "DJdj Development",
|
"author": "DJdj Development",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.27.2",
|
"axios": "^1.6.2",
|
||||||
"chalk": "^5.0.1",
|
"chalk": "^5.0.1",
|
||||||
"discord.js": "^14.14.1"
|
"discord.js": "^14.14.1"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user