You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.4 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. const {
  2. mongo_url,
  3. trello_token,
  4. trello_key
  5. } = require('../config.json');
  6. const {
  7. userModel,
  8. } = require('./schemas.js');
  9. let mongoose = require('mongoose');
  10. module.exports = {
  11. name: 'upgrade',
  12. channels: ['734387503464710165'],
  13. description: 'Upgrade a user!',
  14. roles: ['732345527143759943'],
  15. async execute(message,args) {
  16. try {
  17. await mongoose.connect( mongo_url, {useNewUrlParser: true, useUnifiedTopology: true}, () => null );
  18. }catch (error) {
  19. console.log("ERROR WITH MONGODB CONNECTION");
  20. }
  21. var roles_hierarchy = [
  22. '732558019409346603', // 'kiddie,
  23. '732618552661770241', // 'hunter',
  24. '732618853355356192', // 'hacker',
  25. '732618650158366770' // 'mentor'
  26. ];
  27. const member = message.mentions.members.first();
  28. let data = await userModel.find({_id : member.id},"rank")
  29. let current_index = data[0].rank - 1
  30. if(current_index == roles_hierarchy.length - 1){
  31. return message.channel.send("This user is already at the highest level!")
  32. }
  33. member.roles.remove(roles_hierarchy[current_index])
  34. member.roles.add(roles_hierarchy[current_index + 1]);
  35. userModel.findOneAndUpdate(
  36. {_id : member.id},
  37. {rank : current_index + 2},
  38. {
  39. new: true,
  40. runValidators: true,
  41. useFindAndModify: false
  42. }, function(err, result) {
  43. //if (err) {console.log(err); } else {console.log(result);}
  44. });
  45. return message.channel.send("User upgraded successfully!")
  46. },
  47. };