public Modules() { SaveModule = new SaveModule(this, "UserData.json"); DataModule = new DataModule(this); PunishmentModule = new PunishmentModule(this); TokenModule = new TokenModule(this); UserModule = new UserModule(this); XPModule = new XPModule(this); }
private async Task PunishmentInternal(CommandContext ctx) { using var context = new DiscordContext(); var user = await UserExtension.GetUser(ctx.Message.Author.Id); var settings = UserSetting.GetAllSettings(Convert.ToInt64(ctx.User.Id), context).ToDictionary(setting => (UserSetting.SettingID)setting.SettingId); var items = await WheelItemExtension.GetUserItemsAsync(user.UserId, context); var punishmentModules = PunishmentModule.GetAll(settings, items.ToList()); var sumChances = punishmentModules.Sum(cModule => cModule.Chance); var chanceValue = Helpers.RandomGenerator.RandomInt(0, sumChances); int cChance = 0; PunishmentModule module = null; DiscordEmbed embed = null; foreach (var cModule in punishmentModules) { cChance += cModule.Chance; if (chanceValue < cChance) { module = cModule; break; } } if (module == null) { DiscordEmbedBuilder builder = new DiscordEmbedBuilder() { Title = "No suitable punishment found :(", Description = "Please set up your preferences with ``//settings setup``. You should at least enable cbt and set up some bondage gear." }; await ctx.RespondAsync(embed : builder.Build()); return; } await module.Generate(); embed = module.Embed; if (module.WheelLockTime != null && user.LockTime <= DateTime.Now) { user.LockTime += module.WheelLockTime; var builder = new DiscordEmbedBuilder(embed); builder.Description += " You are not allowed to re-roll until then."; embed = builder.Build(); } if (module.WheelLockTime != null && user.DenialTime <= DateTime.Now) { user.DenialTime += module.DenialTime; } await ctx.RespondAsync(embed : embed); await context.SaveChangesAsync(); }