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'); const strikeM = require('../../models/strikes');
class strike extends Command{ class strike extends Command{
@ -18,6 +18,8 @@ const strikeM = require('../../models/strikes');
{ {
//Check admin privilege //Check admin privilege
this.message = message; 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); 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.']) 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(); var strike = new strikeM();
@ -27,6 +29,7 @@ const strikeM = require('../../models/strikes');
strike.guildID = message.guild.id strike.guildID = message.guild.id
strike.reason = confirm.reason; strike.reason = confirm.reason;
strike.date = Date.now(); strike.date = Date.now();
strike.expireAt = (new Date(Date.now()+(15*24*60*60*1000)));
strike.save(err=> strike.save(err=>
{ {
if(err)console.log(err); if(err)console.log(err);
@ -60,14 +63,6 @@ const strikeM = require('../../models/strikes');
collector.on('collect', async m => collector.on('collect', async m =>
{ {
m.message.delete() m.message.delete()
.then(()=>
{
// console.log('Strikes: Embed Message: Deleted');
})
.catch(()=>
{
// console.log('Strikes: Embed Message: failed to delete.');
})
}); });
collector.on('end', async ()=> collector.on('end', async ()=>
{ {

@ -413,7 +413,8 @@ const ErrorType =
Arguments: "Arguments", Arguments: "Arguments",
NoArguments: "No Arguments Given", NoArguments: "No Arguments Given",
NotOnTheList: "Unknown Command", 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; module.exports.ErrorType = ErrorType;
@ -496,6 +497,10 @@ class ErrorMessage
case ErrorType.OldMessages: case ErrorType.OldMessages:
embed.data.fields[0].value =ErrorType.OldMessages; embed.data.fields[0].value =ErrorType.OldMessages;
break; 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: default:
break; break;
} }
@ -1246,41 +1251,62 @@ class Strikes
}, 5*60*1000); }, 5*60*1000);
//TODO: Handle old strikes //TODO: Handle old strikes
//* Strikes life time should be difined by guild /**
//* A default should be set * db.strikes.createIndex({expireAt:1}, {expireAfterSeconds:0})
//? 15 days * 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() 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}); * TODO: Grab validated strikes.
if(!guilds) return console.log('Striker: No Guilds') * TODO: Check if guild has strikes active.
var guildIds = []; * TODO: Handle player if strikes have reached the threshold
for(var i = 0; i<guilds.length; i++) * TODO: X
{ *
guildIds.push(guilds[i].gID); */
}
var filtered = Strikes.filter( // const Strikes = await strikesM.find().then(s=>{return s});
(e) => { // //console.log(Strikes);
return guildIds.indexOf(e.guildID)>=0; // const guilds = await guildsM.find({strikes:true}).then(g=>{return g});
} // if(!guilds) return console.log('Striker: No Guilds')
) // var guildIds = [];
guildIds.forEach(guild=> // for(var i = 0; i<guilds.length; i++)
{ // {
filtered.forEach(strike=> // guildIds.push(guilds[i].gID);
{ // }
(async (guild, strike)=> // var filtered = Strikes.filter(
{ // (e) => {
const ammount = await strikesM.find({guildID:guild, strokedID:strike.strokedID}).then(res=>{return res.length}); // return guildIds.indexOf(e.guildID)>=0;
if(ammount>2) // }
{ // )
this.handleStroked(strike.strokedID, guild); // guildIds.forEach(guild=>
} // {
})(guild, strike) // 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) handleStroked(user, guild)
{ {
@ -1295,4 +1321,5 @@ class Strikes
.then(() => console.log(`Successfully kicked ${user.user.username}`)) .then(() => console.log(`Successfully kicked ${user.user.username}`))
.catch(err => console.log(`Unable to kick ${user.user.username}: ${err}`)); .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}, guildID:{type:String, required: true},
reason:{type:String, required:true}, reason:{type:String, required:true},
date:{type:Date, required:true}, date:{type:Date, required:true},
expireAt:{type:Date, required:true}
} }
); );

Loading…
Cancel
Save