-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from Assaro/dev
Feature Update 1.0.0
- Loading branch information
Showing
22 changed files
with
1,179 additions
and
98 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
# **Command Overview** | ||
|
||
### /admin | ||
- choose a user to grant or revoke admin privilieges to | ||
- Can only be done by admins | ||
- An admin can not revoke his own admin privileges | ||
|
||
### /docker | ||
- used to start, stop or restart a docker container | ||
- admins are allowed to control every container | ||
- users can only start and stop containers that have been assigned to them by admins | ||
- start and stop permissions are granted separately | ||
- permissions can be done per user and for roles | ||
|
||
### /list | ||
- this command lists all containers the user is allowed to interact with | ||
- includes the status (running or stopped) | ||
- admins see every container | ||
|
||
### /permission | ||
- lists a users permissions | ||
- admins can enter a user or role for permissions to be shown | ||
|
||
### /role | ||
- used to grant/revoke permissions to a role | ||
|
||
### /role | ||
- used to grant/ revoke permissions to a single user |
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,27 +1,31 @@ | ||
<h1 align="center">FAQ</h1> | ||
<p align="center">If you are here, I probably did something wrong</p> | ||
|
||
## I updated the Bot and my commands are not working anymore | ||
- The 1.0.0 update introduced a new permission system | ||
- Either revert back to version 0.1.0 or adapt to the new system | ||
- Info about the new settings has been added to the [settings readme](sites/../settings.md) | ||
|
||
## I just installed your Bot but i do not have admin rights | ||
-You need to add your Discord ID to the settings.json. For more info about settings click [here](sites/../settings.md) | ||
|
||
## The Bot does not go online in Discord | ||
|
||
- Token is not valid | ||
- Check if you entered your token correctly in the settings.json | ||
- Restart the Container for Changes to take effect | ||
- If that did not work, regenerate the Token on Discord's Developer Portal | ||
|
||
## The Container crashes | ||
|
||
- Check if the Container generated a settings.json | ||
- If it exists, check your settings | ||
- If it doesn't exist, make sure that you have a folder pointing to /app/settings | ||
- Check if /var/run/docker.sock exists on your machine. Eventually adjust path to docker.sock if it has been relocated | ||
|
||
## I updated to a newer image and now it crashes | ||
- I probably added new settings. | ||
- Back up your settings.json and let the Container generate a new one | ||
- This will be changed at some point, sorry for the Inconvenience | ||
- Check if `/var/run/docker.sock` exists on your machine. Adjust path to `docker.sock` | ||
|
||
## I get ``` Unhandled exception. Discord.Net.HttpException: The server responded with error 50035: Invalid Form Body ``` when using the /list command | ||
- Too many characters in your list. Lower the `ContainersPerMessage` setting value until it works again | ||
|
||
## How can i contact you | ||
## How can i contact you? | ||
- [Github Issue](https://github.com/Assaro/DD_Bot/issues/new) | ||
- [Discord](https://discord.com/users/341195755677286401) (Assaro Delamar#5823) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* DD_Bot - A Discord Bot to control Docker containers*/ | ||
|
||
/* Copyright (C) 2022 Maxim Kovac | ||
This program is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
using System; | ||
using Discord; | ||
using Discord.WebSocket; | ||
using DD_Bot.Application.Services; | ||
using System.Linq; | ||
using DD_Bot.Domain; | ||
|
||
namespace DD_Bot.Application.Commands | ||
{ | ||
public class AdminCommand | ||
{ | ||
private DiscordSocketClient _discord; | ||
|
||
public AdminCommand(DiscordSocketClient discord) | ||
{ | ||
_discord = discord; | ||
} | ||
|
||
#region CreateCommand | ||
|
||
public static ApplicationCommandProperties Create() | ||
{ | ||
var builder = new SlashCommandBuilder() | ||
{ | ||
Name = "admin", | ||
Description = "Grant or Revoke Admin Privileges" | ||
}; | ||
|
||
builder.AddOption("user", | ||
ApplicationCommandOptionType.User, | ||
"choose a user", | ||
isRequired: true | ||
); | ||
|
||
builder.AddOption("choice", | ||
ApplicationCommandOptionType.String, | ||
"choose grant or revoke", | ||
true, | ||
choices: new[] | ||
{ | ||
new ApplicationCommandOptionChoiceProperties() | ||
{ | ||
Name = "grant", | ||
Value = "grant", | ||
}, | ||
new ApplicationCommandOptionChoiceProperties() | ||
{ | ||
Name = "revoke", | ||
Value = "revoke", | ||
} | ||
}); | ||
|
||
return builder.Build(); | ||
} | ||
|
||
#endregion | ||
|
||
#region ExecuteCommand | ||
|
||
public static async void Execute(SocketSlashCommand arg, Settings settings, SettingsService settingsService) | ||
{ | ||
await arg.RespondAsync("Contacting Settings Service..."); | ||
DiscordSettings discordSettings = settings.DiscordSettings; | ||
if (!discordSettings.AdminIDs.Contains(arg.User.Id)) | ||
{ | ||
await arg.ModifyOriginalResponseAsync(edit => edit.Content = "You are not an Admin!"); | ||
} | ||
else | ||
{ | ||
var choice = arg.Data.Options.FirstOrDefault(option => option.Name == "choice")?.Value as string; | ||
var user = arg.Data.Options.FirstOrDefault(option => option.Name == "user")?.Value as SocketGuildUser; | ||
switch (choice) | ||
{ | ||
case "grant": | ||
Console.WriteLine("grant"); | ||
if (discordSettings.AdminIDs.Contains(user.Id)) | ||
{ | ||
await arg.ModifyOriginalResponseAsync(edit => edit.Content = user.Username + " is already an admin!"); | ||
} | ||
else | ||
{ | ||
settings.DiscordSettings.AdminIDs.Add(user.Id); | ||
settingsService.WriteSettings(settings); | ||
await arg.ModifyOriginalResponseAsync(edit => edit.Content = "Made " + user.Username + " an admin!"); | ||
} | ||
break; | ||
case "revoke": | ||
if (user.Id == arg.User.Id) | ||
{ | ||
await arg.ModifyOriginalResponseAsync(edit => edit.Content = "You are not allowed to revoke your own admin privileges!"); | ||
}else if (!discordSettings.AdminIDs.Contains(user.Id)) | ||
{ | ||
await arg.ModifyOriginalResponseAsync(edit => edit.Content = "User is not an admin!"); | ||
} | ||
else | ||
{ | ||
settings.DiscordSettings.AdminIDs.Remove(user.Id); | ||
settingsService.WriteSettings(settings); | ||
await arg.ModifyOriginalResponseAsync(edit => edit.Content = user.Username + "'s admin privileges have been removed!"); | ||
} | ||
break; | ||
} | ||
} | ||
} | ||
|
||
#endregion | ||
} | ||
} |
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
Oops, something went wrong.