public async Task AddXp(CommandContext ctx, [Description("Mention or use member Id.")] DiscordMember member, [Description("Amount of Xp to add or take away (negative to take).")] int XpNum) { Profile profile = await _profileService.GetOrCreateProfileAsync(ctx.Member.Id, ctx.Guild.Id); GrantXpViewModel viewModel = await _experienceService.GrantXpAsync(member.Id, ctx.Guild.Id, XpNum).ConfigureAwait(false); if (!viewModel.LevelledUp) { return; } if (profile.QuietMode == true) { return; } var levelUpEmbed = new DiscordEmbedBuilder { Title = $"{member.DisplayName} Is Now Level {viewModel.Profile.Level}", Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url = member.AvatarUrl }, Color = member.Color }; levelUpEmbed.WithFooter("w!togglenotifications to hide In future."); await ctx.Channel.SendMessageAsync(embed : levelUpEmbed).ConfigureAwait(false); }
public async Task earnxp(CommandContext ctx) { int XpNum = 1; DiscordMember member = ctx.Member; Profile profile = await _profileService.GetOrCreateProfileAsync(ctx.Member.Id, ctx.Guild.Id); GrantXpViewModel viewModel = await _experienceService.GrantXpAsync(member.Id, ctx.Guild.Id, XpNum).ConfigureAwait(false); Console.WriteLine($"{ctx.Member.Username} earned {XpNum} Xp."); if (!viewModel.LevelledUp) { return; } var json = string.Empty; using (var fs = File.OpenRead("config.json")) using (var sr = new StreamReader(fs, new UTF8Encoding(false))) json = sr.ReadToEnd(); var configJson = JsonConvert.DeserializeObject <ConfigJson>(json); int goldperlevelup = configJson.goldperlevelup; await _goldService.GrantGoldAsync(ctx.Member.Id, ctx.Guild.Id, goldperlevelup); if (profile.QuietMode == true) { return; } var levelUpEmbed = new DiscordEmbedBuilder { Title = $"{ctx.Member.DisplayName} Is Now Level {viewModel.Profile.Level}", Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail { Url = ctx.Member.AvatarUrl }, Color = ctx.Member.Color }; if (goldperlevelup > 0) { levelUpEmbed.WithDescription($"+ {goldperlevelup} :moneybag:"); } levelUpEmbed.WithFooter("`w!profile togglenotifications` to hide In future."); await ctx.Channel.SendMessageAsync(embed : levelUpEmbed).ConfigureAwait(false); }
private async Task GetProfileToDisplayAsync(CommandContext ctx, ulong memberId) { Profile profile = await _profileService.GetOrCreateProfileAsync(memberId, ctx.Guild.Id).ConfigureAwait(false); DiscordMember member = ctx.Guild.Members[profile.DiscordId]; var profileEmbed = new DiscordEmbedBuilder { Title = $"{member.DisplayName}'s Profile", ThumbnailUrl = member.AvatarUrl }; profileEmbed.AddField("Level", profile.Level.ToString()); profileEmbed.AddField("Xp", profile.Xp.ToString()); profileEmbed.AddField("Gold", profile.Gold.ToString()); if (profile.Items.Count > 0) { profileEmbed.AddField("Items", string.Join(", ", profile.Items.Select(x => x.Item.Name))); } await ctx.Channel.SendMessageAsync(embed : profileEmbed).ConfigureAwait(false); GrantXpViewModel viewModel = await _experienceService.GrantXpAsync(memberId, ctx.Guild.Id, 1).ConfigureAwait(false); if (!viewModel.LevelledUp) { return; } var levelUpEmbed = new DiscordEmbedBuilder { Title = $"{member.DisplayName} Is Now Level {viewModel.Profile.Level}", ThumbnailUrl = member.AvatarUrl }; await ctx.Channel.SendMessageAsync(embed : levelUpEmbed).ConfigureAwait(false); }