diff --git a/Xiao.js b/Xiao.js index 8f988068..9390721b 100644 --- a/Xiao.js +++ b/Xiao.js @@ -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'] ]) diff --git a/commands/portal/add-portal-channel.js b/commands/portal/add-portal-channel.js new file mode 100644 index 00000000..1d86f93c --- /dev/null +++ b/commands/portal/add-portal-channel.js @@ -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}!`); + } +}; diff --git a/commands/text-edit/portal-send.js b/commands/portal/portal-send.js similarity index 58% rename from commands/text-edit/portal-send.js rename to commands/portal/portal-send.js index c099252d..fea90504 100644 --- a/commands/text-edit/portal-send.js +++ b/commands/portal/portal-send.js @@ -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 "" 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('')); - 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!'); diff --git a/commands/portal/remove-portal-channel.js b/commands/portal/remove-portal-channel.js new file mode 100644 index 00000000..21ebb600 --- /dev/null +++ b/commands/portal/remove-portal-channel.js @@ -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...`); + } +}; diff --git a/package.json b/package.json index 87619f5c..4b29e85a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiao", - "version": "64.1.2", + "version": "65.0.0", "description": "Your personal server companion.", "main": "Xiao.js", "scripts": {