public async Task CompleteQuest(CommandContext ctx) { try { using var db = new LiteDatabase(@"Sanchez.db"); var userCollection = db.GetCollection <Membre>("Utilisateurs"); var author = ctx.Message.Author; var embed = new DiscordEmbedBuilder { Color = DiscordColor.Gold, Description = "Ajoute la réaction correspondant à la quête que tu as accomplie", ThumbnailUrl = ctx.Message.Author.AvatarUrl, Title = "QUETE ACCOMPLIE !", }; if (userCollection.Exists(Query.Where("DiscordId", _value => (ulong)_value.AsInt64 == author.Id))) { var membre = userCollection .Include((x => x.ActiveQuest)) .FindOne(x => x.DiscordId == ctx.Message.Author.Id); if (membre.ActiveQuest.Count != 0) { var questId = new int[5]; var iterator = 0; foreach (var quete in membre.ActiveQuest) { embed.AddField((iterator + 1).ToString(), quete.Name, false); questId[iterator] = quete.Id; iterator++; } var embedMessage = await ctx.Channel.SendMessageAsync(embed : embed).ConfigureAwait(false); DiscordEmoji[] emojis = { DiscordEmoji.FromName(ctx.Client, ":one:"), DiscordEmoji.FromName(ctx.Client, ":two:"), DiscordEmoji.FromName(ctx.Client, ":three:"), DiscordEmoji.FromName(ctx.Client, ":four:"), DiscordEmoji.FromName(ctx.Client, ":five:"), }; for (var i = 0; i < iterator; i++) { await embedMessage.CreateReactionAsync(emojis[i]).ConfigureAwait(false); } var interactivity = ctx.Client.GetInteractivity(); var result = await interactivity.WaitForReactionAsync( x => x.Message == embedMessage && x.User == ctx.User).ConfigureAwait(false); for (var i = 0; i < iterator; i++) { if (result.Result.Emoji == emojis[i]) { membre.Experience += membre.ActiveQuest[i].ExperienceReward; membre.QuestCompleted += 1; var completionEmbed = new DiscordEmbedBuilder { Color = DiscordColor.Gold, ThumbnailUrl = ctx.Member.AvatarUrl, Title = "Félicitations " + ctx.Member.Username + " !", }; completionEmbed.AddField("Nom de la quête", membre.ActiveQuest[i].Name, true); completionEmbed.AddField("Expérience gagnée", membre.ActiveQuest[i].ExperienceReward.ToString(), true); completionEmbed.AddField("Récompense spéciale", membre.ActiveQuest[i].SpecialReward, true); await embedMessage.DeleteAsync().ConfigureAwait(false); await ctx.Channel.SendMessageAsync(embed : completionEmbed).ConfigureAwait(false); membre.ActiveQuest.RemoveAll(quest => quest.Id == questId[i]); await UtilsCommands.LevelUp(ctx, membre); userCollection.Update(membre); } } } else { await ctx.Channel .SendMessageAsync("Tu n'as aucune quête en cours !") .ConfigureAwait(false); } } else { await ctx.Channel .SendMessageAsync("Tu dois d'abord accepter une quête " + "ou rendre un devoir pour avoir accès à cette commande !") .ConfigureAwait(false); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
public async Task Farm(CommandContext ctx, [Description("Type de votre devoir.\n Y'a une grande liste épinglée dans le channel #farm")] params string[] _type ) { var homeworkName = _type.Aggregate(string.Empty, (current, mot) => current + mot).ToLower(); if (!homeworks.ContainsKey(homeworkName)) { var otherString = string.Join(' ', _type); var m = await ctx.Channel.SendMessageAsync( $"{otherString} ne correspond à aucun type de devoir !\nUtilises ``s!help farm`` pour obtenir de l'aide !"); await Task.Delay(5000); await ctx.Message.DeleteAsync(); await m.DeleteAsync(); return; } using var db = new LiteDatabase(@"Sanchez.db"); try { var _member = ctx.Message.Author; var collection = db.GetCollection <Membre>("Utilisateurs"); var devoir = homeworks[homeworkName]; var xpGained = devoir.Xp; collection.EnsureIndex("DiscordId", true); Membre membre; if (collection.Exists(Query.Where("DiscordId", _value => (ulong)_value.AsInt64 == _member.Id))) { membre = collection.FindOne(x => x.DiscordId == _member.Id); membre.Experience += xpGained; membre.DevoirRendu++; await UtilsCommands.LevelUp(ctx, membre); } else { membre = new Membre { DiscordId = _member.Id, Username = _member.Username, Experience = xpGained, Prestige = 0, DevoirRendu = 1, Niveau = 1, Or = 0, ActiveQuest = new List <Quete>(), QuestCompleted = 0, DefiReussi = 0, DefiRate = 0, DonjonReussi = 0 }; } collection.Upsert(membre); await ctx.Channel .SendMessageAsync($"Bien joué {ctx.Message.Author.Username} ! Tu viens de gagner {xpGained} xp !\nTu es maintenant à {membre.Experience} !"); } catch (LiteDB.LiteException ex) { Console.Write(ex.ToString()); } }