diff --git a/prisma/migrations/20240213210346_outreach_vc/migration.sql b/prisma/migrations/20240213210346_outreach_vc/migration.sql new file mode 100644 index 0000000..83aa921 --- /dev/null +++ b/prisma/migrations/20240213210346_outreach_vc/migration.sql @@ -0,0 +1,8 @@ +/* + Warnings: + + - Added the required column `channelId` to the `StatRole` table without a default value. This is not possible if the table is not empty. + +*/ +-- AlterTable +ALTER TABLE "StatRole" ADD COLUMN "channelId" TEXT NOT NULL; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 0e165c4..c8afe05 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -222,9 +222,10 @@ model Stat { } model StatRole { - stat Stat @relation(fields: [statId], references: [id]) - statId Int @id - roleId String + stat Stat @relation(fields: [statId], references: [id]) + statId Int @id + roleId String + channelId String } model ParticipantStat { diff --git a/src/commands/outreach/outreach.ts b/src/commands/outreach/outreach.ts index d32d142..7829006 100644 --- a/src/commands/outreach/outreach.ts +++ b/src/commands/outreach/outreach.ts @@ -19,7 +19,7 @@ import { Subcommand } from '@sapphire/plugin-subcommands'; import { RegisterBehavior } from '@sapphire/framework'; -import type { Snowflake } from 'discord.js'; +import { ChannelType, PermissionsBitField, Snowflake } from 'discord.js'; import { updateUser } from '#utils/database/dbExistingUser'; import { addStatUser, @@ -207,7 +207,7 @@ export class OutreachCommand extends Subcommand { if (!mod.roles.cache.has(IDs.roles.staff.outreachLeader)) { await interaction.reply({ - content: 'You need to be an Outreach Coordinator to run this command!', + content: 'You need to be an Outreach Leader to run this command!', ephemeral: true, }); return; @@ -274,7 +274,8 @@ export class OutreachCommand extends Subcommand { stat.forEach(({ role }) => { if (role !== null) { - guild.roles.delete(role.roleId); + guild.roles.delete(role.roleId); // Delete role + guild.channels.delete(role.channelId); // Delete VC } }); @@ -387,14 +388,66 @@ export class OutreachCommand extends Subcommand { await updateUser(leaderMember); + // Create role for group const role = await guild.roles.create({ name: `Outreach Group ${groupNo}`, + mentionable: true, }); - await createStat(event.id, leader.id, role.id); + // Create a voice channel for group + const channel = await guild.channels.create({ + name: `Outreach Group ${groupNo}`, + type: ChannelType.GuildVoice, + parent: IDs.categories.activism, + permissionOverwrites: [ + { + id: guild.roles.everyone, + deny: [ + PermissionsBitField.Flags.SendMessages, + PermissionsBitField.Flags.Connect, + PermissionsBitField.Flags.ViewChannel, + ], + }, + { + id: IDs.roles.vegan.activist, + allow: [PermissionsBitField.Flags.ViewChannel], + }, + { + id: role.id, // Permissions for the specific group + allow: [ + PermissionsBitField.Flags.SendMessages, + PermissionsBitField.Flags.Connect, + ], + }, + { + id: IDs.roles.staff.outreachLeader, + allow: [ + PermissionsBitField.Flags.SendMessages, + PermissionsBitField.Flags.Connect, + ], + }, + ], + }); + // Create stats in database + await createStat(event.id, leader.id, role.id, channel.id); + + // Give group leader role await leaderMember.roles.add(role); + // Send message in VC with a welcome and reminder + await channel.send( + `Welcome ${role}, ${leaderMember} is going to be the leader of your group!\n\n` + + 'Remember to keep track of stats during activism with `/outreach group update` and' + + 'to have these questions in mind whilst doing activism:\n' + + '- How many said would go vegan?\n' + + '- How many seriously considered being vegan?\n' + + '- How many people had anti-vegan viewpoints?\n' + + '- How many thanked you for the conversation?\n' + + '- How many said they would watch a vegan documentary?\n' + + '- How many got educated on veganism or the animal industry?', + ); + await interaction.editReply({ content: `Created a group with the leader being ${leader}`, }); diff --git a/src/utils/database/outreach.ts b/src/utils/database/outreach.ts index 4708dc8..ded994e 100644 --- a/src/utils/database/outreach.ts +++ b/src/utils/database/outreach.ts @@ -85,6 +85,7 @@ export async function createStat( eventId: number, leaderId: Snowflake, roleId: Snowflake, + channelId: Snowflake, ) { await container.database.stat.create({ data: { @@ -110,6 +111,7 @@ export async function createStat( role: { create: { roleId, + channelId, }, }, }, diff --git a/src/utils/devIDs.ts b/src/utils/devIDs.ts index 087eb24..0eeec1f 100644 --- a/src/utils/devIDs.ts +++ b/src/utils/devIDs.ts @@ -133,6 +133,7 @@ const devIDs = { staff: '999431676058927253', modMail: '1095453371411996762', verification: '999431677006860409', + activism: '999431677795389549', diversity: '999431679053660185', private: '999431679527628818', restricted: '999431679812845654', diff --git a/src/utils/ids.ts b/src/utils/ids.ts index 456e13a..68002dd 100644 --- a/src/utils/ids.ts +++ b/src/utils/ids.ts @@ -135,6 +135,7 @@ let IDs = { staff: '768685283583328257', modMail: '867077297664426006', verification: '797505409073676299', + activism: '873918877019545640', diversity: '933078380394459146', private: '992581296901599302', restricted: '809765577236283472',