This commit is contained in:
2022-05-04 16:00:46 +03:00
parent 6a6e3ad7e9
commit 3567392dd9
6 changed files with 35 additions and 33 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -1,16 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using Discord.WebSocket;
using dsc = Discord.Commands;
using ds = Discord;
using DiscordLibCommands = Discord.Commands;
using DiscordLib = Discord;
using PluginManager.Interfaces;
using PluginManager.Others.Permissions;
@@ -56,9 +49,9 @@ namespace DiscordBot.Discord.Commands
/// <param name="message">The command message</param>
/// <param name="client">The discord bot client</param>
/// <param name="isDM">True if the message was sent from a DM channel, false otherwise</param>
public async void Execute(dsc.SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
public async void Execute(DiscordLibCommands.SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
{
if (!DiscordPermissions.hasPermission(message.Author as SocketGuildUser, ds.GuildPermission.Administrator)) return;
if (!DiscordPermissions.hasPermission(message.Author as SocketGuildUser, DiscordLib.GuildPermission.Administrator)) return;
var args = Functions.GetArguments(message);
var OS = Functions.GetOperatinSystem();
if (args.Count == 0)
@@ -87,15 +80,22 @@ namespace DiscordBot.Discord.Commands
break;
case "-cmd":
case "-args":
string cmd = "--args";
if (args.Count > 1)
for (int i = 1; i < args.Count; i++)
cmd += $" {args[i]}";
switch (OS)
{
case PluginManager.Others.OperatingSystem.WINDOWS:
Process.Start("./DiscordBot.exe", Functions.MergeStrings(args.ToArray(), 1));
Functions.WriteLogFile("Restarting the bot with the following arguments: \"" + cmd + "\"");
Process.Start("./DiscordBot.exe", cmd);
break;
case PluginManager.Others.OperatingSystem.LINUX:
case PluginManager.Others.OperatingSystem.MAC_OS:
Process.Start("./DiscordBot", Functions.MergeStrings(args.ToArray(), 1));
Process.Start("./DiscordBot", cmd);
break;
default:
return;

View File

@@ -36,9 +36,9 @@ namespace DiscordBot
Directory.CreateDirectory("./Data/Languages");
Directory.CreateDirectory("./Data/Plugins/Commands");
Directory.CreateDirectory("./Data/Plugins/Events");
if (!File.Exists("./Data/Resources/DiscordBotCore.data") || Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_TOKEN", '\t')!.Length != 59)
if (!File.Exists("./Data/Resources/DiscordBotCore.data") || Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_TOKEN", '=')!.Length != 59)
{
File.WriteAllText("./Data/Resources/DiscordBotCore.data", "BOT_TOKEN\ttoken\nBOT_PREFIX\t!\n");
File.WriteAllText("./Data/Resources/DiscordBotCore.data", "BOT_TOKEN=token\nBOT_PREFIX=!\n");
while (true)
{
Console.WriteLine("Please insert your token: ");
@@ -46,11 +46,10 @@ namespace DiscordBot
string botToken = Console.ReadLine();
if (botToken.Length == 59)
{
string prefix = Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_PREFIX",
'\t');
string prefix = Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_PREFIX", '=');
if (prefix == string.Empty || prefix == null)
prefix = "!";
File.WriteAllText("./Data/Resources/DiscordBotCore.data", $"BOT_TOKEN\t{botToken}\nBOT_PREFIX\t{prefix}\n");
File.WriteAllText("./Data/Resources/DiscordBotCore.data", $"BOT_TOKEN={botToken}\nBOT_PREFIX={prefix}\n");
break;
}
else Console.WriteLine("Invalid Token !");
@@ -239,7 +238,7 @@ namespace DiscordBot
break;
case "token":
if (File.Exists("./Data/Resources/DiscordBotCore.data"))
Console.WriteLine("Token: " + Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_TOKEN", '\t'));
Console.WriteLine("Token: " + Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_TOKEN", '='));
else Console.WriteLine("File could not be found. Please register token");
break;
default:
@@ -359,17 +358,12 @@ namespace DiscordBot
Console.Clear();
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("Discord BOT for Cross Platform\n\nCreated by: Wizzy\nDiscord: Wizzy#9181");
//Console.WriteLine("Discord BOT for Cross Platform\n\nCreated by: Wizzy\nDiscord: Wizzy#9181");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("============================ Discord BOT - Cross Platform ============================");
string token =
Functions.readCodeFromFile((Functions.dataFolder + "DiscordBotCore.data"), "BOT_TOKEN",
'\t');
string prefix = Functions.readCodeFromFile((Functions.dataFolder + "DiscordBotCore.data"),
"BOT_PREFIX",
'\t');
string token = Functions.readCodeFromFile(Functions.dataFolder + "DiscordBotCore.data", "BOT_TOKEN", '=');
string prefix = Functions.readCodeFromFile(Functions.dataFolder + "DiscordBotCore.data", "BOT_PREFIX", '=');
Console.WriteLine("Detected prefix: " + prefix);
var discordbooter = new Boot(token, prefix);
await discordbooter.Awake();
return discordbooter;
@@ -430,7 +424,7 @@ namespace DiscordBot
return;
}
if (len > 0 && args.Contains("--cmd"))
if (len > 0 && (args.Contains("--cmd") || args.Contains("--args")))
{
if (args.Contains("lp") || args.Contains("loadplugins"))
loadPluginsOnStartup = true;

View File

@@ -18,7 +18,17 @@ public class LevelingSystem : DBEvent
private async Task Client_MessageReceived(SocketMessage arg)
{
if (arg.Author.IsBot || arg.Attachments.Count > 0 || arg.Content.StartsWith(Functions.readCodeFromFile(System.IO.Path.Combine(Functions.dataFolder, "DiscordBotCore.data"), "BOT_PREFIX", '\t')))
if (arg.Author.IsBot || arg.Attachments.Count > 0 ||
arg.Content.StartsWith
(
Functions.readCodeFromFile
(
fileName: System.IO.Path.Combine(Functions.dataFolder, "DiscordBotCore.data"),
Code: "BOT_PREFIX",
separator: '='
)
)
)
return;
if (Core.playerMessages.ContainsKey(arg.Author.Id))

View File

@@ -48,7 +48,7 @@ namespace PluginManager.Others
/// <param name="fileName">File name</param>
/// <param name="Code">Setting name</param>
/// <param name="separator">Separator between setting key code and its value</param>
/// <returns>The value of the specified setting key code in the specified file (STRING)</returns>
/// <returns>The value of the specified setting key code in the specified file (<see cref="string"/>)</returns>
public static string? readCodeFromFile(string fileName, string Code, char separator)
=> File.ReadAllLines(fileName)
.Where(p => p.StartsWith(Code) && !p.StartsWith(commentMark.ToString()))
@@ -65,9 +65,7 @@ namespace PluginManager.Others
archFile = pakFolder + archFile;
Directory.CreateDirectory(pakFolder);
if (!File.Exists(archFile))
{
throw new Exception("Failed to load file !");
}
throw new FileNotFoundException("Failed to load file !");
string? textValue = null;
var fs = new FileStream(archFile, FileMode.Open);