mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 00:10:58 -05:00
Add level-up notification setting (False by default)
This commit is contained in:
parent
de6e3370ed
commit
55b60742b8
@ -24,7 +24,7 @@ export default {
|
|||||||
const index = allData.sort((a, b) => b.messages - a.messages).map(x => x._id).indexOf(member.id) + 1;
|
const index = allData.sort((a, b) => b.messages - a.messages).map(x => x._id).indexOf(member.id) + 1;
|
||||||
const memberDifference = userData.messages - client.userLevels.algorithm(userData.level);
|
const memberDifference = userData.messages - client.userLevels.algorithm(userData.level);
|
||||||
const levelDifference = client.userLevels.algorithm(userData.level+1) - client.userLevels.algorithm(userData.level);
|
const levelDifference = client.userLevels.algorithm(userData.level+1) - client.userLevels.algorithm(userData.level);
|
||||||
interaction.reply({embeds: [new client.embed().setColor(member.displayColor).setTitle(`Level: **${userData.level}**\nRank: **${index ? '#' + index : 'last'}**\nProgress: **${memberDifference}/${levelDifference} (${(memberDifference/levelDifference*100).toFixed(2)}%)**\nTotal: **${userData.messages.toLocaleString('en-US')}**`).setThumbnail(member.avatarURL({extension:'png',size:1024}) || member.user.avatarURL({extension:'png',size:1024}) || member.user.defaultAvatarURL)]})
|
interaction.reply({embeds: [new client.embed().setColor(member.displayColor).setTitle(`Level: **${userData.level}**\nRank: **${index ? '#' + index : 'last'}**\nProgress: **${memberDifference}/${levelDifference} (${(memberDifference/levelDifference*100).toFixed(2)}%)**\nTotal: **${userData.messages.toLocaleString('en-US')}**`).setThumbnail(member.avatarURL({extension:'png',size:1024}) || member.user.avatarURL({extension:'png',size:1024}) || member.user.defaultAvatarURL).setFooter({text: userData.notificationPing === true ? 'Ping notification enabled' : 'Ping notification disabled'})]})
|
||||||
},
|
},
|
||||||
leaderboard: ()=>{
|
leaderboard: ()=>{
|
||||||
const messageCountsTotal = allData.reduce((a, b) => a + b.messages, 0);
|
const messageCountsTotal = allData.reduce((a, b) => a + b.messages, 0);
|
||||||
@ -156,7 +156,17 @@ export default {
|
|||||||
.setImage('attachment://dailymsgs.png').setColor(client.config.embedColor)
|
.setImage('attachment://dailymsgs.png').setColor(client.config.embedColor)
|
||||||
.setFooter({text: 'Graph updates daily.'})
|
.setFooter({text: 'Graph updates daily.'})
|
||||||
interaction.reply({embeds: [embed], files: [graphImage]})
|
interaction.reply({embeds: [embed], files: [graphImage]})
|
||||||
}
|
},
|
||||||
|
notification: async()=>{
|
||||||
|
const findUserInMongo = await client.userLevels._content.findById(interaction.user.id);
|
||||||
|
if (!findUserInMongo.notificationPing ?? findUserInMongo.notificationPing === false) {
|
||||||
|
await findUserInMongo.updateOne({_id: interaction.user.id, notificationPing: true})
|
||||||
|
interaction.reply({content: 'You will be pinged for level-up notification in the future.', ephemeral: true})
|
||||||
|
} else if (findUserInMongo.notificationPing === true) {
|
||||||
|
await findUserInMongo.updateOne({_id: interaction.user.id, notificationPing: false})
|
||||||
|
interaction.reply({content: 'You won\'t be pinged for level-up notification in the future.', ephemeral: true})
|
||||||
|
}
|
||||||
|
}
|
||||||
} as any)[interaction.options.getSubcommand()]();
|
} as any)[interaction.options.getSubcommand()]();
|
||||||
},
|
},
|
||||||
data: new Discord.SlashCommandBuilder()
|
data: new Discord.SlashCommandBuilder()
|
||||||
@ -171,4 +181,7 @@ export default {
|
|||||||
.addSubcommand(x=>x
|
.addSubcommand(x=>x
|
||||||
.setName('leaderboard')
|
.setName('leaderboard')
|
||||||
.setDescription('View top 10 users on leaderboard'))
|
.setDescription('View top 10 users on leaderboard'))
|
||||||
|
.addSubcommand(x=>x
|
||||||
|
.setName('notification')
|
||||||
|
.setDescription('Allow the bot to ping you or not when you level up'))
|
||||||
}
|
}
|
@ -5,7 +5,8 @@ import mongoose from 'mongoose';
|
|||||||
const Schema = mongoose.model('userLevels', new mongoose.Schema({
|
const Schema = mongoose.model('userLevels', new mongoose.Schema({
|
||||||
_id: {type: String},
|
_id: {type: String},
|
||||||
messages: {type: Number, required: true},
|
messages: {type: Number, required: true},
|
||||||
level: {type: Number, required: true}
|
level: {type: Number, required: true},
|
||||||
|
notificationPing: {type: Boolean}
|
||||||
}, {versionKey: false}));
|
}, {versionKey: false}));
|
||||||
|
|
||||||
export default class userLevels extends Schema {
|
export default class userLevels extends Schema {
|
||||||
@ -18,7 +19,6 @@ export default class userLevels extends Schema {
|
|||||||
}
|
}
|
||||||
async incrementUser(userid:string){
|
async incrementUser(userid:string){
|
||||||
const userData = await this._content.findById(userid)
|
const userData = await this._content.findById(userid)
|
||||||
|
|
||||||
if (userData){
|
if (userData){
|
||||||
await this._content.findByIdAndUpdate(userid, {messages: userData.messages + 1});
|
await this._content.findByIdAndUpdate(userid, {messages: userData.messages + 1});
|
||||||
if (userData.messages >= this.algorithm(userData.level+2)){
|
if (userData.messages >= this.algorithm(userData.level+2)){
|
||||||
@ -28,9 +28,10 @@ export default class userLevels extends Schema {
|
|||||||
}
|
}
|
||||||
} else if (userData.messages >= this.algorithm(userData.level+1)) {
|
} else if (userData.messages >= this.algorithm(userData.level+1)) {
|
||||||
const newData = await this._content.findByIdAndUpdate(userid, {level:userData.level+1}, {new: true});
|
const newData = await this._content.findByIdAndUpdate(userid, {level:userData.level+1}, {new: true});
|
||||||
(this.client.channels.resolve(this.client.config.mainServer.channels.botcommands) as Discord.TextChannel).send({content: `<@${userid}> has reached level **${newData.level}**. GG!`, allowedMentions: {parse: ['users']}})
|
const fetchUserSchema = await this._content.findById(userid);
|
||||||
|
(this.client.channels.resolve(this.client.config.mainServer.channels.botcommands) as Discord.TextChannel).send({content: `${fetchUserSchema.notificationPing === true ? `<@${userid}>` : `**${(await this.client.users.fetch(userid)).username}**`} has reached level **${newData.level}**. GG!`, allowedMentions: {parse: ['users']}});
|
||||||
}
|
}
|
||||||
} else await this._content.create({_id: userid, messages: 1, level: 0})
|
} else await this._content.create({_id: userid, notificationPing: true, messages: 1, level: 0})
|
||||||
}
|
}
|
||||||
algorithm = (level:number)=>level*level*15;
|
algorithm = (level:number)=>level*level*15;
|
||||||
// Algorithm for determining levels. If adjusting, recommended to only change the integer at the end of equation.
|
// Algorithm for determining levels. If adjusting, recommended to only change the integer at the end of equation.
|
||||||
|
Loading…
Reference in New Issue
Block a user