This commit is contained in:
@@ -23,6 +23,12 @@ internal class Level : DBCommand
|
|||||||
|
|
||||||
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
||||||
{
|
{
|
||||||
|
if (!File.Exists(Config.GetValue<string>("LevelingSystemPath") + $"/{message.Author.Id}.dat"))
|
||||||
|
{
|
||||||
|
await context.Channel.SendMessageAsync("You are now unranked !");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var user = await Functions.ConvertFromJson<User>(Config.GetValue<string>("LevelingSystemPath") + $"/{message.Author.Id}.dat");
|
var user = await Functions.ConvertFromJson<User>(Config.GetValue<string>("LevelingSystemPath") + $"/{message.Author.Id}.dat");
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,8 +1,17 @@
|
|||||||
namespace CMD_LevelingSystem;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
|
namespace CMD_LevelingSystem;
|
||||||
|
|
||||||
|
public class DiscordUser
|
||||||
|
{
|
||||||
|
public string Username { get; set; }
|
||||||
|
public ushort DiscordTag { get; set; }
|
||||||
|
public ulong userID { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public class User
|
public class User
|
||||||
{
|
{
|
||||||
public string userID { get; set; }
|
public DiscordUser user { get; set; }
|
||||||
public int CurrentLevel { get; set; }
|
public int CurrentLevel { get; set; }
|
||||||
public long CurrentEXP { get; set; }
|
public long CurrentEXP { get; set; }
|
||||||
public long RequiredEXPToLevelUp { get; set; }
|
public long RequiredEXPToLevelUp { get; set; }
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ namespace DiscordBot
|
|||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory("./Data/Resources");
|
Directory.CreateDirectory("./Data/Resources");
|
||||||
Directory.CreateDirectory("./Data/Languages");
|
|
||||||
Directory.CreateDirectory("./Data/Plugins/Commands");
|
Directory.CreateDirectory("./Data/Plugins/Commands");
|
||||||
Directory.CreateDirectory("./Data/Plugins/Events");
|
Directory.CreateDirectory("./Data/Plugins/Events");
|
||||||
PreLoadComponents();
|
PreLoadComponents();
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Discord.WebSocket;
|
using Discord;
|
||||||
|
using Discord.WebSocket;
|
||||||
using EVE_LevelingSystem.LevelingSystemCore;
|
using EVE_LevelingSystem.LevelingSystemCore;
|
||||||
using PluginManager;
|
using PluginManager;
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
@@ -45,9 +46,9 @@ namespace EVE_LevelingSystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
user = new User() { CurrentEXP = 0, CurrentLevel = 1, RequiredEXPToLevelUp = LevelCalculator.GetNextLevelRequiredEXP(1), userID = userID };
|
user = new User { CurrentEXP = 0, CurrentLevel = 1, RequiredEXPToLevelUp = LevelCalculator.GetNextLevelRequiredEXP(1), user = new DiscordUser { DiscordTag = arg.Author.DiscriminatorValue, userID = arg.Author.Id, Username = arg.Author.Username } };
|
||||||
if (user.AddEXP()) await arg.Channel.SendMessageAsync($"{arg.Author.Mention} is now level {user.CurrentLevel}");
|
if (user.AddEXP()) await arg.Channel.SendMessageAsync($"{arg.Author.Mention} is now level {user.CurrentLevel}");
|
||||||
await Functions.SaveToJsonFile($"{Config.GetValue<string>("LevelingSystemPath")}/{userID}.dat", user);
|
await Functions.SaveToJsonFile<User>($"{Config.GetValue<string>("LevelingSystemPath")}/{userID}.dat", user);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace EVE_LevelingSystem.LevelingSystemCore
|
|||||||
|
|
||||||
internal static bool AddEXP(this User user)
|
internal static bool AddEXP(this User user)
|
||||||
{
|
{
|
||||||
if (OnWaitingList.Contains(user.userID)) 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(2, 12);
|
||||||
Int64 userXP = user.CurrentEXP;
|
Int64 userXP = user.CurrentEXP;
|
||||||
@@ -40,14 +40,14 @@ namespace EVE_LevelingSystem.LevelingSystemCore
|
|||||||
|
|
||||||
user.CurrentEXP += exp;
|
user.CurrentEXP += exp;
|
||||||
|
|
||||||
OnWaitingList.Add(user.userID);
|
OnWaitingList.Add(user.user.userID.ToString());
|
||||||
|
|
||||||
|
|
||||||
new Thread(() =>
|
new Thread(() =>
|
||||||
{
|
{
|
||||||
int minutesToWait = Level.globalSettings.TimeToWaitBetweenMessages;
|
int minutesToWait = Level.globalSettings.TimeToWaitBetweenMessages;
|
||||||
Thread.Sleep(60000 * minutesToWait);
|
Thread.Sleep(60000 * minutesToWait);
|
||||||
OnWaitingList.Remove(user.userID);
|
OnWaitingList.Remove(user.user.userID.ToString());
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,20 @@
|
|||||||
namespace EVE_LevelingSystem.LevelingSystemCore;
|
using Discord;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
|
||||||
public class User
|
namespace EVE_LevelingSystem.LevelingSystemCore
|
||||||
{
|
{
|
||||||
public string userID { get; set; }
|
public class DiscordUser
|
||||||
|
{
|
||||||
|
public string Username { get; set; }
|
||||||
|
public ushort DiscordTag { get; set; }
|
||||||
|
public ulong userID { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class User
|
||||||
|
{
|
||||||
|
public DiscordUser user { get; set; }
|
||||||
public int CurrentLevel { get; set; }
|
public int CurrentLevel { get; set; }
|
||||||
public long CurrentEXP { get; set; }
|
public long CurrentEXP { get; set; }
|
||||||
public long RequiredEXPToLevelUp { get; set; }
|
public long RequiredEXPToLevelUp { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -61,6 +61,7 @@ namespace PluginManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static async Task LoadConfig()
|
public static async Task LoadConfig()
|
||||||
|
|
||||||
{
|
{
|
||||||
string path = Functions.dataFolder + "var.dat";
|
string path = Functions.dataFolder + "var.dat";
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
|
|||||||
@@ -239,8 +239,7 @@ 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)
|
||||||
{
|
{
|
||||||
string jsonText = JsonSerializer.Serialize(Data, typeof(T), new JsonSerializerOptions { WriteIndented = true });
|
using (var s = File.OpenWrite(file)) await JsonSerializer.SerializeAsync(s, Data, typeof(T), new JsonSerializerOptions { WriteIndented = true });
|
||||||
await File.WriteAllTextAsync(file, jsonText);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user