-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress.js
90 lines (81 loc) · 3.14 KB
/
progress.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const User = require('../../models/User')
const saveErrorToDatabase = require('../../utils/saveErrorToDatabase')
const { Client, Interaction, ApplicationCommandOptionType } = require('discord.js');
const reply = require("../../utils/reply");
module.exports = {
name: 'progress',
description: 'update your daily progress',
devOnly: false,
testOnly: false,
options: [{
name: 'updates',
description: 'progress made',
type: ApplicationCommandOptionType.String,
required: true,
}],
deleted: false,
/**
*
* @param {Client} client
* @param {Interaction} interaction
*/
callback: async(client, interaction) => {
// interaction.deferReply({ephemeral: true});
if(interaction.channelId !== process.env.DAILYPROGRESS_CHANNEL_ID){
interaction.reply({
content: `The command ${interaction.commandName} can only be used in ${interaction.guild.channels.cache.get(process.env.DAILYPROGRESS_CHANNEL_ID)} channel`,
ephemeral: true,
})
return;
}
try {
const query = {
userId: interaction.member.id,
guildId: interaction.guild.id,
}
let user = await User.findOne(query);
if(user){
const lastDailyDate = user.lastDaily.toDateString();
const currentDate = new Date().toDateString();
const newData = user.data;
if(lastDailyDate === currentDate){
interaction.reply({
content: `${interaction.member.user} you have already updated your progress, please come tommorrow to update your progress`,
// ephemeral: true
});
return;
}
newData.push(interaction.options.get('updates').value);
user.data = newData;
user.lastDaily = new Date();
}
else{
const newData = [];
newData.push(interaction.options.get('updates').value);
user = new User({
...query,
lastDaily: new Date(),
data: newData,
});
}
user.points += 25;
interaction.deferReply()
const message = await reply(interaction.options.get('updates').value, interaction.user.id, user.points);
if(message === "BhagulobsDobby"){
interaction.editReply({
content: `Good progress ${interaction.member.user}, daily reward of 25 points is added to your account. Now your balance is ${user.points}`,
// ephemeral: true,
});
}else{
interaction.editReply({
content: message,
// ephemeral: true,
});
}
await user.save();
return;
} catch (error) {
saveErrorToDatabase(error);
}
}
}