Revamp of strikes

master
masterhc 1 year ago
parent 129a4e5600
commit 873992dbbf

@ -1,6 +1,6 @@
const {Command,ErrorMessage, ErrorType, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle} = require('../../lib.js')
const {Command,ErrorMessage, ErrorType, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, Strikes} = require('../../lib.js')
const strikeM = require('../../models/strikes');
class strike extends Command{
@ -18,6 +18,8 @@ const strikeM = require('../../models/strikes');
{
//Check admin privilege
this.message = message;
const isActive = await new Strikes(this.client).getAreStrikesActive(message.guildId);
if(!isActive) return new ErrorMessage(this.client).send(ErrorType.FeatureInnactive, message)
var confirm = await this.confirmArgs(message,args);
if(confirm=='Error') return new ErrorMessage(this.client).send(ErrorType.Arguments, message, ['Use the mention method to pass the user.', 'Make sure you provide a reason.'])
var strike = new strikeM();
@ -27,6 +29,7 @@ const strikeM = require('../../models/strikes');
strike.guildID = message.guild.id
strike.reason = confirm.reason;
strike.date = Date.now();
strike.expireAt = (new Date(Date.now()+(15*24*60*60*1000)));
strike.save(err=>
{
if(err)console.log(err);
@ -60,14 +63,6 @@ const strikeM = require('../../models/strikes');
collector.on('collect', async m =>
{
m.message.delete()
.then(()=>
{
// console.log('Strikes: Embed Message: Deleted');
})
.catch(()=>
{
// console.log('Strikes: Embed Message: failed to delete.');
})
});
collector.on('end', async ()=>
{

@ -413,7 +413,8 @@ const ErrorType =
Arguments: "Arguments",
NoArguments: "No Arguments Given",
NotOnTheList: "Unknown Command",
OldMessages: "Can't delete this messages."
OldMessages: "Can't delete this messages.",
FeatureInnactive: "This feature is not active."
}
module.exports.ErrorType = ErrorType;
@ -496,6 +497,10 @@ class ErrorMessage
case ErrorType.OldMessages:
embed.data.fields[0].value =ErrorType.OldMessages;
break;
case ErrorType.FeatureInnactive:
embed.data.fields[0].value =ErrorType.FeatureInnactive;
embed.data.fields[1].value = 'If you are an admin you can activate the function on the dashboard. (rem.wordfights.com)'
break;
default:
break;
}
@ -1246,41 +1251,62 @@ class Strikes
}, 5*60*1000);
//TODO: Handle old strikes
//* Strikes life time should be difined by guild
//* A default should be set
//? 15 days
/**
* db.strikes.createIndex({expireAt:1}, {expireAfterSeconds:0})
* db.strikes.insertOne(
* {whatever data it takes,
* ! expireAt:new Date(new Date().getTime() + 60000)
* })
*
*
*/
}
async getAreStrikesActive(guildId)
{
const flag = await guildsM.find({gID:guildId}).then(g=>{return g.strikes});
if(!flag) return false;
return true;
}
async check()
{
const Strikes = await strikesM.find().then(s=>{return s});
//console.log(Strikes);
const guilds = await guildsM.find({strikes:true}).then(g=>{return g});
if(!guilds) return console.log('Striker: No Guilds')
var guildIds = [];
for(var i = 0; i<guilds.length; i++)
{
guildIds.push(guilds[i].gID);
}
var filtered = Strikes.filter(
(e) => {
return guildIds.indexOf(e.guildID)>=0;
}
)
guildIds.forEach(guild=>
{
filtered.forEach(strike=>
{
(async (guild, strike)=>
{
const ammount = await strikesM.find({guildID:guild, strokedID:strike.strokedID}).then(res=>{return res.length});
if(ammount>2)
{
this.handleStroked(strike.strokedID, guild);
}
})(guild, strike)
})
})
/**
* TODO: Grab validated strikes.
* TODO: Check if guild has strikes active.
* TODO: Handle player if strikes have reached the threshold
* TODO: X
*
*/
// const Strikes = await strikesM.find().then(s=>{return s});
// //console.log(Strikes);
// const guilds = await guildsM.find({strikes:true}).then(g=>{return g});
// if(!guilds) return console.log('Striker: No Guilds')
// var guildIds = [];
// for(var i = 0; i<guilds.length; i++)
// {
// guildIds.push(guilds[i].gID);
// }
// var filtered = Strikes.filter(
// (e) => {
// return guildIds.indexOf(e.guildID)>=0;
// }
// )
// guildIds.forEach(guild=>
// {
// filtered.forEach(strike=>
// {
// (async (guild, strike)=>
// {
// const ammount = await strikesM.find({guildID:guild, strokedID:strike.strokedID}).then(res=>{return res.length});
// if(ammount>2)
// {
// this.handleStroked(strike.strokedID, guild);
// }
// })(guild, strike)
// })
// })
}
handleStroked(user, guild)
{
@ -1295,4 +1321,5 @@ class Strikes
.then(() => console.log(`Successfully kicked ${user.user.username}`))
.catch(err => console.log(`Unable to kick ${user.user.username}: ${err}`));
}
}
}
module.exports.Strikes = Strikes;

@ -10,6 +10,7 @@ new Schema(
guildID:{type:String, required: true},
reason:{type:String, required:true},
date:{type:Date, required:true},
expireAt:{type:Date, required:true}
}
);

Loading…
Cancel
Save