This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,16 +1,9 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
using dsc = Discord.Commands;
|
using DiscordLibCommands = Discord.Commands;
|
||||||
using ds = Discord;
|
using DiscordLib = Discord;
|
||||||
|
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
using PluginManager.Others.Permissions;
|
using PluginManager.Others.Permissions;
|
||||||
@@ -56,9 +49,9 @@ namespace DiscordBot.Discord.Commands
|
|||||||
/// <param name="message">The command message</param>
|
/// <param name="message">The command message</param>
|
||||||
/// <param name="client">The discord bot client</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>
|
/// <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 args = Functions.GetArguments(message);
|
||||||
var OS = Functions.GetOperatinSystem();
|
var OS = Functions.GetOperatinSystem();
|
||||||
if (args.Count == 0)
|
if (args.Count == 0)
|
||||||
@@ -87,15 +80,22 @@ namespace DiscordBot.Discord.Commands
|
|||||||
break;
|
break;
|
||||||
case "-cmd":
|
case "-cmd":
|
||||||
case "-args":
|
case "-args":
|
||||||
|
string cmd = "--args";
|
||||||
|
|
||||||
|
if (args.Count > 1)
|
||||||
|
for (int i = 1; i < args.Count; i++)
|
||||||
|
cmd += $" {args[i]}";
|
||||||
|
|
||||||
|
|
||||||
switch (OS)
|
switch (OS)
|
||||||
{
|
{
|
||||||
case PluginManager.Others.OperatingSystem.WINDOWS:
|
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;
|
break;
|
||||||
case PluginManager.Others.OperatingSystem.LINUX:
|
case PluginManager.Others.OperatingSystem.LINUX:
|
||||||
case PluginManager.Others.OperatingSystem.MAC_OS:
|
case PluginManager.Others.OperatingSystem.MAC_OS:
|
||||||
Process.Start("./DiscordBot", Functions.MergeStrings(args.ToArray(), 1));
|
Process.Start("./DiscordBot", cmd);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -36,9 +36,9 @@ namespace DiscordBot
|
|||||||
Directory.CreateDirectory("./Data/Languages");
|
Directory.CreateDirectory("./Data/Languages");
|
||||||
Directory.CreateDirectory("./Data/Plugins/Commands");
|
Directory.CreateDirectory("./Data/Plugins/Commands");
|
||||||
Directory.CreateDirectory("./Data/Plugins/Events");
|
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)
|
while (true)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Please insert your token: ");
|
Console.WriteLine("Please insert your token: ");
|
||||||
@@ -46,11 +46,10 @@ namespace DiscordBot
|
|||||||
string botToken = Console.ReadLine();
|
string botToken = Console.ReadLine();
|
||||||
if (botToken.Length == 59)
|
if (botToken.Length == 59)
|
||||||
{
|
{
|
||||||
string prefix = Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_PREFIX",
|
string prefix = Functions.readCodeFromFile("./Data/Resources/DiscordBotCore.data", "BOT_PREFIX", '=');
|
||||||
'\t');
|
|
||||||
if (prefix == string.Empty || prefix == null)
|
if (prefix == string.Empty || prefix == null)
|
||||||
prefix = "!";
|
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;
|
break;
|
||||||
}
|
}
|
||||||
else Console.WriteLine("Invalid Token !");
|
else Console.WriteLine("Invalid Token !");
|
||||||
@@ -239,7 +238,7 @@ namespace DiscordBot
|
|||||||
break;
|
break;
|
||||||
case "token":
|
case "token":
|
||||||
if (File.Exists("./Data/Resources/DiscordBotCore.data"))
|
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");
|
else Console.WriteLine("File could not be found. Please register token");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -359,17 +358,12 @@ namespace DiscordBot
|
|||||||
|
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
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.ForegroundColor = ConsoleColor.White;
|
||||||
Console.WriteLine("============================ Discord BOT - Cross Platform ============================");
|
Console.WriteLine("============================ Discord BOT - Cross Platform ============================");
|
||||||
string token =
|
string token = Functions.readCodeFromFile(Functions.dataFolder + "DiscordBotCore.data", "BOT_TOKEN", '=');
|
||||||
Functions.readCodeFromFile((Functions.dataFolder + "DiscordBotCore.data"), "BOT_TOKEN",
|
string prefix = Functions.readCodeFromFile(Functions.dataFolder + "DiscordBotCore.data", "BOT_PREFIX", '=');
|
||||||
'\t');
|
|
||||||
string prefix = Functions.readCodeFromFile((Functions.dataFolder + "DiscordBotCore.data"),
|
|
||||||
"BOT_PREFIX",
|
|
||||||
'\t');
|
|
||||||
|
|
||||||
Console.WriteLine("Detected prefix: " + prefix);
|
|
||||||
var discordbooter = new Boot(token, prefix);
|
var discordbooter = new Boot(token, prefix);
|
||||||
await discordbooter.Awake();
|
await discordbooter.Awake();
|
||||||
return discordbooter;
|
return discordbooter;
|
||||||
@@ -430,7 +424,7 @@ namespace DiscordBot
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (len > 0 && args.Contains("--cmd"))
|
if (len > 0 && (args.Contains("--cmd") || args.Contains("--args")))
|
||||||
{
|
{
|
||||||
if (args.Contains("lp") || args.Contains("loadplugins"))
|
if (args.Contains("lp") || args.Contains("loadplugins"))
|
||||||
loadPluginsOnStartup = true;
|
loadPluginsOnStartup = true;
|
||||||
|
|||||||
@@ -18,7 +18,17 @@ public class LevelingSystem : DBEvent
|
|||||||
|
|
||||||
private async Task Client_MessageReceived(SocketMessage arg)
|
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;
|
return;
|
||||||
|
|
||||||
if (Core.playerMessages.ContainsKey(arg.Author.Id))
|
if (Core.playerMessages.ContainsKey(arg.Author.Id))
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ namespace PluginManager.Others
|
|||||||
/// <param name="fileName">File name</param>
|
/// <param name="fileName">File name</param>
|
||||||
/// <param name="Code">Setting name</param>
|
/// <param name="Code">Setting name</param>
|
||||||
/// <param name="separator">Separator between setting key code and its value</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)
|
public static string? readCodeFromFile(string fileName, string Code, char separator)
|
||||||
=> File.ReadAllLines(fileName)
|
=> File.ReadAllLines(fileName)
|
||||||
.Where(p => p.StartsWith(Code) && !p.StartsWith(commentMark.ToString()))
|
.Where(p => p.StartsWith(Code) && !p.StartsWith(commentMark.ToString()))
|
||||||
@@ -65,9 +65,7 @@ namespace PluginManager.Others
|
|||||||
archFile = pakFolder + archFile;
|
archFile = pakFolder + archFile;
|
||||||
Directory.CreateDirectory(pakFolder);
|
Directory.CreateDirectory(pakFolder);
|
||||||
if (!File.Exists(archFile))
|
if (!File.Exists(archFile))
|
||||||
{
|
throw new FileNotFoundException("Failed to load file !");
|
||||||
throw new Exception("Failed to load file !");
|
|
||||||
}
|
|
||||||
|
|
||||||
string? textValue = null;
|
string? textValue = null;
|
||||||
var fs = new FileStream(archFile, FileMode.Open);
|
var fs = new FileStream(archFile, FileMode.Open);
|
||||||
|
|||||||
Reference in New Issue
Block a user