C#:
using Facepunch.Extend;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Oxide.Core;
using Oxide.Core.Libraries.Covalence;
using Oxide.Core.Plugins;
using Oxide.Ext.Discord;
using Oxide.Ext.Discord.Attributes;
using Oxide.Ext.Discord.Builders;
using Oxide.Ext.Discord.Builders.MessageComponents;
using Oxide.Ext.Discord.Constants;
using Oxide.Ext.Discord.Entities;
using Oxide.Ext.Discord.Entities.Channels;
using Oxide.Ext.Discord.Entities.Emojis;
using Oxide.Ext.Discord.Entities.Gatway;
using Oxide.Ext.Discord.Entities.Gatway.Events;
using Oxide.Ext.Discord.Entities.Guilds;
using Oxide.Ext.Discord.Entities.Interactions;
using Oxide.Ext.Discord.Entities.Interactions.MessageComponents;
using Oxide.Ext.Discord.Entities.Messages;
using Oxide.Ext.Discord.Entities.Messages.Embeds;
using Oxide.Ext.Discord.Entities.Permissions;
using Oxide.Ext.Discord.Entities.Users;
using Oxide.Ext.Discord.Libraries.Command;
using Oxide.Ext.Discord.Libraries.Linking;
using Oxide.Ext.Discord.Logging;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using UnityEngine;
namespace Oxide.Plugins {
[Info("Discord Server Panel", "Aimon", "1.0.3")]
[Description("Adds server control commands to your discord bot.")]
public class DiscordServerPanel : CovalencePlugin {
#region Classes
public string consolelog = "";
public class PlayerConsole : IPlayer {
public object Object {
set;
get;
}
public CommandType LastCommand {
set;
get;
}
= CommandType.Console;
public string Name {
set;
get;
}
= "Server Console";
public string Id {
set;
get;
}
= "server_console";
public string Address {
set;
get;
}
= "server_console";
public int Ping {
set;
get;
}
= -1;
public CultureInfo Language {
set;
get;
}
= null;
public bool IsConnected {
set;
get;
}
= false;
public bool IsSleeping {
set;
get;
}
= true;
public bool IsServer {
set;
get;
}
= true;
public bool IsAdmin {
set;
get;
}
= true;
public bool IsBanned {
set;
get;
}
= false;
public TimeSpan BanTimeRemaining {
set;
get;
}
= new TimeSpan(0, 0, 0);
public float Health {
set;
get;
}
= 0;
public float MaxHealth {
set;
get;
}
= 100;
public void AddToGroup(string group) {
}
public void Ban(string reason, TimeSpan duration = default(TimeSpan)) {
}
public bool BelongsToGroup(string group) {
return false;
}
public void Command(string command, params object[] args) {
}
public void GrantPermission(string perm) {
}
public bool HasPermission(string perm) {
return true;
}
public void Heal(float amount) {
}
public void Hurt(float amount) {
}
public void Kick(string reason) {
}
public void Kill() {
}
public void Message(string message, string prefix, params object[] args) {
}
public void Message(string message) {
}
public void Position(out float x, out float y, out float z) {
x = 0;
y = 0;
z = 0;
}
public GenericPosition Position() {
return new GenericPosition(0, 0, 0);
}
public void RemoveFromGroup(string group) {
}
public void Rename(string name) {
}
public void Reply(string message, string prefix, params object[] args) {
;
}
public void Reply(string message) {
}
public void RevokePermission(string perm) {
}
public void Teleport(float x, float y, float z) {
}
public void Teleport(GenericPosition pos) {
}
public void Unban() {
}
}
public class LinkMessageData {
public Snowflake ChannelId {
get;
set;
}
public Snowflake MessageId {
get;
set;
}
}
#endregion Classes
#region Global Variables
[PluginReference]
private readonly Plugin DiscordAuth, DiscordCore, WipeInfoApi, Economics, TimedPermissions, EnhancedBanSystem, ServerArmour, BetterChatMute, Clans;
[DiscordClient]
private readonly DiscordClient _client;
private bool connected = true;
private DiscordGuild _guild;
private DiscordRole _role;
private DiscordRole _rolec;
private DiscordRole _roleperm;
private DiscordRole _rolep;
private DiscordRole _roler;
private readonly DiscordLink _link = GetLibrary<DiscordLink>();
private readonly DiscordCommand _dcCommands = Interface.Oxide.GetLibrary<DiscordCommand>();
public List<PluginInfo> DisabledPlugins = new List<PluginInfo>();
private const string PluginsButtonIcon = "🔵";
private const string PermissionsButtonIcon = "👀";
private const string RestartButtonIcon = "🔁";
private const string MapVoterButtonIcon = "🌍";
private const string SkipNightButtonIcon = "💤";
private const string CustomButtonIcon = "🔨";
public class PluginInfo {
public PluginInfo(string name, string title) {
Name = name;
Title = title;
}
public string Name {
get;
set;
}
public string Title {
get;
set;
}
}
#endregion Global Variables
#region Configuration
private ConfigData _configData;
private class ConfigData {
public string LogFileName = "DiscordServerPanel";
[JsonProperty(PropertyName = "Bot token")]
public string Token = "";
[JsonProperty(PropertyName = "Discord Guild ID (optional if the bot is in one guild)")]
public Snowflake GuildId {
get;
set;
}
[JsonProperty(PropertyName = "Discord Role ID")]
public Snowflake RoleId {
get;
set;
}
[JsonProperty(PropertyName = "Discord Channel ID where the command can be used")]
public Snowflake ChannelID {
get;
set;
}
[JsonProperty(PropertyName = "Embed's color")]
public string Color = "#ff0000";
[JsonProperty(PropertyName = "Show Server FPS (Server command)")]
public bool showfps = true;
[JsonProperty(PropertyName = "Show Gamemode (Server command)")]
public bool showgamemode = true;
[JsonProperty(PropertyName = "Show Plugins Loaded (Server command)")]
public bool showplugins = true;
[JsonProperty(PropertyName = "Custom")]
public Custom CUSTOM = new Custom();
[JsonProperty(PropertyName = "Restart")]
public Restart RESTART = new Restart();
[JsonProperty(PropertyName = "Plugins")]
public Plugins PLUGINS = new Plugins();
[JsonProperty(PropertyName = "Permissions")]
public Perm PERM = new Perm();
public class Restart {
[JsonProperty(PropertyName = "Use Restart (true/false)")]
public bool restartuse = true;
[JsonProperty(PropertyName = "Discord Role ID (Can be left empty to use the first role id)")]
public Snowflake RoleId {
get;
set;
}
[JsonProperty(PropertyName = "Restart Reasons (One Word)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public string[] RestartReasons = new string[] {
"Maintenance", "Update", "Wipe", "None"
}
;
[JsonProperty(PropertyName = "Time for command (Use 'h' for hours, 'm' for minutes)", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public string[] timerestart = new string[] {
"5m", "10m", "30m", "1h"
}
;
}
public class Perm {
[JsonProperty(PropertyName = "Use Permissions (true/false)")]
public bool permuse = true;
[JsonProperty(PropertyName = "Discord Role ID (Can be left empty to use the first role id)")]
public Snowflake RoleId {
get;
set;
}
}
public class Plugins {
[JsonProperty(PropertyName = "Use Plugins (true/false)")]
public bool pluginsuse = true;
[JsonProperty(PropertyName = "Discord Role ID (Can be left empty to use the first role id)")]
public Snowflake RoleId {
get;
set;
}
[JsonProperty(PropertyName = "Use Confirmation (true/false)")]
public bool confirmuse = true;
}
public class Custom {
[JsonProperty(PropertyName = "Use Custom (true/false)")]
public bool customuse = false;
[JsonProperty(PropertyName = "Use Confirmation (true/false)")]
public bool confirmuse = false;
[JsonProperty(PropertyName = "Discord Role ID (Can be left empty to use the first role id)")]
public Snowflake RoleId {
get;
set;
}
[JsonProperty(PropertyName = "Custom Commands ('command name' 'command to send on console')", ObjectCreationHandling = ObjectCreationHandling.Replace)]
public Dictionary<string, string> Commands = new Dictionary<string, string> {
{
"Restart", "restart 300 Maintenance"
}
, {
"SkipNight", "env.time 12"
}
}
;
}
public Logs logs = new Logs();
public class Logs {
[JsonProperty(PropertyName = "Log to console (true/false)")]
public bool LogToConsole = true;
[JsonProperty(PropertyName = "Log to discord (true/false)")]
public bool LogToDiscord = false;
[JsonProperty(PropertyName = "Log Discord Channel ID")]
public Snowflake logChannelID {
get;
set;
}
[JsonConverter(typeof(StringEnumConverter))]
[JsonProperty(PropertyName = "Discord Extension Log Level (Verbose/Debug/Info/Warning/Error/Exception/Off)")]
public DiscordLogLevel ExtensionDebugging = DiscordLogLevel.Info;
[JsonProperty(PropertyName = "Delete message after command")]
public bool messagedelete = true;
[JsonProperty(PropertyName = "Delete message after interaction")]
public bool interactiondelete = true;
}
}
protected override void LoadConfig() {
try {
base.LoadConfig();
_configData = Config.ReadObject<ConfigData>();
SaveConfig(_configData);
}
catch (Exception) {
PrintError(Lang("ConfigIssue"));
return;
}
}
private void OnServerInitialized() {
if (string.IsNullOrEmpty(_configData.Token)) {
PrintError(Lang("NoToken"));
return;
}
RegisterCommands();
RegisterPerms();
}
protected override void LoadDefaultConfig() {
Puts(Lang("NewConfig"));
_configData = new ConfigData();
SaveConfig(_configData);
}
private void SaveConfig(ConfigData config) {
Config.WriteObject(config, true);
}
private void Loaded() {
UnityEngine.Application.logMessageReceived += ConsoleLog;
}
private void Unload() {
UnityEngine.Application.logMessageReceived -= ConsoleLog;
}
#endregion Configuration
#region Discord Bot Connection
[HookMethod(DiscordExtHooks.OnDiscordClientCreated)]
private void OnDiscordClientCreated() {
if (string.IsNullOrEmpty(_configData.Token) || _configData.Token == null || _configData.Token == "BotToken") {
PrintError("API key is empty or invalid!");
server.Command("o.unload DiscordServerPanel");
return;
}
try {
DiscordSettings settings = new DiscordSettings {
ApiToken = _configData.Token, Intents = GatewayIntents.Guilds | GatewayIntents.GuildMembers | GatewayIntents.GuildMessages | GatewayIntents.DirectMessages, LogLevel = _configData.logs.ExtensionDebugging
}
;
_client.Connect(settings);
}
catch (Exception e) {
connected = false;
PrintError($"DiscordAdminPanel failed to create client! Exception message: {e}");
}
}
private void GetGuild(GatewayReadyEvent ready) {
DiscordGuild guild = null;
if (!ready.Guilds.Values.Contains(ready.Guilds[_configData.GuildId])) {
guild = ready.Guilds.Values.FirstOrDefault();
}
if (guild == null) {
guild = ready.Guilds[_configData.GuildId];
}
if (guild == null) {
PrintError(Lang("InviteBot"));
_client.Disconnect();
server.Command("o.unload DiscordServerPanel");
return;
}
_guild = guild;
}
private void RegisterDiscordCommands() {
if (string.IsNullOrEmpty(_configData.ChannelID.ToString())) {
_dcCommands.AddGuildCommand("plugins", this, null, nameof(PluginList));
_dcCommands.AddGuildCommand("server", this, null, nameof(ServerCommand));
}
else {
_dcCommands.AddGuildCommand("plugins", this, new List<Snowflake> {
_configData.ChannelID
}
, nameof(PluginList));
_dcCommands.AddGuildCommand("server", this, new List<Snowflake> {
_configData.ChannelID
}
, nameof(ServerCommand));
}
}
[HookMethod(DiscordExtHooks.OnDiscordGatewayReady)]
private void OnDiscordGatewayReady(GatewayReadyEvent ready) {
if (ready.Guilds.Count == 0) {
PrintError(Lang("InviteBot"));
_client.Disconnect();
return;
}
GetGuild(ready);
RegisterDiscordCommands();
Puts(Lang("Connected"));
Puts($"Connected to bot: {_client.Bot.BotUser.Username}");
}
private void OnDiscordGuildMembersLoaded(DiscordGuild guild) {
if (string.IsNullOrEmpty(_configData.RoleId)) {
PrintWarning("Main Role ID Cannot be empty or Null");
server.Command("unload DiscordServerPanel");
}
foreach (DiscordRole role in guild.Roles.Values) {
if (role.Id == _configData.RoleId) {
_role = role;
}
if (!string.IsNullOrEmpty(_configData.CUSTOM.RoleId)) {
if (role.Id == _configData.CUSTOM.RoleId) {
_rolec = role;
}
}
if (!string.IsNullOrEmpty(_configData.PLUGINS.RoleId)) {
if (role.Id == _configData.PLUGINS.RoleId) {
_rolep = role;
}
}
if (!string.IsNullOrEmpty(_configData.RESTART.RoleId)) {
if (role.Id == _configData.RESTART.RoleId) {
_roler = role;
}
}
if (!string.IsNullOrEmpty(_configData.PERM.RoleId)) {
if (role.Id == _configData.PERM.RoleId) {
_roleperm = role;
}
}
}
if (_rolec == null) {
_rolec = _role;
}
if (_rolep == null) {
_rolep = _role;
}
if (_roler == null) {
_roler = _role;
}
if (_roleperm == null) {
_roleperm = _role;
}
if (_role == null) {
PrintError(Lang("RoleNotFound"));
_client.Disconnect();
server.Command("unload DiscordAdminPanel");
}
}
#endregion Discord Bot Connection
#region Commands
public void RegisterCommands() {
}
public void RegisterPerms() {
}
#endregion Commands
#region DiscordCommand
private void ServerCommand(DiscordMessage message, string cmd, string[] args) {
if (!message.Member.HasRole(_role) || message.Author.Bot == true) {
message.Reply(_client, CreateEmbed(Lang("NotAllowedTitle"), Lang("NotAllowedContent"), _configData.Color).Build());
return;
}
DiscordEmbedBuilder Embed = CreateEmbed("Server Command", "Choose a command:", _configData.Color);
Embed.AddField("Hostname:", $" {ConVar.Server.hostname}", true);
if (_configData.showfps) Embed.AddField("FPS:", $" {Performance.report.frameRate}", true);
Embed.AddField("Player Count:", $" {players.Connected.Count()} / {ConVar.Server.maxplayers}", true);
if (!(ConVar.Server.gamemode == "hardcore")) {
Embed.AddField("Map Seed:", $" {ConVar.Server.seed}", true);
}
string gamemode = string.IsNullOrEmpty(ConVar.Server.gamemode) ? "Vanilla" : ConVar.Server.gamemode;
if (_configData.showgamemode) Embed.AddField("Gamemode:", $" {gamemode}", true);
if (_configData.showplugins) Embed.AddField("Plugins Loaded:", $" {GetPlugins()}", true);
List<DiscordEmbed> embeds = new List<DiscordEmbed> {
Embed.Build()
}
;
MessageComponentBuilder builder = AddButtonsServer();
MessageCreate create = new MessageCreate {
Content = "Server Command", Embeds = embeds, Components = builder.Build()
}
;
DiscordChannel.GetChannel(_client, message.ChannelId, chan => {
chan.CreateMessage(_client, create);
}
);
//Log(_configData.LogFileName, "Server Command", message.Author.Username, (string)message.Author.Id);
message.DeleteMessage(_client);
}
private void PluginList(DiscordMessage message, string cmd, string[] args) {
if (!message.Member.HasRole(_role) || message.Author.Bot == true) {
message.Reply(_client, CreateEmbed(Lang("NotAllowedTitle"), Lang("NotAllowedContent"), _configData.Color).Build());
return;
}
var embed = CreateEmbed("Plugin List: ", $"Select Plugin Interaction to access plugins actions.\n You will find disabled plugins in the end of the list.", _configData.Color).Build();
List<DiscordEmbed> embeds = new List<DiscordEmbed> {
embed
}
;
MessageComponentBuilder builder = AddButtonsPluginlist();
MessageCreate create = new MessageCreate {
Content = "Plugin List Command", Embeds = embeds, Components = builder.Build()
}
;
DiscordChannel.GetChannel(_client, message.ChannelId, chan => {
chan.CreateMessage(_client, create);
}
);
Log(_configData.LogFileName, "Plugins Command", message.Author.Username, (string)message.Author.Id);
message.DeleteMessage(_client);
}
#endregion DiscordCommand
#region ProcessInteraction
private void ProcessRestartCommand(DiscordUser author, string[] args, DiscordInteraction interaction) {
GuildMember member = _guild.Members[author.Id];
if (member == null) {
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.ChannelMessageWithSource, Data = new InteractionCallbackData {
Content = "Restart Command!", Embeds = new List<DiscordEmbed> {
CreateEmbed("Who sent the command?", "Not a valid Guild Member", _configData.Color).Build()
}
, Flags = MessageFlags.Ephemeral
}
}
);
return;
}
if (!member.HasRole(_roler) || author.Bot == true) {
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.ChannelMessageWithSource, Data = new InteractionCallbackData {
Content = "Restart Command!", Embeds = new List<DiscordEmbed> {
CreateEmbed(Lang("NotAllowedTitle"), Lang("NotAllowedContent"), _configData.Color).Build()
}
, Flags = MessageFlags.Ephemeral
}
}
);
return;
}
if (args.Length == 4) {
if ((args[1] == "1") || (args[1] == "-1")) server.Command($"restart {args[1]} {args[2]}");
else server.Command($"restart {ToSeconds(args[1])} {args[2]}");
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.ChannelMessageWithSource, Data = new InteractionCallbackData {
Content = $"**Restart Command Sent Successfully!**\nReturned {consolelog}", Flags = MessageFlags.Ephemeral
}
}
);
Log(_configData.LogFileName, "Restart Command", interaction.Member.User.Username, (string)interaction.Member.User.Id, args[1], args[2]);
return;
}
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.UpdateMessage,
}
);
MessageComponentBuilder builder = new MessageComponentBuilder();
var embed = CreateEmbed("Restart Notice: ", null, _configData.Color);
List<DiscordEmbed> embeds = new List<DiscordEmbed>();
if (args.Length == 1) {
embed.AddDescription("Choose a delay");
foreach (var time in _configData.RESTART.timerestart) {
var enabletime = !BetterChatMute;
string timeprocessed = "";
if (time.ToLower().Contains("d")) {
timeprocessed = time.Substring(0, time.IndexOf("d")) + " days";
}
if (time.ToLower().Contains("m")) {
timeprocessed = time.Substring(0, time.IndexOf("m")) + " minutes";
}
if (time.ToLower().Contains("h")) {
timeprocessed = time.Substring(0, time.IndexOf("h")) + " hours";
}
builder.AddActionButton(ButtonStyle.Danger, $"{timeprocessed}", $"restartdsp {time}", false, null);
}
builder.AddActionButton(ButtonStyle.Danger, $"Cancel Restart", $"restartdsp -1 Cancel", false, null);
builder.AddActionButton(ButtonStyle.Danger, $"Instant Restart", $"restartdsp 1", false, null);
}
if (args.Length == 2) {
embed.AddField("Delay of restart", $"{args[1]}", true);
embed.AddDescription("Choose a reason");
foreach (var reason in _configData.RESTART.RestartReasons) builder.AddActionButton(ButtonStyle.Danger, $"{reason}", $"restartdsp {args[1]} {reason}", false, null);
}
if (args.Length == 3) {
embed.AddField("Delay of restart", $"{args[1]}", true);
embed.AddField("Reason of restart", $"{args[2]}", true);
embed.AddDescription("Confirm your action");
builder.AddActionButton(ButtonStyle.Danger, $"Confirm Action", $"restartdsp {args[1]} {args[2]} y", false, null);
}
embeds.Add(embed.Build());
builder.AddActionButton(ButtonStyle.Danger, "Exit", "deletedsp", false, null);
MessageCreate create = new MessageCreate {
Content = "Restart Command", Embeds = embeds, Components = builder.Build()
}
;
DiscordChannel.GetChannel(_client, (Snowflake)interaction.ChannelId, chan => {
chan.CreateMessage(_client, create);
}
);
}
private void ProcessPluginCommand(DiscordUser author, string[] args, DiscordInteraction interaction) {
GuildMember member = _guild.Members[author.Id];
int arglength = _configData.PLUGINS.confirmuse ? 4 : 3;
if (member == null) {
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.ChannelMessageWithSource, Data = new InteractionCallbackData {
Content = "Plugin Command!", Embeds = new List<DiscordEmbed> {
CreateEmbed("Who sent the command?", "Not a valid Guild Member", _configData.Color).Build()
}
, Flags = MessageFlags.Ephemeral
}
}
);
return;
}
if (!member.HasRole(_rolep) || author.Bot == true) {
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.ChannelMessageWithSource, Data = new InteractionCallbackData {
Content = "Plugin Command!", Embeds = new List<DiscordEmbed> {
CreateEmbed(Lang("NotAllowedTitle"), Lang("NotAllowedContent"), _configData.Color).Build()
}
, Flags = MessageFlags.Ephemeral
}
}
);
return;
}
if (args.Length == arglength) {
if (args[2] == "o.unload") {
DisabledPlugins.Add(new PluginInfo(args[1], SearchPlugin(args[1]).Title));
}
if (args[2] == "o.load") {
EnablePlugin(args[1]);
}
server.Command($"{args[2]} {args[1]}");
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.ChannelMessageWithSource, Data = new InteractionCallbackData {
Content = $"**{args[2]} sent on {args[1]} Successfully!**\nReturned {consolelog}", Flags = MessageFlags.Ephemeral
}
}
);
Log(_configData.LogFileName, "Plugin Command", interaction.Member.User.Username, (string)interaction.Member.User.Id, args[1], args[2]);
return;
}
MessageComponentBuilder builder = new MessageComponentBuilder();
var embed = CreateEmbed("Plugin Command: ", null, _configData.Color);
List<DiscordEmbed> embeds = new List<DiscordEmbed>();
if (args.Length == 2) {
embed.AddField("Plugin Name", $"{args[1]}", true);
embed.AddDescription("Choose a command");
if (IsPluginDisabled(args[1])) builder.AddActionButton(ButtonStyle.Primary, "Load", $"plugindsp {args[1]} o.load", false, null);
else {
builder.AddActionButton(ButtonStyle.Primary, "Reload", $"plugindsp {args[1]} o.reload", false, null);
builder.AddActionButton(ButtonStyle.Primary, "Unload", $"plugindsp {args[1]} o.unload", false, null);
}
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.UpdateMessage,
}
);
}
if ((args.Length == 3) && (_configData.PLUGINS.confirmuse)) {
embed.AddField("Plugin Name", $"{args[1]}", true);
embed.AddField("Command Chosen", $"{args[2]}", true);
embed.AddDescription("Confirm Your Choice");
builder.AddActionButton(ButtonStyle.Success, "Confirm", $"plugindsp {args[1]} {args[2]} y", false, null);
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.UpdateMessage,
}
);
}
embeds.Add(embed.Build());
builder.AddActionButton(ButtonStyle.Danger, "Exit", "deletedsp", false, null);
MessageCreate create = new MessageCreate {
Content = "Plugin Command", Embeds = embeds, Components = builder.Build()
}
;
DiscordChannel.GetChannel(_client, (Snowflake)interaction.ChannelId, chan => {
chan.CreateMessage(_client, create);
}
);
}
private void ProcessPermissionsCommand(DiscordUser author, string[] args, DiscordInteraction interaction) {
GuildMember member = _guild.Members[author.Id];
if (member == null) {
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.ChannelMessageWithSource, Data = new InteractionCallbackData {
Content = "Permissions Command!", Embeds = new List<DiscordEmbed> {
CreateEmbed("Who sent the command?", "Not a valid Guild Member", _configData.Color).Build()
}
, Flags = MessageFlags.Ephemeral
}
}
);
return;
}
if (!member.HasRole(_roleperm) || author.Bot == true) {
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.ChannelMessageWithSource, Data = new InteractionCallbackData {
Content = "Permissions Command!", Embeds = new List<DiscordEmbed> {
CreateEmbed(Lang("NotAllowedTitle"), Lang("NotAllowedContent"), _configData.Color).Build()
}
, Flags = MessageFlags.Ephemeral
}
}
);
return;
}
if (args.Length == 6) {
string type = args[1];
string action = args[3];
switch (type) {
case "player" : switch (action) {
case "grant" : server.Command($"o.grant user {args[2]} {args[4]}");
break;
case "revoke" : server.Command($"o.revoke user {args[2]} {args[4]}");
break;
case "add" : server.Command($"o.usergroup add {args[2]} {args[4]}");
break;
case "remove" : server.Command($"o.usergroup remove {args[2]} {args[4]}");
break;
}
break;
case "group" : switch (args[3]) {
case "grant" : server.Command($"o.grant group {args[2]} {args[4]}");
break;
case "revoke" : server.Command($"o.revoke group {args[2]} {args[4]}");
break;
case "add" : server.Command($"o.usergroup add {args[4]} {args[2]}");
break;
case "remove" : server.Command($"o.usergroup remove {args[4]} {args[2]}");
break;
}
break;
}
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.ChannelMessageWithSource, Data = new InteractionCallbackData {
Content = $"**Permissions Command Sent Successfully!**\nReturned {consolelog}", Flags = MessageFlags.Ephemeral
}
}
);
Log(_configData.LogFileName, "Permission Command", interaction.Member.User.Username, (string)interaction.Member.User.Id, type, action, args[4], args[2]);
return;
}
MessageComponentBuilder builder = new MessageComponentBuilder();
var embed = CreateEmbed("Permissions Command: ", null, _configData.Color);
List<DiscordEmbed> embeds = new List<DiscordEmbed>();
//Args 1 = Player or Group
if (args.Length == 1) {
embed.AddDescription("Choose an entity type");
builder.AddActionButton(ButtonStyle.Primary, "Players", $"permissionsdsp player", false, null);
builder.AddActionButton(ButtonStyle.Primary, "Oxide Group", $"permissionsdsp group", false, null);
builder.AddActionButton(ButtonStyle.Danger, "Exit", "deletedsp", false, null);
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.UpdateMessage,
}
);
}
//Args 2 = playerid or groupname
if (args.Length == 2) {
embed.AddField("Entity Chosen", $"{args[1]}", true);
embed.AddDescription("Choose an entity");
builder = args[1] == "player" ? AddButtonsPlayerlist(0, args) : args[1] == "group" ? AddButtonsGrouplist(0, args) : null;
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.UpdateMessage,
}
);
}
//Args 3 = grant or revoke or "add player to group or group to player"
if (args.Length == 3) {
embed.AddField("Entity Chosen", $"{args[1]} {args[2]}", true);
embed.AddDescription("Choose a command");
string buttonadd = args[1] == "player" ? "to group" : "";
string buttonremove = args[1] == "player" ? "from group" : "";
builder.AddActionButton(ButtonStyle.Primary, "Grant", $"permissionsdsp {args[1]} {args[2]} grant", false, null);
builder.AddActionButton(ButtonStyle.Primary, "Revoke", $"permissionsdsp {args[1]} {args[2]} revoke", false, null);
if (args[1] == "player") {
builder.AddActionButton(ButtonStyle.Primary, $"Add {buttonadd}", $"permissionsdsp {args[1]} {args[2]} add", false, null);
builder.AddActionButton(ButtonStyle.Primary, $"Remove {buttonremove}", $"permissionsdsp {args[1]} {args[2]} remove", false, null);
}
builder.AddActionButton(ButtonStyle.Danger, "Exit", "deletedsp", false, null);
}
//Args 4 = permission or affectation to affect on
if (args.Length == 4) {
embed.AddField("Entity Chosen", $"{args[1]} {args[2]}", true);
embed.AddField("Command Chosen", $"{args[3]}", true);
embed.AddDescription("Choose a permission/group");
builder = args[3] == "grant" ? AddButtonsGrantlist(0, args) : args[3] == "revoke" ? AddButtonsRevokelist(0, args) : (args[3] == "add" || args[3] == "remove") ? args[1] == "player" ? AddButtonsGrouplist(0, args, args[2]) : null : null;
}
//Args 5 = confirmation
if (args.Length == 5) {
embed.AddField("Entity Chosen", $"{args[1]} {args[2]}", true);
embed.AddField("Command Chosen", $"{args[3]} {args[4]}", true);
embed.AddDescription("Confirm your action");
builder.AddActionButton(ButtonStyle.Success, "Confirm Action", $"permissionsdsp {args[1]} {args[2]} {args[3]} {args[4]} y", false, null);
builder.AddActionButton(ButtonStyle.Danger, "Exit", "deletedsp", false, null);
}
embeds.Add(embed.Build());
MessageCreate create = new MessageCreate {
Content = "Permissions Command", Embeds = embeds, Components = builder.Build()
}
;
DiscordChannel.GetChannel(_client, (Snowflake)interaction.ChannelId, chan => {
chan.CreateMessage(_client, create);
}
);
}
private void ProcessCustomCommand(DiscordUser author, string[] args, DiscordInteraction interaction) {
GuildMember member = _guild.Members[author.Id];
int arglength = _configData.CUSTOM.confirmuse ? 3 : 2;
if (member == null) {
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.ChannelMessageWithSource, Data = new InteractionCallbackData {
Content = "Custom Command!", Embeds = new List<DiscordEmbed> {
CreateEmbed("Who sent the command?", "Not a valid Guild Member", _configData.Color).Build()
}
, Flags = MessageFlags.Ephemeral
}
}
);
return;
}
if (!member.HasRole(_rolec) || author.Bot == true) {
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.ChannelMessageWithSource, Data = new InteractionCallbackData {
Content = "Custom Command!", Embeds = new List<DiscordEmbed> {
CreateEmbed(Lang("NotAllowedTitle"), Lang("NotAllowedContent"), _configData.Color).Build()
}
, Flags = MessageFlags.Ephemeral
}
}
);
return;
}
if (args.Length == arglength) {
string cmd = _configData.CUSTOM.Commands[args[1]];
server.Command(cmd);
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.ChannelMessageWithSource, Data = new InteractionCallbackData {
Content = $"**{args[1]} Command Successfully!**\nReturned {consolelog}", Flags = MessageFlags.Ephemeral
}
}
);
Log(_configData.LogFileName, "Custom Command", interaction.Member.User.Username, (string)interaction.Member.User.Id, args[1]);
return;
}
interaction.CreateInteractionResponse(_client, new InteractionResponse {
Type = InteractionResponseType.UpdateMessage,
}
);
MessageComponentBuilder builder = new MessageComponentBuilder();
var embed = CreateEmbed("Custom Command Notice: ", $"Sending Custom Command.", _configData.Color);
List<DiscordEmbed> embeds = new List<DiscordEmbed> {
embed.Build()
}
;
if (args.Length == 1) {
embed.AddDescription("Choose a command");
foreach (var cmd in _configData.CUSTOM.Commands) {
builder.AddActionButton(ButtonStyle.Primary, $"{cmd.Key}", $"customdsp {cmd.Key}", false, null);
}
}
if (args.Length == 2) {
embed.AddField("Custom Command Chosen", $"{args[1]}", true);
embed.AddDescription("Confirm your action");
builder.AddActionButton(ButtonStyle.Success, $"Confirm {args[1]}", $"customdsp {args[1]} Yes", false, null);
}
builder.AddActionButton(ButtonStyle.Danger, "Exit", "deletedsp", false, null);
MessageCreate create = new MessageCreate {
Content = "Custom Command", Embeds = embeds, Components = builder.Build()
}
;
DiscordChannel.GetChannel(_client, (Snowflake)interaction.ChannelId, chan => {
chan.CreateMessage(_client, create);
}
);
}
private void PagePlugin(DiscordUser author, string[] args, DiscordInteraction interaction, int page) {
GuildMember member = _guild.Members[author.Id];
if (member == null) {
DiscordChannel.GetChannel(_client, (Snowflake)interaction.ChannelId, chan => {
chan.CreateMessage(_client, CreateEmbed("Who sent the command?", "Not a valid Guild Member", _configData.Color).Build());
}
);
return;
}
if (!member.HasRole(_role) || author.Bot == true) {
DiscordChannel.GetChannel(_client, (Snowflake)interaction.ChannelId, chan => {
chan.CreateMessage(_client, CreateEmbed(Lang("NotAllowedTitle"), Lang("NotAllowedContent"), _configData.Color).Build());
}
);
return;
}
var embed = CreateEmbed($"Plugin List: Page {page}", $"Select Plugins Interaction to interact with it.", _configData.Color);
List<DiscordEmbed> embeds = new List<DiscordEmbed> {
embed.Build()
}
;
MessageComponentBuilder builder = AddButtonsPluginlist(page);
MessageCreate create = new MessageCreate {
Content = "Plugins Page Command", Embeds = embeds, Components = builder.Build()
}
;
DiscordChannel.GetChannel(_client, (Snowflake)interaction.ChannelId, chan => {
chan.CreateMessage(_client, create);
}
);
}
private void PagePlayer(DiscordUser author, string[] args, DiscordInteraction interaction, int page) {
GuildMember member = _guild.Members[author.Id];
if (member == null) {
DiscordChannel.GetChannel(_client, (Snowflake)interaction.ChannelId, chan => {
chan.CreateMessage(_client, CreateEmbed("Who sent the command?", "Not a valid Guild Member", _configData.Color).Build());
}
);
return;
}
if (!member.HasRole(_role) || author.Bot == true) {
DiscordChannel.GetChannel(_client, (Snowflake)interaction.ChannelId, chan => {
chan.CreateMessage(_client, CreateEmbed(Lang("NotAllowedTitle"), Lang("NotAllowedContent"), _configData.Color).Build());
}
);
return;
}
var embed = CreateEmbed($"Player List: Page {page}", $"Select Player Interaction to interact with it.", _configData.Color);
List<DiscordEmbed> embeds = new List<DiscordEmbed> {
embed.Build()
}
;
MessageComponentBuilder builder = new MessageComponentBuilder();
builder = AddButtonsPlayerlist(page, args.Skip(2).ToArray());
MessageCreate create = new MessageCreate {
Content = "Player Page Command", Embeds = embeds, Components = builder.Build()
}
;
DiscordChannel.GetChannel(_client, (Snowflake)interaction.ChannelId, chan => {
chan.CreateMessage(_client, create);
}
);
}
private void PageGroup(DiscordUser author, string[] args, DiscordInteraction interaction, int page) {
GuildMember member = _guild.Members[author.Id];
if (member == null) {
DiscordChannel.GetChannel(_client, (Snowflake)interaction.ChannelId, chan => {
chan.CreateMessage(_client, CreateEmbed("Who sent the command?", "Not a valid Guild Member", _configData.Color).Build());
}
);
return;
}
if (!member.HasRole(_role) || author.Bot == true) {
DiscordChannel.GetChannel(_client, (Snowflake)interaction.ChannelId, chan => {
chan.CreateMessage(_client, CreateEmbed(Lang("NotAllowedTitle"), Lang("NotAllowedContent"), _configData.Color).Build());
}
);
return;
}
var embed = CreateEmbed($"Group List: Page {page}", $"Select Group Interaction to interact with it.", _configData.Color);
List<DiscordEmbed> embeds = new List<DiscordEmbed> {
embed.Build()
}
;
MessageComponentBuilder builder = new MessageComponentBuilder();
string[] arg = args.Skip(2).ToArray(
// ... [Code preview truncated due to length. Full source in attached file] ...