This commit is contained in:
Wizzy69
2022-01-12 15:37:45 +02:00
parent 84ee5c6235
commit bb5260ce68
40 changed files with 484 additions and 73 deletions

View File

@@ -0,0 +1,16 @@
########################
# #
# Language Config File #
# Romanian #
# #
########################
#Language name
LANGUAGE_NAME=Romanian
#Language on plugins
PLUGIN_LOADING_START=Incarcare extensii...
COMMAND_LOAD_SUCCESS=[COMANDA] Comanda {0} a fost incarcata cu succes
COMMAND_LOAD_FAIL=[COMANDA] Comanda {0} nu a fost incarcata pentru ca {1}
EVENT_LOAD_SUCCESS=[EVENIMENT] Evenimentul {0} a fost initializat cu succes
EVENT_LOAD_FAIL=[EVENIMENT] Evenimentul {0} nu a fost initializat pentru ca {1}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,2 @@
BOT_TOKEN NzEzNzczNTM1MTIxNzY4NTU5.Xsk_aA.5ZDlK_bBm_7kqTALuuzhMyjDbXI
BOT_PREFIX ;

View File

@@ -0,0 +1 @@
Language=English

View File

@@ -0,0 +1 @@
Level=1,EXP=6,REXP=75

View File

@@ -0,0 +1 @@
Level=2,EXP=10,REXP=78

View File

@@ -0,0 +1,7 @@
Enabled=False
Dynamic Title=False
#For dynamic title add titles like this:
#Title=Hello,World,Test,Test2
Title=Hello World
Dynamic Title Change Rate=3501

View File

@@ -0,0 +1,13 @@
Enabled=True
Embed=True
#Available placeholders:
#{user.Name} => Username of the user
#{time.date} => Current Date
#{time.time} => Current time (hh:mm::ss)
MessageTitle = Welcome {user.Name}
MessageDescription=Embed description
MessageField1Title=Custom Title
MessageFiled1Text=Custom Filed 1 text
MessageField2Title=Custom Title
MessageFiled2Text=Custom Filed 2 text
MessageFooter=Today: {time.date} at {time.time}

View File

@@ -3,6 +3,7 @@ using Discord.WebSocket;
using PluginManager.Loaders;
using PluginManager.Interfaces;
using PluginManager.Others.Permissions;
namespace PluginManager.Commands
{
@@ -17,21 +18,47 @@ namespace PluginManager.Commands
public bool canUseDM => true;
public bool canUseServer => true;
public bool requireAdmin => false;
public void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
{
if (isDM)
bool isAdmin = ((SocketGuildUser)message.Author).isAdmin();
if (isAdmin)
{
foreach (DBCommand p in PluginLoader.Plugins!)
if (p.canUseDM)
context.Channel.SendMessageAsync(p.Usage + "\t" + p.Description);
if (isDM)
{
foreach (DBCommand p in PluginLoader.Plugins!)
if (p.canUseDM)
if (p.requireAdmin)
context.Channel.SendMessageAsync("[ADMIN] " + p.Usage + "\t" + p.Description);
else context.Channel.SendMessageAsync(p.Usage + "\t" + p.Description);
}
else
{
foreach (DBCommand p in PluginLoader.Plugins!)
if (p.canUseServer)
if (p.requireAdmin)
context.Channel.SendMessageAsync("[ADMIN] " + p.Usage + "\t" + p.Description);
else context.Channel.SendMessageAsync(p.Usage + "\t" + p.Description);
}
}
else
{
foreach (DBCommand p in PluginLoader.Plugins!)
if (p.canUseServer)
context.Channel.SendMessageAsync(p.Usage + "\t" + p.Description);
if (isDM)
{
foreach (DBCommand p in PluginLoader.Plugins!)
if (p.canUseDM && !p.requireAdmin)
context.Channel.SendMessageAsync(p.Usage + "\t" + p.Description);
}
else
{
foreach (DBCommand p in PluginLoader.Plugins!)
if (p.canUseServer && !p.requireAdmin)
context.Channel.SendMessageAsync(p.Usage + "\t" + p.Description);
}
}
}
}
}

View File

@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using PluginManager.Core;
using PluginManager.Interfaces;
using PluginManager.Others;
using PluginManager.Others.Permissions;
namespace DiscordBot.Discord.Commands
{
class Settings : DBCommand
{
public string Command => "set";
public string Description => "This command allows you change all settings. Use \"set help\" to show details";
public string Usage => "set [keyword] [new Value]";
public bool canUseDM => true;
public bool canUseServer => true;
public bool requireAdmin => true;
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
{
var channel = message.Channel;
try
{
string content = message.Content;
string[] data = content.Split(' ');
string 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;
}
Functions.WriteToSettings("./Data/Resources/DiscordBotCore.data", "BOT_TOKEN", data[2], '\t');
break;
case "prefix":
if (data.Length != 3)
{
await channel.SendMessageAsync("Invalid token !");
return;
}
Functions.WriteToSettings("./Data/Resources/DiscordBotCore.data", "BOT_PREFIX", data[2], '\t');
break;
default:
return;
}
await channel.SendMessageAsync("Restart required ...");
}
catch
{
await channel.SendMessageAsync("Unknown usage to this command !\nUsage: " + Usage);
}
}
}
}

View File

@@ -46,13 +46,13 @@ namespace PluginManager.Core
public async Task ShutDown()
{
if (client == null) return;
await client.LogoutAsync();
await client.StopAsync();
}
private void CommonTasks()
{
if (client == null)
return;
if (client == null) return;
client.LoggedOut += Client_LoggedOut;
client.Log += Log;
client.LoggedIn += LoggedIn;

View File

@@ -5,10 +5,12 @@ using PluginManager.Interfaces;
using System.Reflection;
using PluginManager.Others;
using PluginManager.Others.Permissions;
using PluginManager.Loaders;
using System.Threading.Tasks;
using System.Linq;
using Discord;
namespace PluginManager.Core
{
@@ -18,6 +20,9 @@ namespace PluginManager.Core
private readonly CommandService commandService;
private readonly string botPrefix;
internal static bool awaitRestartOnSetCommand = false;
internal static SocketUser? RestartOnSetCommandCaster = null;
public CommandHandler(DiscordSocketClient client, CommandService commandService, string botPrefix)
{
this.client = client;
@@ -51,7 +56,26 @@ namespace PluginManager.Core
}
if (!(message.HasStringPrefix(botPrefix, ref argPos) || message.Author.IsBot))
return;
if (message.Author.IsBot) return;
else
{
if (awaitRestartOnSetCommand && RestartOnSetCommandCaster is not null)
{
if (message.Content.ToLower() == "yes")
{
if (!(((SocketGuildUser)message.Author).hasPermission(GuildPermission.Administrator)))
{
await message.Channel.SendMessageAsync("You do not have permission to use this command !");
awaitRestartOnSetCommand = false;
RestartOnSetCommandCaster = null;
return;
}
var fileName = Assembly.GetExecutingAssembly().Location;
System.Diagnostics.Process.Start(fileName);
}
}
return;
}
var context = new SocketCommandContext(client, message);
@@ -63,19 +87,51 @@ namespace PluginManager.Core
DBCommand? plugin = PluginLoader.Plugins!.Where(p => p.Command == (message.Content.Split(' ')[0]).Substring(botPrefix.Length)).FirstOrDefault();
if (plugin != null)
{
if (message.Channel == await message.Author.CreateDMChannelAsync())
{
if (plugin.canUseDM)
{
if (plugin.requireAdmin)
{
if (message.Author.isAdmin())
{
plugin.Execute(context, message, client, true);
Functions.WriteLogFile($"[{message.Author.Id}] Executed command (DM) : " + plugin.Command);
return;
}
await message.Channel.SendMessageAsync("This command is for administrators only !");
return;
}
plugin.Execute(context, message, client, true);
Functions.WriteLogFile("Executed command (DM) : " + plugin.Command);
Functions.WriteLogFile($"[{message.Author.Id}] Executed command (DM) : " + plugin.Command);
return;
}
await message.Channel.SendMessageAsync("This command is not for DMs");
return;
}
plugin.Execute(context, message, client, false);
Functions.WriteLogFile("Executed command : " + plugin.Command);
if (plugin.canUseServer)
{
if (plugin.requireAdmin)
{
if (message.Author.isAdmin())
{
plugin.Execute(context, message, client, false);
Functions.WriteLogFile($"[{message.Author.Id}] Executed command : " + plugin.Command);
return;
}
await message.Channel.SendMessageAsync("This command is for administrators only !");
return;
}
plugin.Execute(context, message, client, false);
Functions.WriteLogFile($"[{message.Author.Id}] Executed command : " + plugin.Command);
return;
}
return;
}
}
catch { }

View File

@@ -5,10 +5,10 @@ using System.Threading.Tasks;
using PluginManager.Core;
using PluginManager.Others;
using PluginManager.Loaders;
using PluginManager.LanguageSystem;
using PluginManager.Online;
namespace DiscordBot
{
public class Program
@@ -26,8 +26,6 @@ namespace DiscordBot
public static void Main(string[] args)
{
AppDomain.CurrentDomain.AppendPrivatePath(".\\Requirements");
Console.Clear();
Directory.CreateDirectory("./Data/Resources");
Directory.CreateDirectory("./Data/Languages");
Directory.CreateDirectory("./Data/Plugins/Commands");
@@ -39,10 +37,10 @@ namespace DiscordBot
{
Console.WriteLine("Please insert your token: ");
Console.Write("TOKEN: ");
string botToken = Console.ReadLine();
string? botToken = Console.ReadLine();
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)
prefix = "!";
@@ -123,8 +121,28 @@ namespace DiscordBot
break;
case "dwlang":
string Lname = data.MergeStrings(1);
string[] link = await languageManager.GetDownloadLink(Lname);
if (link[0] == null)
string?[] link = await languageManager.GetDownloadLink(Lname);
try
{
if (link[0] is null || link is null)
{
if (Lname == "")
{
Functions.WriteColorText($"Name is invalid");
break;
}
Functions.WriteColorText("Failed to find language &b" + Lname + " &c! Use &glistlang &ccommand to display all available languages !");
break;
}
if (link[1].Contains("CrossPlatform") || link[1].Contains("cp"))
{
Downloader dwn = new Downloader(Lname + ".lng", link[0]);
await dwn.DownloadFileAsync(Functions.langFolder);
}
else Functions.WriteColorText("The language you are trying to download (&b" + Lname + "&c) is not compatible with the version of this bot. User &glistlang &ccommand in order to see all available languages for your current version !\n" + link[1]);
break;
}
catch
{
if (Lname == "")
{
@@ -134,13 +152,7 @@ namespace DiscordBot
Functions.WriteColorText("Failed to find language &b" + Lname + " &c! Use &glistlang &ccommand to display all available languages !");
break;
}
if (link[1].Contains("CrossPlatform") || link[1].Contains("cp"))
{
Downloader dwn = new Downloader(Lname + ".lng", link[0]);
await dwn.DownloadFileAsync(Functions.langFolder);
}
else Functions.WriteColorText("The language you are trying to download (&b" + Lname + "&c) is not compatible with the version of this bot. User &glistlang &ccommand in order to see all available languages for your current version !\n" + link[1]);
break;
case "loadplugins":
case "lp":
LoadPlugins(discordbooter);
@@ -283,18 +295,7 @@ namespace DiscordBot
Console.Clear();
Console.ForegroundColor = ConsoleColor.DarkYellow;
Console.WriteLine("Discord BOT for Cross Platform\n\nCreated by: Wizzy\nDiscord: Wizzy#9181\nCommands:");
Console.WriteLine(
"lp | loadplugins -> load all plugins\n" +
"sd | shutdown->close connection to the server(stop bot)\n" +
"token -> display the current token\n" +
"listplugs -> list all available plugins\n" +
"dwplug [name] -> download plugin by name\n" +
"listlang -> list all available languages\n" +
"dwlang -> download language by name\n" +
"setlang [name] -> set language from the downloaded languages\n" +
"set-setting [setting.path] [value] -> set setting value"
);
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 =
@@ -327,42 +328,22 @@ namespace DiscordBot
return Task.CompletedTask;
}
/// <summary>
/// Replace text in the file
/// </summary>
/// <param name="file">The file location (path)</param>
/// <param name="code">The setting key code where to replace</param>
/// <param name="value">The new value</param>
/// <exception cref="FileNotFoundException">If the <paramref name="file"/> does not exist, then this error is thrown</exception>
private static void ReplaceText(string file, string code, string value)
{
try
{
var f = false;
string[] text = File.ReadAllLines(file);
foreach (string line in text)
if (line.StartsWith(code))
{
line.Replace(line.Split('\t')[1], value);
f = true;
}
if (f)
File.WriteAllLines(@"./Data/Resources/DiscordBotCore.data", text);
else throw new FileNotFoundException();
}
catch (FileNotFoundException)
{
File.AppendAllText(file, code + "\t" + value + "\n");
}
}
/// <summary>
/// Handle user input arguments from the startup of the application
/// </summary>
/// <param name="args">The arguments</param>
private static async Task HandleInput(string[] args)
{
if (args.Length == 0)
{
if (File.Exists("./ref/startupArguments.txt"))
{
var lines = await File.ReadAllLinesAsync("./ref/startupArguments.txt");
args = lines;
}
}
int len = args.Length;
if (len == 1 && args[0] == "--help")
{