Skip to content

Commit

Permalink
Rss role command - change the role to mention for a feed
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaaz committed Sep 23, 2018
1 parent 24c508d commit 7701f94
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/modules/Rss/commands/Rss_Role.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict';

import { Command } from 'axoncore';

class Role extends Command {
constructor(module) {
super(module);

this.label = 'role';
this.aliases = ['role'];

this.isSubcmd = true;

this.infos = {
owner: ['KhaaZ'],
name: 'rss role',
description: 'Edit role to mention.',
usage: 'rss role [feed name | feed url] [role]',
examples: ['rss role splashtoon everyone', 'rss role splashtoon splashtoonRole'],
};

this.options.argsMin = 2;
this.options.cooldown = 10000;

this.permissions.user.needed = ['manageGuild'];
this.permissions.serverAdmin = true;
}

get rssHandler() {
return this.module.APIHandler;
}

async execute({ msg, args }) {
const api = this.rssHandler.apis.find(a => a.name.toLowerCase() === args[0].toLowerCase());
if (!api) {
return this.sendError(msg.channel, 'Ce feed n\'existe pas!');
}
if (!api.guilds[msg.channel.guild.id]) {
return this.sendError(msg.channel, 'Vous n\'avez pas souscris a ce feed!');
}

let role;
if (args[1] === 'everyone' || args[1] === 'here') {
role = args[1];
}
let roleObj;
if (!role) {
roleObj = this.Resolver.role(msg.channel.guild, args.slice(1));
if (!roleObj) {
return this.sendError(msg.channel, 'Ce role n\'existe pas!');
} else {
role = roleObj.id;
}
}

await this.rssHandler.updateRoleFeed(api.url, msg.channel.guild.id, role);
return this.sendSuccess(msg.channel, `Vous avez changé le role a mentionné pour **${api.name}** pour etre **${roleObj ? roleObj.name : role}**.`);
}
}

export default Role;

0 comments on commit 7701f94

Please sign in to comment.