Restore strike self-actionability

master
masterhc 1 year ago
parent e3508d00db
commit 989bb5d671

@ -1265,46 +1265,63 @@ class Strikes
* TODO: Handle player if strikes have reached the threshold * TODO: Handle player if strikes have reached the threshold
* *
*/ */
const Strikes = await strikesM.find().then(s=>{return s}); const Strikes = await strikesM.find().then(s=>{return s})
const guilds = await guildsM.find({strikes:true}).then(g=>{return g}); if(Strikes.length==0) return console.log('Lib: Striker: No Strikes')
if(!guilds) return console.log('Lib: Striker: No Guilds') const guilds = await guildsM.find({strikes:true}).then(g=>{return g})
var guildIds = []; .then(guilds => guilds.map(guild => guild.gID));;
for(var i = 0; i<guilds.length; i++) if(guilds.length==0) return console.log('Lib: Striker: No Guilds')
const validStrikes = await strikesM.find({validated:true}).then(res=>{return res});
const strikesByGuildID = new Map();
validStrikes.forEach(strike =>
{ {
guildIds.push(guilds[i].gID); const { strokedID, guildID } = strike;
}
var filtered = Strikes.filter( // If the guildID key doesn't exist in strikesByGuildID, create it
(e) => { if (!strikesByGuildID.has(guildID)) strikesByGuildID.set(guildID, new Map());
return guildIds.indexOf(e.guildID)>=0;
} const strikesByStrokedID = strikesByGuildID.get(guildID);
)
guildIds.forEach(guild=> // If the strokedID key doesn't exist in the strikesByStrokedID map, create it
if (!strikesByStrokedID.has(strokedID)) strikesByStrokedID.set(strokedID, [strike]);
else strikesByStrokedID.get(strokedID).push(strike);
});
const guildsWith3Strikes = new Map();
strikesByGuildID.forEach((strikesByStrokedID, guildID) => {
// Filter strikes by each strokedID to find users with at least three strikes
const usersWith3Strikes = [];
strikesByStrokedID.forEach((strikes, strokedID) => {
if (strikes.length >= 3) {
usersWith3Strikes.push({ user: strokedID, strikes });
}
});
// If there are users with at least three strikes, add them to the map
if (usersWith3Strikes.length > 0) {
guildsWith3Strikes.set(guildID, usersWith3Strikes);
}
});
const guildsWith3StrikesFiltered = new Map([...guildsWith3Strikes].filter(([guildID]) => guilds.includes(guildID)));
guildsWith3StrikesFiltered.forEach((guild, guildid)=>
{
guild.forEach((user)=>
{ {
filtered.forEach(strike=> this.handleStroked(user,guildid);
{
(async (guild, strike)=>
{
const ammount = await strikesM.find({guildID:guild, strokedID:strike.strokedID, validated:true}).then(res=>{return res.length});
if(ammount>2)
{
this.handleStroked(strike.strokedID, guild);
}
})(guild, strike)
})
}) })
})
} }
handleStroked(user, guild) handleStroked(user, guild)
{ {
// strikesM.deleteMany({ guildID: guild, strokedID: user }, (err, res) => { const member = this.client.guilds.cache.get(guild).members.cache.get(user.user);
// if (!err) return console.log('Lib: Strikes: Deleted: From User:', user, 'on Guild:', guild) if (!member) return console.log('Lib:Strikes: Handle Struck: Member not valid', member)
// }); const reason = `Strike 1: ${user.strikes[0].reason}; Strike 2: ${user.strikes[1].reason}; Strike 3: ${user.strikes[2].reason}`;
// If the user is found, kick them from the server member.kick(reason)
// const member = this.client.guilds.cache.get(guild).members.cache.get(user); .then(() => console.log(`Successfully kicked ${member.user.username}`))
// if (!member) return console.log('Lib:Strikes: Handle Struck: Member not valid') .catch(err => console.log(`Unable to kick ${member.user.username}: ${err}`));
// console.log(member.user.username) strikesM.deleteMany({ guildID: guild, strokedID: user.user }, (err, res) => {
// member.kick('Optional reason that will be displayed in the audit logs') if (!err) return console.log('Lib: Strikes: Deleted: From User:', member.user.username, 'on Guild:', member.guild.name)
// .then(() => console.log(`Successfully kicked ${user.user.username}`)) });
// .catch(err => console.log(`Unable to kick ${user.user.username}: ${err}`));
} }
} }
module.exports.Strikes = Strikes; module.exports.Strikes = Strikes;

Loading…
Cancel
Save