Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.94 KB | None | 0 0
  1. if (command === 'battery' || command === 'batteries') {
  2. bot.test = require('./battery.json');
  3. bot.test[message.guild.id] = {
  4. "ch": message.channel.id
  5. }
  6. if (message.member.permissions.has("MANAGE_ROLES") || message.author.id === admin) {
  7. if (args[0] === 'on') {
  8. fs.writeFile("./battery.json", JSON.stringify(bot.test, null, 4), (err) => {
  9. if (err) console.error(err)
  10. });
  11. console.log(`${message.guild.name} was added to reminders list`);
  12. message.channel.send(`${message.guild.name} is now receiving reminder for batteries.`);
  13.  
  14. } else if (args[0] === 'off') {
  15. let success = 0;
  16. fs.readFile('battery.json', 'utf8', function readFileCallback(err, data) {
  17. if (err) console.error(err);
  18. let dict = JSON.parse(data);
  19. Object.keys(dict).forEach((element) => {
  20. if (element === message.guild.id) {
  21. delete dict[element];
  22. success = 1;
  23. fs.writeFile("./battery.json", JSON.stringify(dict, 4, 4), (err) => {
  24. if (err) console.error(err);
  25.  
  26. });
  27. if (success === 1) message.channel.send(`${message.guild.name} is no longer receiving reminders for batteries`);
  28. }
  29. });
  30. if (success === 0) message.channel.send(`${message.guild.name} is not currently receiving reminders for batteries.`);
  31. });
  32. } else message.channel.send("Please let me know if you would reminders for batteries turned `on` or `off`");
  33. } else message.channel.send("I'm sorry but you do not have the permissions for this. Please ask your admin to turn on reminders.");
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement