Fixed some text and added some missing texts to commands. Added new command to clear screen and formated code.

This commit is contained in:
2023-07-03 14:39:50 +03:00
parent 4a6a12baae
commit 298e557260
36 changed files with 1503 additions and 1542 deletions

View File

@@ -1,11 +1,9 @@
using System.Net.Mime;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using PluginManager.Others;
namespace PluginManager.Bot;
@@ -44,35 +42,37 @@ public class Boot
public Boot(string botToken, string botPrefix)
{
this.botPrefix = botPrefix;
this.botToken = botToken;
this.botToken = botToken;
}
/// <summary>
/// Checks if the bot is ready
/// </summary>
/// <value> true if the bot is ready, othwerwise false </value>
/// <value> true if the bot is ready, otherwise false </value>
public bool isReady { get; private set; }
/// <summary>
/// The start method for the bot. This method is used to load the bot
/// </summary>
/// <param name="config">The discord socket config. If null then the default one will be applied (AlwaysDownloadUsers=true, UseInteractionSnowflakeDate=false, GatewayIntents=GatewayIntents.All)</param>
/// <param name="config">
/// The discord socket config. If null then the default one will be applied (AlwaysDownloadUsers=true,
/// UseInteractionSnowflakeDate=false, GatewayIntents=GatewayIntents.All)
/// </param>
/// <returns>Task</returns>
public async Task Awake(DiscordSocketConfig? config = null)
{
if (config is null)
config = new DiscordSocketConfig
{
AlwaysDownloadUsers = true,
//Disable system clock checkup (for responses at slash commands)
UseInteractionSnowflakeDate = false,
GatewayIntents = GatewayIntents.All
GatewayIntents = GatewayIntents.All
};
client = new DiscordSocketClient(config);
client = new DiscordSocketClient(config);
service = new CommandService();
CommonTasks();
@@ -86,7 +86,6 @@ public class Boot
await commandServiceHandler.InstallCommandsAsync();
await Task.Delay(2000);
Config._DiscordBotClient = this;
@@ -97,10 +96,10 @@ public class Boot
private void CommonTasks()
{
if (client == null) return;
client.LoggedOut += Client_LoggedOut;
client.Log += Log;
client.LoggedIn += LoggedIn;
client.Ready += Ready;
client.LoggedOut += Client_LoggedOut;
client.Log += Log;
client.LoggedIn += LoggedIn;
client.Ready += Ready;
client.Disconnected += Client_Disconnected;
}
@@ -109,7 +108,8 @@ public class Boot
if (arg.Message.Contains("401"))
{
Config.Data.Remove("token");
Config.Logger.Log("The token is invalid. Please restart the bot and enter a valid token.", this, Others.LogLevel.ERROR);
Config.Logger.Log("The token is invalid. Please restart the bot and enter a valid token.", this,
LogLevel.ERROR);
Config.Data.Save();
await Task.Delay(4000);
Environment.Exit(0);
@@ -140,7 +140,7 @@ public class Boot
{
case LogSeverity.Error:
case LogSeverity.Critical:
Config.Logger.Log(message.Message, this, Others.LogLevel.ERROR);
Config.Logger.Log(message.Message, this, LogLevel.ERROR);
break;

View File

@@ -2,7 +2,6 @@ using System;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Discord.Commands;
using Discord.WebSocket;
using PluginManager.Interfaces;
@@ -14,9 +13,9 @@ namespace PluginManager.Bot;
internal class CommandHandler
{
private readonly string botPrefix;
private readonly string botPrefix;
private readonly DiscordSocketClient client;
private readonly CommandService commandService;
private readonly CommandService commandService;
/// <summary>
/// Command handler constructor
@@ -26,10 +25,9 @@ internal class CommandHandler
/// <param name="botPrefix">The prefix to watch for</param>
public CommandHandler(DiscordSocketClient client, CommandService commandService, string botPrefix)
{
this.client = client;
this.client = client;
this.commandService = commandService;
this.botPrefix = botPrefix;
this.botPrefix = botPrefix;
}
/// <summary>
@@ -38,7 +36,7 @@ internal class CommandHandler
/// <returns></returns>
public async Task InstallCommandsAsync()
{
client.MessageReceived += MessageHandler;
client.MessageReceived += MessageHandler;
client.SlashCommandExecuted += Client_SlashCommandExecuted;
await commandService.AddModulesAsync(Assembly.GetEntryAssembly(), null);
}
@@ -63,7 +61,6 @@ internal class CommandHandler
}
return Task.CompletedTask;
}
/// <summary>
@@ -73,10 +70,9 @@ internal class CommandHandler
/// <returns></returns>
private async Task MessageHandler(SocketMessage Message)
{
try
{
if (Message.Author.IsBot)
if (Message.Author.IsBot)
return;
if (Message as SocketUserMessage == null)
@@ -97,18 +93,22 @@ internal class CommandHandler
await commandService.ExecuteAsync(context, argPos, null);
DBCommand? plugin;
string cleanMessage = "";
var cleanMessage = "";
if (message.HasMentionPrefix(client.CurrentUser, ref argPos))
{
string mentionPrefix = "<@" + client.CurrentUser.Id + ">";
var mentionPrefix = "<@" + client.CurrentUser.Id + ">";
plugin = PluginLoader.Commands!
.FirstOrDefault(plug => plug.Command == message.Content.Substring(mentionPrefix.Length+1).Split(' ')[0] ||
(
plug.Aliases is not null &&
plug.Aliases.Contains(message.CleanContent.Substring(mentionPrefix.Length+1).Split(' ')[0])
));
.FirstOrDefault(plug => plug.Command ==
message.Content.Substring(mentionPrefix.Length + 1)
.Split(' ')[0] ||
(
plug.Aliases is not null &&
plug.Aliases.Contains(message.CleanContent
.Substring(mentionPrefix.Length + 1)
.Split(' ')[0])
));
cleanMessage = message.Content.Substring(mentionPrefix.Length + 1);
}
@@ -116,23 +116,27 @@ internal class CommandHandler
else
{
plugin = PluginLoader.Commands!
.FirstOrDefault(p => p.Command == message.Content.Split(' ')[0].Substring(botPrefix.Length) ||
(p.Aliases is not null &&
p.Aliases.Contains(
message.Content.Split(' ')[0].Substring(botPrefix.Length))));
.FirstOrDefault(p => p.Command ==
message.Content.Split(' ')[0].Substring(botPrefix.Length) ||
(p.Aliases is not null &&
p.Aliases.Contains(
message.Content.Split(' ')[0]
.Substring(botPrefix.Length))));
cleanMessage = message.Content.Substring(botPrefix.Length);
}
if (plugin is null)
throw new Exception($"Failed to run command ! " + message.CleanContent + " (user: " + context.Message.Author.Username + " - " + context.Message.Author.Id + ")");
if (plugin is null)
throw new Exception("Failed to run command ! " + message.CleanContent + " (user: " +
context.Message.Author.Username + " - " + context.Message.Author.Id + ")");
if (plugin.requireAdmin && !context.Message.Author.isAdmin())
return;
string[] split = cleanMessage.Split(' ');
var split = cleanMessage.Split(' ');
string[]? argsClean = null;
if(split.Length > 1)
argsClean = string.Join(' ', split, 1, split.Length-1).Split(' ');
if (split.Length > 1)
argsClean = string.Join(' ', split, 1, split.Length - 1).Split(' ');
DBCommandExecutingArguments cmd = new(context, cleanMessage, split[0], argsClean);