mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Re-factor portal system
This commit is contained in:
@@ -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']
|
||||
])
|
||||
|
||||
@@ -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!');
|
||||
@@ -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
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "xiao",
|
||||
"version": "64.1.2",
|
||||
"version": "65.0.0",
|
||||
"description": "Your personal server companion.",
|
||||
"main": "Xiao.js",
|
||||
"scripts": {
|
||||
|
||||
Reference in New Issue
Block a user