-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d334071
commit e03839a
Showing
8 changed files
with
100 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,72 @@ | ||
|
||
const emojis = require("../utils/emojis") | ||
const emojis = require("../utils/emojis"); | ||
/** | ||
* @param {{app: import('@slack/bolt').App}} param1 | ||
*/ | ||
module.exports = async function ({ app }) { | ||
const { PrismaClient } = require("@prisma/client"); | ||
const prisma = new PrismaClient(); | ||
app.command("/setemoji", async ({ command, body, ack, respond }) => { | ||
await prisma.$connect() | ||
await ack(); | ||
if (!command.text) | ||
return await respond( | ||
"Please provide an emoji. I.e. /setemoji 🎒 or /setemoji :hackclub:", | ||
); | ||
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, | ||
}); | ||
if (command.user_id != channel.channel.creator && !user.user.is_admin) | ||
return await respond( | ||
"Only channel managers and workspace admins can opt .", | ||
); | ||
const channelRecord = await prisma.channel.findFirst({ | ||
where: { | ||
id: channelId, | ||
}, | ||
}); | ||
if (!command.text && !command.text.match(/:[a-zA-Z0-9_-]+:/) && !emojis.includes(command.text)) | ||
return await respond("Please provide an emoji") | ||
|
||
|
||
if (!channel.channel.is_member) | ||
try { | ||
await app.client.conversations.join({ | ||
channel: channel.channel.id, | ||
}); | ||
} catch (e) { } | ||
if (!channelRecord) | ||
await prisma.channel.create({ | ||
data: { | ||
id: channelId, | ||
emoji: command.text | ||
}, | ||
}); | ||
else if (channelRecord.locked && !user.user.is_admin) | ||
return await respond( | ||
"This channel cannot be locked as it is locked in the database. Usually, this is because it is a public, community-owned channel, i.e. #lounge, #code, etc.", | ||
); | ||
const { PrismaClient } = require("@prisma/client"); | ||
const prisma = new PrismaClient(); | ||
app.command("/setemoji", async ({ command, body, ack, respond }) => { | ||
await prisma.$connect(); | ||
await ack(); | ||
if (!command.text) | ||
return await respond( | ||
"Please provide an emoji. I.e. /setemoji 🎒 or /setemoji :hackclub:", | ||
); | ||
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, | ||
}); | ||
if (command.user_id != channel.channel.creator && !user.user.is_admin) | ||
return await respond( | ||
"Only channel managers and workspace admins can opt .", | ||
); | ||
const channelRecord = await prisma.channel.findFirst({ | ||
where: { | ||
id: channelId, | ||
}, | ||
}); | ||
if ( | ||
!command.text && | ||
!command.text.match(/:[a-zA-Z0-9_-]+:/) && | ||
!emojis.includes(command.text) | ||
) | ||
return await respond("Please provide an emoji"); | ||
|
||
await prisma.channel.update({ | ||
where: { | ||
id: channelId, | ||
}, | ||
data: { | ||
optout: false, | ||
emoji: command.text | ||
}, | ||
if (!channel.channel.is_member) | ||
try { | ||
await app.client.conversations.join({ | ||
channel: channel.channel.id, | ||
}); | ||
await app.client.chat.postEphemeral({ | ||
channel: channel.channel.id, | ||
user: command.user_id, | ||
text: `Set your channel emoji to ${command.text}`, | ||
}); | ||
await prisma.$disconnect() | ||
} catch (e) {} | ||
if (!channelRecord) | ||
await prisma.channel.create({ | ||
data: { | ||
id: channelId, | ||
emoji: command.text, | ||
}, | ||
}); | ||
else if (channelRecord.locked && !user.user.is_admin) | ||
return await respond( | ||
"This channel cannot be locked as it is locked in the database. Usually, this is because it is a public, community-owned channel, i.e. #lounge, #code, etc.", | ||
); | ||
|
||
await prisma.channel.update({ | ||
where: { | ||
id: channelId, | ||
}, | ||
data: { | ||
optout: false, | ||
emoji: command.text, | ||
}, | ||
}); | ||
await app.client.chat.postEphemeral({ | ||
channel: channel.channel.id, | ||
user: command.user_id, | ||
text: `Set your channel emoji to ${command.text}`, | ||
}); | ||
await prisma.$disconnect(); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters