public async Task DelDM(int msgcount) { IDMChannel dm = await Context.User.GetOrCreateDMChannelAsync(); IEnumerable <IMessage> msgs = dm.GetMessagesAsync(msgcount).FlattenAsync().Result; foreach (IMessage msg in msgs) { await dm.DeleteMessageAsync(msg); } IEmote emote = new Emoji("✅"); await Context.Message.AddReactionAsync(emote); }
private async Task DisplayPlayer(Player player) { try { // Get the channel for this adventure.. SocketUser user = DiscordSocketClient.GetUser(Convert.ToUInt64(player.Id)); IDMChannel channel = await user.GetOrCreateDMChannelAsync(); // Get the adventureMessage that we will update. IUserMessage playerSheetMessage; // If we were passed the "RegenerateMessages" flag set to true, or if there is no PlayerSheetMessage, then create a new adventureMessage. if (player.RegenerateMessage || player.PlayerSheetMessage == 0) { playerSheetMessage = await channel.SendMessageAsync("<PLAYER SHEET MESSAGE>") as IUserMessage; } // If we were passed the "RegenerateMessages" flag set to false, then retrieve the existing adventureMessage. else { playerSheetMessage = await channel.GetMessageAsync(player.PlayerSheetMessage) as IUserMessage; } // Alter the messages to now have new status updates. EmbedBuilder embedBuilder = new EmbedBuilder(); embedBuilder.Color = Color.Blue; string adventureHeader = $"PLAYER SHEET"; embedBuilder.Title = adventureHeader; if (player.GameStatus == Player.PlayerGameStatus.Adventure) { double healthTicksRaw = player.Health / (double)player.MaxHealth; int healthTicks = 0; for (int i = 1; i < BarDisplaySize + 1; i++) { if (healthTicksRaw < (i / (double)BarDisplaySize)) { break; } healthTicks += 1; } string healthBar = "["; for (int i = 0; i < healthTicks; i++) { healthBar += "+"; } for (int i = 0; i < BarDisplaySize - healthTicks; i++) { healthBar += "-"; } healthBar += "]"; double manaTicksRaw = player.Mana / (double)Player.MaxMana; int manaTicks = 0; for (int i = 1; i < BarDisplaySize + 1; i++) { if (manaTicksRaw < (i / (double)BarDisplaySize)) { break; } manaTicks += 1; } string manaBar = "["; for (int i = 0; i < manaTicks; i++) { manaBar += "+"; } for (int i = 0; i < BarDisplaySize - manaTicks; i++) { manaBar += "-"; } manaBar += "]"; embedBuilder.AddField("Class", player.Class == null ? "NOT SET!" : player.Class.ToString()); embedBuilder.AddField("Health Points", $"{player.Health}/{player.MaxHealth} {healthBar}"); embedBuilder.AddField("Mana Points", $"{player.Mana}/{Player.MaxMana} {manaBar}"); string timePassed = (player.AdventureJoinTime == null) ? "" : (DateTime.UtcNow - player.AdventureJoinTime.Value).ToString(@"mm\:ss"); embedBuilder.AddField("Status", $"On Adventure ({timePassed})"); } else if (player.GameStatus == Player.PlayerGameStatus.Idle) { embedBuilder.AddField("Class", player.Class == null ? "NOT SET!" : player.Class.ToString()); embedBuilder.AddField("Health Points", $"{player.MaxHealth}/{player.MaxHealth}"); embedBuilder.AddField("Mana Points", $"{Player.MaxMana}/{Player.MaxMana}"); embedBuilder.AddField("Status", "Idle"); } else { throw new Exception("Invalid Player Game Status!"); } await playerSheetMessage.ModifyAsync(m => { m.Content = ""; m.Embed = embedBuilder.Build(); }); // If we were passed the "RegenerateMessages" flag set to true, or if there was no old PlayerSheetMessage, then delete old adventureMessage if possible. // Then, toggle the "RegenerateMessages" flag to false, and set the new adventureMessage on the Adventure. if (player.RegenerateMessage || player.PlayerSheetMessage == 0) { if (player.PlayerSheetMessage != 0) { await channel.DeleteMessageAsync(await channel.GetMessageAsync(player.PlayerSheetMessage)); } await PlayersRepository.SetNewChannelsForMessages ( playerId : player.Id, playerSheetMessage : playerSheetMessage.Id ); } } catch (Exception e) { Console.WriteLine(e); } }