-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New channel permissions helper (#293)
### Notes This commit adds a new `channel-management` helper to Valkyrie which will always ensure permissions on new channels within the `defense` category are assigned to the same permission set as the base channel category permissions. It then sends a message to the newly created channel, listing the permissions and access levels they have for quick verification on channel permissions. If the channel is created with different permissions than base category, it will be overwritten by the permissions on base category. However, permissions can also be altered after creation if needed manually.
- Loading branch information
Showing
2 changed files
with
33 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Client, TextChannel } from "discord.js" | ||
import { Robot } from "hubot" | ||
|
||
export default async function manageChannelPermissions( | ||
discordClient: Client, | ||
robot: Robot, | ||
) { | ||
const { application } = discordClient | ||
if (process.env.DEFENSE_CATEGORY_ID) { | ||
if (application) { | ||
discordClient.on("channelCreate", async (channel) => { | ||
if ( | ||
channel.parent && | ||
channel.parentId === process.env.DEFENSE_CATEGORY_ID | ||
) { | ||
const permissions = channel.parent.permissionOverwrites.cache | ||
await channel.permissionOverwrites.set(permissions) | ||
robot.logger.info("Channel permissions set to base category") | ||
if (channel instanceof TextChannel) { | ||
await channel.send( | ||
"This channel now has the same base permissions as the Defense category.", | ||
) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
} |
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