Discord Administrator Role Permissions (#54)
* add: admin check for disable * update: shutoff uses memberPerms now * rm: superUser env variable * update: version increment * rm: admin env in docker and workflow
This commit is contained in:
@@ -22,6 +22,3 @@ DISCORD_IP = IP_ADDRESS
|
||||
|
||||
# subnet address, ex. 172.18.0.0 as we use /16.
|
||||
SUBNET_ADDRESS = ADDRESS
|
||||
|
||||
# list of admins to handle admin commands for the bot, use single quotes
|
||||
ADMINS=['username1', 'username2', 'username3', ...]
|
||||
2
.github/workflows/build-test.yml
vendored
2
.github/workflows/build-test.yml
vendored
@@ -37,7 +37,6 @@ jobs:
|
||||
echo CLIENT_UID = ${{ secrets.CLIENT_UID }} >> .env
|
||||
echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env
|
||||
echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env
|
||||
echo ADMINS = ${{ secrets.ADMINS }} >> .env
|
||||
|
||||
# set -e ensures if nohup fails, this section fails
|
||||
- name: Startup Discord Bot Client
|
||||
@@ -68,7 +67,6 @@ jobs:
|
||||
echo CLIENT_UID = ${{ secrets.CLIENT_UID }} >> .env
|
||||
echo OLLAMA_IP = ${{ secrets.OLLAMA_IP }} >> .env
|
||||
echo OLLAMA_PORT = ${{ secrets.OLLAMA_PORT }} >> .env
|
||||
echo ADMINS = ${{ secrets.ADMINS }} >> .env
|
||||
|
||||
- name: Setup Docker Network and Images
|
||||
run: |
|
||||
|
||||
@@ -8,7 +8,7 @@ services:
|
||||
build: ./ # find docker file in designated path
|
||||
container_name: discord
|
||||
restart: always # rebuild container always
|
||||
image: discord/bot:0.4.2
|
||||
image: discord/bot:0.4.3
|
||||
environment:
|
||||
CLIENT_TOKEN: ${CLIENT_TOKEN}
|
||||
GUILD_ID: ${GUILD_ID}
|
||||
@@ -17,7 +17,6 @@ services:
|
||||
CLIENT_UID: ${CLIENT_UID}
|
||||
OLLAMA_IP: ${OLLAMA_IP}
|
||||
OLLAMA_PORT: ${OLLAMA_PORT}
|
||||
ADMINS: ${ADMINS}
|
||||
networks:
|
||||
ollama-net:
|
||||
ipv4_address: ${DISCORD_IP}
|
||||
|
||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "discord-ollama",
|
||||
"version": "0.4.0",
|
||||
"version": "0.4.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "discord-ollama",
|
||||
"version": "0.4.0",
|
||||
"version": "0.4.3",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"discord.js": "^14.14.1",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "discord-ollama",
|
||||
"version": "0.4.2",
|
||||
"version": "0.4.3",
|
||||
"description": "Ollama Integration into discord",
|
||||
"main": "build/index.js",
|
||||
"exports": "./build/index.js",
|
||||
|
||||
@@ -4,7 +4,7 @@ import { openFile } from '../utils/jsonHandler.js'
|
||||
|
||||
export const Disable: SlashCommand = {
|
||||
name: 'toggle-chat',
|
||||
description: 'toggle all chat features, slash commands will still work.',
|
||||
description: 'toggle all chat features, Adminstrator Only.',
|
||||
|
||||
// set available user options to pass to the command
|
||||
options: [
|
||||
@@ -22,6 +22,15 @@ export const Disable: SlashCommand = {
|
||||
const channel = await client.channels.fetch(interaction.channelId)
|
||||
if (!channel || channel.type !== ChannelType.GuildText) return
|
||||
|
||||
// check if runner is an admin
|
||||
if (!interaction.memberPermissions?.has('Administrator')) {
|
||||
interaction.reply({
|
||||
content: `${interaction.commandName} is an Administrator Command.\n\nYou, ${interaction.member?.user.username}, are not an Administrator in this server.\nPlease contact an admin to use this command.`,
|
||||
ephemeral: true
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// set state of bot chat features
|
||||
openFile('config.json', interaction.commandName, interaction.options.get('enabled')?.value)
|
||||
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { ChannelType, Client, CommandInteraction, ApplicationCommandOptionType } from 'discord.js'
|
||||
import { SlashCommand } from '../utils/commands.js'
|
||||
import Keys from '../keys.js'
|
||||
|
||||
export const Shutoff: SlashCommand = {
|
||||
name: 'shutoff',
|
||||
description: 'shutdown the bot. You will need to manually bring it online again.',
|
||||
description: 'shutdown the bot. You will need to manually bring it online again. Administrator Only.',
|
||||
|
||||
// set available user options to pass to the command
|
||||
options: [
|
||||
@@ -25,24 +24,22 @@ export const Shutoff: SlashCommand = {
|
||||
// log this, this will probably be improtant for logging who did this
|
||||
console.log(`User -> ${interaction.user.tag} attempting to shutdown ${client.user!!.tag}`)
|
||||
|
||||
// create list of superUsers based on string parse
|
||||
const superUsers: string[] = JSON.parse(Keys.superUser.replace(/'/g, '"'))
|
||||
|
||||
// check if admin or false on shutdown
|
||||
if (interaction.user.tag !in superUsers) {
|
||||
if (!interaction.memberPermissions?.has('Administrator')) {
|
||||
interaction.reply({
|
||||
content: `Shutdown failed:\n\n${interaction.user.tag}, You do not have permission to shutoff **${client.user?.tag}**.`,
|
||||
content: `**Shutdown Aborted:**\n\n${interaction.user.tag}, You do not have permission to shutoff **${client.user?.tag}**.`,
|
||||
ephemeral: true
|
||||
})
|
||||
return // stop from shutting down
|
||||
} else if (!interaction.options.get('are-you-sure')?.value) {
|
||||
interaction.reply({
|
||||
content: `Shutdown failed:\n\n${interaction.user.tag}, You didn't want to shutoff **${client.user?.tag}**.`,
|
||||
content: `**Shutdown Aborted:**\n\n${interaction.user.tag}, You didn't want to shutoff **${client.user?.tag}**.`,
|
||||
ephemeral: true
|
||||
})
|
||||
return
|
||||
return // chickened out
|
||||
}
|
||||
|
||||
// Shutoff cleared, do it
|
||||
interaction.reply({
|
||||
content: `${client.user?.tag} is ${interaction.options.get('are-you-sure')?.value ? "shutting down now." : "not shutting down." }`,
|
||||
ephemeral: true
|
||||
|
||||
@@ -8,7 +8,6 @@ export const Keys = {
|
||||
guildId: getEnvVar('GUILD_ID'),
|
||||
ipAddress: getEnvVar('OLLAMA_IP'),
|
||||
portAddress: getEnvVar('OLLAMA_PORT'),
|
||||
superUser: getEnvVar('ADMINS')
|
||||
} as const // readonly keys
|
||||
|
||||
export default Keys
|
||||
Reference in New Issue
Block a user