Skip to content

Commit

Permalink
allow channels to be marked as personal
Browse files Browse the repository at this point in the history
  • Loading branch information
dispherical committed Oct 19, 2024
1 parent e1245a0 commit d79b1ff
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
66 changes: 66 additions & 0 deletions commands/setpersonal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const getChannelManagers = require("../utils/channelManagers");

/**
* @param {{app: import('@slack/bolt').App}} param1
*/
module.exports = async function ({ app, prisma }) {
app.command("/setpersonal", async ({ command, body, ack, respond }) => {
await ack();
const channelId = body.channel_id;
const channel = await app.client.conversations.info({
channel: body.channel_id,
});
const user = await app.client.users.info({
user: command.user_id,
});
const channelManagers = await getChannelManagers(body.channel_id);
if (!channelManagers.includes(command.user_id) && !user.user.is_admin)
return await respond(
"Only channel managers and workspace admins can mark a channel as personal",
);
const channelRecord = await prisma.channel.findFirst({
where: {
id: channelId,
},
});
if (!channelRecord)
await prisma.channel.create({
data: {
id: channelId,
personal: true,
},
});
else if (channelRecord.locked && !user.user.is_admin)
return await respond(
"This channel cannot be modified as it is locked in the database. Usually, this is because it is a public, community-owned channel, i.e. #lounge, #code, etc.",
);
else if (channelRecord.personal) {
await prisma.channel.update({
where: {
id: channelId,
},
data: {
personal: false,
},
});
return await respond(
"Your channel has been marked as personal. Run the command again to unmark it.",
);
}

else
await prisma.channel.update({
where: {
id: channelId,
},
data: {
personal: true
},
});
await app.client.chat.postEphemeral({
channel: channel.channel.id,
user: command.user_id,
text: "This channel has been marked as regular. Run this command again to mark it as personal.",
});
});
};
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ Array.prototype.random = function () {
await require("./commands/setuserlocation")({ app, client, prisma });
await require("./commands/setemoji")({ app, client, prisma });
await require("./commands/setfeatured")({ app, client, prisma });
await require("./commands/setpersonal")({ app, client, prisma });



// This deletes and sends a new message to bypass the 10 day editing limit and to show up on the user's unread channel list
Expand Down
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ model Channel {
emoji String?
featured Boolean? @default(false)
description String?
personal Boolean @default(false)
}

model User {
Expand Down

0 comments on commit d79b1ff

Please sign in to comment.