New Command added & Leveling System update

This commit is contained in:
2022-08-17 14:19:46 +03:00
parent 1f5e5d0611
commit 8b36c086ef
7 changed files with 58 additions and 30 deletions

View File

@@ -2,18 +2,13 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Runtime.Loader;
using System.Threading;
using System.Threading.Tasks;
using Discord.WebSocket;
using DiscordBot.Discord.Core;
using PluginManager;
using PluginManager.Interfaces;
using PluginManager.Items;
using PluginManager.Online;
using PluginManager.Others;
@@ -119,22 +114,16 @@ public class Program
if (listPluginsAtStartup) consoleCommandsHandler.HandleCommand("listplugs");
#endif
Config.SaveConfig();
while (true)
{
Console.ForegroundColor = ConsoleColor.White;
#if DEBUG
//Console_Utilities.WriteColorText("&rSethBot (&yDEBUG&r) &c> ", false);
var cmd = Console.ReadLine();
if (!consoleCommandsHandler.HandleCommand(cmd!, false) && cmd.Length > 0)
Console.WriteLine("Failed to run command " + cmd);
#else
//Console_Utilities.WriteColorText("&rSethBot &c> ", false);
var cmd = Console.ReadLine();
if (!consoleCommandsHandler.HandleCommand(cmd!) && cmd.Length > 0)
Console.WriteLine("Failed to run command " + cmd);
if (!consoleCommandsHandler.HandleCommand(cmd!,
#if DEBUG
false
#endif
) && cmd.Length > 0)
Console.WriteLine("Failed to run command " + cmd);
}
}

View File

@@ -1,6 +1,8 @@
using Discord;
using Discord.WebSocket;
using EVE_LevelingSystem.LevelingSystemCore;
using PluginManager;
using PluginManager.Interfaces;
using PluginManager.Others;

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using PluginManager;
namespace EVE_LevelingSystem.LevelingSystemCore
@@ -27,14 +28,14 @@ namespace EVE_LevelingSystem.LevelingSystemCore
{
if (OnWaitingList.Contains(user.user.userID.ToString())) return false;
Random r = new Random();
int exp = r.Next(2, 12);
int exp = r.Next(Level.globalSettings.MinEXP, Level.globalSettings.MaxEXP + 1);
Int64 userXP = user.CurrentEXP;
Int64 reqEXP = user.RequiredEXPToLevelUp;
if (userXP + exp >= reqEXP)
{
user.LevelUp();
user.CurrentEXP = exp - (reqEXP - userXP);
Console.WriteLine("Level up");
//Console.WriteLine("Level up");
return true;
}
@@ -49,7 +50,7 @@ namespace EVE_LevelingSystem.LevelingSystemCore
Thread.Sleep(60000 * minutesToWait);
OnWaitingList.Remove(user.user.userID.ToString());
}
);
).Start();
return false;
}

View File

@@ -9,5 +9,7 @@ namespace EVE_LevelingSystem
public class Settings
{
public int TimeToWaitBetweenMessages { get; set; }
public int MinEXP { get; set; }
public int MaxEXP { get; set; }
}
}

View File

@@ -2,11 +2,14 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Discord.WebSocket;
using PluginManager.Interfaces;
using PluginManager.Loaders;
using PluginManager.Online;
using PluginManager.Online.Helpers;
@@ -262,6 +265,35 @@ public class ConsoleCommandsHandler
Environment.Exit(0);
}
);
AddCommand("extern", "Load an external command", "extern [pluginName]", async (args) =>
{
if (args.Length <= 1) return;
string pName = Functions.MergeStrings(args, 1);
HttpClient client = new HttpClient();
string url = (await manager.GetPluginLinkByName(pName))[1];
Stream s = await client.GetStreamAsync(url);
MemoryStream str = new MemoryStream();
await s.CopyToAsync(str);
var asmb = Assembly.Load(str.ToArray());
var types = asmb.GetTypes();
foreach (var type in types)
{
if (type.IsClass && typeof(DBEvent).IsAssignableFrom(type))
{
DBEvent instance = (DBEvent)Activator.CreateInstance(type);
instance.Start(this.client);
Console.WriteLine($"Loaded external {type.FullName}!");
}
else if (type.IsClass && typeof(DBCommand).IsAssignableFrom(type))
{
Console.WriteLine("Only events can be loaded from external sources !");
return;
}
}
});
//Sort the commands by name
commandList.Sort((x, y) => x.CommandName.CompareTo(y.CommandName));
}
@@ -309,6 +341,7 @@ public class ConsoleCommandsHandler
public bool HandleCommand(string command, bool removeCommandExecution = true)
{
Console.ForegroundColor = ConsoleColor.White;
var args = command.Split(' ');
foreach (var item in commandList.ToList())
if (item.CommandName == args[0])

View File

@@ -261,7 +261,8 @@ namespace PluginManager.Others
/// <returns></returns>
public static async Task SaveToJsonFile<T>(string file, T Data)
{
var s = File.OpenWrite(file);
File.Delete(file);
var s = File.Open(file, FileMode.OpenOrCreate);
await JsonSerializer.SerializeAsync(s, Data, typeof(T), new JsonSerializerOptions { WriteIndented = true });
s.Close();
}
@@ -276,7 +277,7 @@ namespace PluginManager.Others
{
Stream text;
if (File.Exists(input))
text = File.Open(input, FileMode.OpenOrCreate);
text = File.OpenRead(input);
else
text = new MemoryStream(Encoding.ASCII.GetBytes(input));