mirror of
https://github.com/veganhacktivists/arabot.git
synced 2025-05-19 08:24:16 +02:00
Merge pull request #82 from veganhacktivists/nonvegan_access
feat(arabot): non-vegan access
This commit is contained in:
commit
f6149a60f5
65
src/commands/roles/nvAccess.ts
Normal file
65
src/commands/roles/nvAccess.ts
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
/*
|
||||||
|
Animal Rights Advocates Discord Bot
|
||||||
|
Copyright (C) 2023 Anthony Berg
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Command } from '@sapphire/framework';
|
||||||
|
import type { Message } from 'discord.js';
|
||||||
|
import IDs from '#utils/ids';
|
||||||
|
import { DurationFormatter } from '@sapphire/time-utilities';
|
||||||
|
|
||||||
|
export class ActivistCommand extends Command {
|
||||||
|
public constructor(context: Command.Context, options: Command.Options) {
|
||||||
|
super(context, {
|
||||||
|
...options,
|
||||||
|
name: 'nvaccess',
|
||||||
|
description: 'Gives the nvaccess role',
|
||||||
|
preconditions: ['DevCoordinatorOnly'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async messageRun(message: Message) {
|
||||||
|
const { guild } = message;
|
||||||
|
|
||||||
|
if (guild === null) {
|
||||||
|
await message.reply('Guild is null');
|
||||||
|
await message.react('❌');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await guild.members.fetch();
|
||||||
|
|
||||||
|
const vegan = await guild.roles.cache.get(IDs.roles.vegan.vegan);
|
||||||
|
|
||||||
|
if (vegan === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const vegans = vegan.members.map((member) => member);
|
||||||
|
const count = vegans.length;
|
||||||
|
const timeout = 1500;
|
||||||
|
|
||||||
|
await message.reply(`Starting the process now, ETA to completion: ${new DurationFormatter().format(timeout * count)}`);
|
||||||
|
|
||||||
|
for (let i = 0; i < count; i += 1) {
|
||||||
|
const member = vegans[i];
|
||||||
|
setTimeout(async () => {
|
||||||
|
await member.roles.add(IDs.roles.vegan.nvAccess);
|
||||||
|
this.container.logger.debug(`NVAccess: Processed ${i + 1}/${count}`);
|
||||||
|
}, timeout * i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
87
src/interaction-handlers/nonVeganAccess.ts
Normal file
87
src/interaction-handlers/nonVeganAccess.ts
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
/*
|
||||||
|
Animal Rights Advocates Discord Bot
|
||||||
|
Copyright (C) 2023 Anthony Berg
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { InteractionHandler, InteractionHandlerTypes, PieceContext } from '@sapphire/framework';
|
||||||
|
import type { ButtonInteraction, GuildMember } from 'discord.js';
|
||||||
|
import IDs from '#utils/ids';
|
||||||
|
|
||||||
|
export class NonVeganAccessButtonHandler extends InteractionHandler {
|
||||||
|
public constructor(ctx: PieceContext, options: InteractionHandler.Options) {
|
||||||
|
super(ctx, {
|
||||||
|
...options,
|
||||||
|
interactionHandlerType: InteractionHandlerTypes.Button,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public override parse(interaction: ButtonInteraction) {
|
||||||
|
if (interaction.customId !== 'nvAccess') return this.none();
|
||||||
|
|
||||||
|
return this.some();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async run(interaction: ButtonInteraction) {
|
||||||
|
let { member } = interaction;
|
||||||
|
|
||||||
|
const errorMessage = 'There was an error giving you the role, please try again later or contact ModMail/the developer '
|
||||||
|
+ 'to sort out this problem.';
|
||||||
|
|
||||||
|
if (member === null) {
|
||||||
|
await interaction.reply({
|
||||||
|
content: errorMessage,
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
member = member as GuildMember;
|
||||||
|
|
||||||
|
if (!member.roles.cache.has(IDs.roles.vegan.vegan)) {
|
||||||
|
await interaction.reply({
|
||||||
|
content: 'You need to be vegan to use this button!',
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (member.roles.cache.has(IDs.roles.vegan.nvAccess)) {
|
||||||
|
await member.roles.remove(IDs.roles.vegan.nvAccess);
|
||||||
|
await interaction.reply({
|
||||||
|
content: 'Your access from the non vegan section has been removed. '
|
||||||
|
+ 'If you want to gain access again, click this button again.',
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await member.roles.add(IDs.roles.vegan.nvAccess);
|
||||||
|
await interaction.reply({
|
||||||
|
content: 'Your access to the non vegan section has been given back. '
|
||||||
|
+ 'If you want to remove access again, click this button again.',
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
this.container.logger.error(`Non Vegan Access Interaction: ${error}`);
|
||||||
|
await interaction.reply({
|
||||||
|
content: errorMessage,
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
80
src/listeners/nonVeganAccess.ts
Normal file
80
src/listeners/nonVeganAccess.ts
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
/*
|
||||||
|
Animal Rights Advocates Discord Bot
|
||||||
|
Copyright (C) 2023 Anthony Berg
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { Listener } from '@sapphire/framework';
|
||||||
|
import { ButtonStyle, ActionRowBuilder, ButtonBuilder } from 'discord.js';
|
||||||
|
|
||||||
|
import type {
|
||||||
|
Client,
|
||||||
|
TextChannel,
|
||||||
|
} from 'discord.js';
|
||||||
|
import IDs from '#utils/ids';
|
||||||
|
|
||||||
|
export class NonVeganAccessReady extends Listener {
|
||||||
|
public constructor(context: Listener.Context, options: Listener.Options) {
|
||||||
|
super(context, {
|
||||||
|
...options,
|
||||||
|
once: true,
|
||||||
|
event: 'ready',
|
||||||
|
enabled: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async run(client: Client) {
|
||||||
|
let roles = client.channels.cache
|
||||||
|
.get(IDs.channels.information.roles) as TextChannel | undefined;
|
||||||
|
if (roles === undefined) {
|
||||||
|
roles = await client.channels
|
||||||
|
.fetch(IDs.channels.information.roles) as TextChannel | undefined;
|
||||||
|
if (roles === undefined) {
|
||||||
|
this.container.logger.error('nonVeganAccess: Roles not found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const botId = this.container.client.id;
|
||||||
|
const messages = await roles.messages.fetch();
|
||||||
|
const message = messages.first();
|
||||||
|
|
||||||
|
const content = '**Change access to non-vegan section of the server:**\n\n'
|
||||||
|
+ 'If you\'re vegan and want your access removed/added back to the non vegan sections, '
|
||||||
|
+ 'press the button bellow to remove/gain access to the non vegan sections.';
|
||||||
|
|
||||||
|
const button = new ActionRowBuilder<ButtonBuilder>()
|
||||||
|
.addComponents(
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setCustomId('nvAccess')
|
||||||
|
.setLabel('Non Vegan Access')
|
||||||
|
.setStyle(ButtonStyle.Primary),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (message?.author.id !== botId) {
|
||||||
|
await roles.send({
|
||||||
|
content,
|
||||||
|
components: [button],
|
||||||
|
});
|
||||||
|
} else if (message?.author.id === botId && message?.components.length < 1) {
|
||||||
|
await message.delete();
|
||||||
|
await roles.send({
|
||||||
|
content,
|
||||||
|
components: [button],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -28,6 +28,7 @@ const devIDs = {
|
|||||||
vegan: {
|
vegan: {
|
||||||
vegan: '999431675098447937',
|
vegan: '999431675098447937',
|
||||||
activist: '999431675098447934',
|
activist: '999431675098447934',
|
||||||
|
nvAccess: '1076859125415301141',
|
||||||
plus: '999431675010359460',
|
plus: '999431675010359460',
|
||||||
},
|
},
|
||||||
restrictions: {
|
restrictions: {
|
||||||
|
@ -31,6 +31,7 @@ let IDs = {
|
|||||||
vegan: {
|
vegan: {
|
||||||
vegan: '788114978020392982',
|
vegan: '788114978020392982',
|
||||||
activist: '730915638746546257',
|
activist: '730915638746546257',
|
||||||
|
nvAccess: '1076857105648209971',
|
||||||
plus: '798682625619132428',
|
plus: '798682625619132428',
|
||||||
},
|
},
|
||||||
restrictions: {
|
restrictions: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user