using System;
using System.Collections.Generic;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using PluginManager;
using PluginManager.Interfaces;
namespace DiscordBot.Discord.Commands;
internal class Settings : DBCommand
{
///
/// Command name
///
public string Command => "set";
public List Aliases => null;
///
/// Command Description
///
public string Description => "This command allows you change all settings. Use \"set help\" to show details";
///
/// Command usage
///
public string Usage => "set [keyword] [new Value]";
///
/// Check if the command can be used />
///
public bool canUseDM => true;
///
/// Check if the command can be used in a server
///
public bool canUseServer => true;
///
/// Check if the command require administrator to be executed
///
public bool requireAdmin => true;
///
/// The main body of the command
///
/// The command context
/// The command message
/// The discord bot client
/// True if the message was sent from a DM channel, false otherwise
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
{
var channel = message.Channel;
try
{
var content = message.Content;
var data = content.Split(' ');
var keyword = data[1];
if (keyword.ToLower() == "help")
{
await channel.SendMessageAsync("set token [new value] -- set the value of the new token (require restart)");
await channel.SendMessageAsync("set prefix [new value] -- set the value of the new preifx (require restart)");
return;
}
switch (keyword.ToLower())
{
case "token":
if (data.Length != 3)
{
await channel.SendMessageAsync("Invalid token !");
return;
}
Config.SetValue("token", data[2]);
break;
case "prefix":
if (data.Length != 3)
{
await channel.SendMessageAsync("Invalid token !");
return;
}
Config.SetValue("token", data[2]);
break;
default:
return;
}
await channel.SendMessageAsync("Restart required ...");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
await channel.SendMessageAsync("Unknown usage to this command !\nUsage: " + Usage);
}
}
}