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

@@ -12,11 +12,11 @@
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>none</DebugType> <DebugType>none</DebugType>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>none</DebugType> <DebugType>none</DebugType>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

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

View File

@@ -1,6 +1,8 @@
using Discord; using Discord;
using Discord.WebSocket; using Discord.WebSocket;
using EVE_LevelingSystem.LevelingSystemCore; using EVE_LevelingSystem.LevelingSystemCore;
using PluginManager; using PluginManager;
using PluginManager.Interfaces; using PluginManager.Interfaces;
using PluginManager.Others; using PluginManager.Others;
@@ -9,8 +11,8 @@ namespace EVE_LevelingSystem
{ {
internal class Level : DBEvent internal class Level : DBEvent
{ {
public string name => "Leveling System Event Handler"; public string name => "Leveling System Event Handler";
public string description => "The Leveling System Event Handler"; public string description => "The Leveling System Event Handler";
internal static Settings globalSettings = new(); internal static Settings globalSettings = new();
@@ -39,7 +41,7 @@ namespace EVE_LevelingSystem
{ {
if (arg.Author.IsBot || arg.IsTTS || arg.Content.StartsWith(Config.GetValue<string>("prefix"))) return; if (arg.Author.IsBot || arg.IsTTS || arg.Content.StartsWith(Config.GetValue<string>("prefix"))) return;
string userID = arg.Author.Id.ToString(); string userID = arg.Author.Id.ToString();
User user; User user;
if (File.Exists($"{Config.GetValue<string>("LevelingSystemPath")}/{userID}.dat")) if (File.Exists($"{Config.GetValue<string>("LevelingSystemPath")}/{userID}.dat"))
{ {
user = await Functions.ConvertFromJson<User>(Config.GetValue<string>("LevelingSystemPath")! + $"/{userID}.dat"); user = await Functions.ConvertFromJson<User>(Config.GetValue<string>("LevelingSystemPath")! + $"/{userID}.dat");

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using PluginManager; using PluginManager;
namespace EVE_LevelingSystem.LevelingSystemCore namespace EVE_LevelingSystem.LevelingSystemCore
@@ -18,7 +19,7 @@ namespace EVE_LevelingSystem.LevelingSystemCore
internal static void LevelUp(this User user) internal static void LevelUp(this User user)
{ {
user.CurrentEXP = 0; user.CurrentEXP = 0;
user.RequiredEXPToLevelUp = GetNextLevelRequiredEXP(user.CurrentLevel); user.RequiredEXPToLevelUp = GetNextLevelRequiredEXP(user.CurrentLevel);
user.CurrentLevel++; user.CurrentLevel++;
} }
@@ -26,15 +27,15 @@ namespace EVE_LevelingSystem.LevelingSystemCore
internal static bool AddEXP(this User user) internal static bool AddEXP(this User user)
{ {
if (OnWaitingList.Contains(user.user.userID.ToString())) return false; if (OnWaitingList.Contains(user.user.userID.ToString())) return false;
Random r = new Random(); 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 userXP = user.CurrentEXP;
Int64 reqEXP = user.RequiredEXPToLevelUp; Int64 reqEXP = user.RequiredEXPToLevelUp;
if (userXP + exp >= reqEXP) if (userXP + exp >= reqEXP)
{ {
user.LevelUp(); user.LevelUp();
user.CurrentEXP = exp - (reqEXP - userXP); user.CurrentEXP = exp - (reqEXP - userXP);
Console.WriteLine("Level up"); //Console.WriteLine("Level up");
return true; return true;
} }
@@ -49,7 +50,7 @@ namespace EVE_LevelingSystem.LevelingSystemCore
Thread.Sleep(60000 * minutesToWait); Thread.Sleep(60000 * minutesToWait);
OnWaitingList.Remove(user.user.userID.ToString()); OnWaitingList.Remove(user.user.userID.ToString());
} }
); ).Start();
return false; return false;
} }

View File

@@ -9,5 +9,7 @@ namespace EVE_LevelingSystem
public class Settings public class Settings
{ {
public int TimeToWaitBetweenMessages { get; set; } 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.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord.WebSocket; using Discord.WebSocket;
using PluginManager.Interfaces;
using PluginManager.Loaders; using PluginManager.Loaders;
using PluginManager.Online; using PluginManager.Online;
using PluginManager.Online.Helpers; using PluginManager.Online.Helpers;
@@ -262,6 +265,35 @@ public class ConsoleCommandsHandler
Environment.Exit(0); 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 //Sort the commands by name
commandList.Sort((x, y) => x.CommandName.CompareTo(y.CommandName)); commandList.Sort((x, y) => x.CommandName.CompareTo(y.CommandName));
} }
@@ -309,6 +341,7 @@ public class ConsoleCommandsHandler
public bool HandleCommand(string command, bool removeCommandExecution = true) public bool HandleCommand(string command, bool removeCommandExecution = true)
{ {
Console.ForegroundColor = ConsoleColor.White;
var args = command.Split(' '); var args = command.Split(' ');
foreach (var item in commandList.ToList()) foreach (var item in commandList.ToList())
if (item.CommandName == args[0]) if (item.CommandName == args[0])

View File

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