Re-factor portal system

This commit is contained in:
Daniel Odendahl Jr
2018-02-17 21:56:09 +00:00
parent e1e848a08f
commit e2089131d0
5 changed files with 70 additions and 9 deletions
+1
View File
@@ -28,6 +28,7 @@ client.registry
['avatar-edit', 'Avatar Manipulation'],
['text-edit', 'Text Manipulation'],
['number-edit', 'Number Manipulation'],
['portal', 'Portal Messages'],
['other', 'Other'],
['roleplay', 'Roleplay']
])
+30
View File
@@ -0,0 +1,30 @@
const { Command } = require('discord.js-commando');
module.exports = class AddPortalChannelCommand extends Command {
constructor(client) {
super(client, {
name: 'add-portal-channel',
aliases: ['set-portal-channel', 'portal-channel', 'open-portal'],
group: 'portal',
memberName: 'add-portal-channel',
description: 'Sets a channel to be a portal channel.',
guildOnly: true,
args: [
{
key: 'channel',
prompt: 'What channel do you want to set as a portal channel?',
type: 'channel'
}
]
});
}
run(msg, { channel }) {
if (channel.type !== 'text') return msg.reply('Only text channels can have a portal!');
const channels = this.client.provider.get('global', 'portals', []);
if (channels.includes(channel.id)) return msg.reply(`${channel} is already has an open portal!`);
channels.push(channel.id);
this.client.provider.set('global', 'portals', channels);
return msg.say(`A portal opened in ${channel}!`);
}
};
@@ -5,10 +5,9 @@ module.exports = class PortalSendCommand extends Command {
super(client, {
name: 'portal-send',
aliases: ['send-portal-message', 'portal-message', 'send-portal-msg', 'portal-msg'],
group: 'text-edit',
group: 'portal',
memberName: 'portal-send',
description: 'Send a message to a random channel with "<portal>" in the topic.',
guildOnly: true,
description: 'Send a message to a portal channel.',
args: [
{
key: 'message',
@@ -22,12 +21,12 @@ module.exports = class PortalSendCommand extends Command {
async run(msg, { message }) {
if (/discord(\.gg|app\.com\/invite|\.me)\//gi.test(message)) return msg.reply('Please do not send invites.');
const valid = this.client.channels.filter(channel => channel.type === 'text' && channel.guild.id !== msg.guild.id);
const channels = valid.filter(channel => channel.topic && channel.topic.toLowerCase().includes('<portal>'));
if (!channels.size) return msg.say('No channels have an open portal.');
const channel = channels.random();
let channels = this.client.provider.get('global', 'portals', []);
if (msg.channel.type === 'text') channels = channels.filter(channel => !msg.guild.channels.has(channel));
if (!channels.length) return msg.reply('No channels have an open portal...');
const channel = this.client.channels.get(channels[Math.floor(Math.random() * channels.length)]);
try {
await channel.send(`**${msg.author.tag} (${msg.guild.name})**: ${message}`);
await channel.send(`**${msg.author.tag} (${msg.channel.type !== 'text' ? 'DM' : msg.guild.name})**: ${message}`);
return msg.say(`Message sent to **${channel.name}** in **${channel.guild.name}**!`);
} catch (err) {
return msg.reply('Failed to send the message. Try again later!');
+31
View File
@@ -0,0 +1,31 @@
const { Command } = require('discord.js-commando');
module.exports = class RemovePortalChannelCommand extends Command {
constructor(client) {
super(client, {
name: 'remove-portal-channel',
aliases: ['delete-portal-channel', 'close-portal'],
group: 'portal',
memberName: 'remove-portal-channel',
description: 'Remove a channel from the portal channels.',
guildOnly: true,
args: [
{
key: 'channel',
prompt: 'What channel do you want to remove from the portal channels?',
type: 'channel'
}
]
});
}
run(msg, { channel }) {
if (channel.type !== 'text') return msg.reply('Only text channels can have a portal!');
const channels = this.client.provider.get('global', 'portals', []);
if (!channels.includes(channel.id)) return msg.reply(`${channel} does not have an open portal!`);
channels.splice(channels.indexOf(channel.id), 1);
if (!channels.length) this.client.provider.remove('global', 'portals');
else this.client.provider.set('global', 'portals', channels);
return msg.say(`The portal in ${channel} closed...`);
}
};
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiao",
"version": "64.1.2",
"version": "65.0.0",
"description": "Your personal server companion.",
"main": "Xiao.js",
"scripts": {