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.

53 lines
1.7 KiB

  1. const {
  2. mongo_url,
  3. trello_token,
  4. trello_key
  5. } = require('../config.json');
  6. const {
  7. userModel,
  8. teamModel,
  9. } = require('./schemas.js');
  10. let mongoose = require('mongoose');
  11. let Trello = require('trello-node-api')(trello_key, trello_token);
  12. module.exports = {
  13. name: 'close',
  14. family: 'team',
  15. channels: ['734387503464710165'],
  16. description: 'Close the team! ',
  17. async execute(message) {
  18. var member_id = message.member.id;
  19. try {
  20. await mongoose.connect( mongo_url, {useNewUrlParser: true, useUnifiedTopology: true}, () => null);
  21. }catch (error) {
  22. console.log("could not connect");
  23. }
  24. const user_data = await userModel.find({_id: member_id},"team_id trello_id email");
  25. const team_id = user_data[0].team_id
  26. if(team_id == '0'){
  27. return message.reply('You must be in a team to quit!');
  28. }
  29. var teamdata = await teamModel.find({ _id :team_id },'member_role mod_role text_channel voice_channel mods board_id');
  30. var team = teamdata[0];
  31. message.guild.roles.fetch(team.member_role).then((role) => role.delete());
  32. message.guild.roles.fetch(team.mod_role).then((role) => role.delete());
  33. message.client.channels.fetch(team.text_channel).then((channel) => channel.delete());
  34. message.client.channels.fetch(team.voice_channel).then((channel) => channel.delete());
  35. let old_team = new teamModel(team);
  36. old_team.remove();
  37. Trello.board.del(team.board_id)
  38. .catch(function (error) {
  39. console.log('error', error);
  40. });
  41. userModel.updateMany({team_id: team_id}, { team_id: 0 }, function(err, res) {});
  42. message.channel.send("Team closed successfully!")
  43. },
  44. }