public async Task <SocketMessage> NextMessageAsync(GuildContext context, ICriterion <SocketMessage> criterion, TimeSpan?timeout = null) { timeout = timeout ?? _defaultTimeout; var eventTrigger = new TaskCompletionSource <SocketMessage>(); async Task Handler(SocketMessage message) { var result = await criterion.JudgeAsync(context, message).ConfigureAwait(false); if (result) { eventTrigger.SetResult(message); } } (context.Client).MessageReceived += Handler; var trigger = eventTrigger.Task; var delay = Task.Delay(timeout.Value); var task = await Task.WhenAny(trigger, delay).ConfigureAwait(false); (context.Client).MessageReceived -= Handler; if (task == trigger) { return(await trigger); } else { return(null); } }
public async Task GetSecondaryStatModsGuild(string playerUserName, string modType, string resultsRows = "20") { bool rowsIsNumber = int.TryParse(resultsRows, out int rows); if (!rowsIsNumber) { await ReplyAsync($"If you want to specify how many results want, you have to put a number as third parameter! '{rows}' is not a number!"); return; } playerUserName = playerUserName.ToLower().Trim(); modType = modType.ToLower().Trim(); string loadingStr = string.Format("```{1} mods are loading...```", playerUserName, modType); var messageLoading = await ReplyAsync($"{loadingStr}"); ModValueType secondaryStatValueType = ModValueType.None; if (modType.Substring(modType.Length - 1, 1) == "%") { secondaryStatValueType = ModValueType.Percentage; modType = modType.Replace("%", ""); } else { secondaryStatValueType = ModValueType.Flat; } ModStatType secondaryStatType = (ModStatType)EnumExtensions.GetEnumFromDescription(modType, typeof(ModStatType)); if (secondaryStatType == ModStatType.None) { await ReplyAsync($"Something is wrong with your command..."); await messageLoading.DeleteAsync(); return; } //get player //var player = IResolver.Current.MongoDBRepository.GetPlayer(playerUserName).Result; var applicationSettings = new ApplicationSettings(new SettingsConfiguration()); var repoSettings = applicationSettings.GetTripleZeroRepositorySettings(); IMapper mapper = null; var context = new GuildContext(repoSettings, _cacheClient, mapper); var guild = await context.GetGuildData(playerUserName); if (guild == null) { await ReplyAsync($"I couldn't find player : {playerUserName}..."); await messageLoading.DeleteAsync(); return; } var result = await GetSpecificSecondaryModsGuild(guild, secondaryStatType, secondaryStatValueType, rows); SendSecondaryModReplyGuild(guild, secondaryStatType, secondaryStatValueType, result); await messageLoading.DeleteAsync(); }
public async Task DeleteLotteryAsync() { using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); var guild = await context.Guilds .Include(x => x.Messages) .Include(x => x.Channels) .SingleOrDefaultAsync(x => x.DBDiscordID == Context.Guild.Id.ToString()); var savedChannel = guild.GetChannel("Lottery"); var savedMessage = guild.GetMessage("LotteryMessage"); var channel = Context.Guild.GetTextChannel(savedChannel.DiscordID); await Misc.DiscordUtils.DeleteMessageAsync(channel, savedMessage.DiscordID); guild.Messages.Remove(savedMessage); await context.SaveChangesAsync(); } await ReplyAsync("Lottery deleted"); }
public async Task ChangePointDisplayAsync(ulong discordID, PointDisplay pointDisplay) { using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); var guild = await context.Guilds .AsQueryable() .SingleOrDefaultAsync(x => x.DBDiscordID == Context.Guild.Id.ToString()); if (guild is null) { await ReplyAsync("Guild was not found in the database"); return; } var user = await context.Users .AsQueryable() .SingleOrDefaultAsync(x => x.DBDiscordID == discordID.ToString() && x.Guild == guild); if (user is null) { await ReplyAsync("User not found in the database"); return; } user.PointDisplay = pointDisplay; await context.SaveChangesAsync(); } await ReplyAsync("Value changed"); }
public async Task RemoveUserAsync(ulong discordID) { using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); var guild = await context.Guilds .AsQueryable() .SingleOrDefaultAsync(x => x.DBDiscordID == Context.Guild.Id.ToString()); if (guild is null) { await ReplyAsync("Guild was not found in the database."); return; } var user = await context.Users .AsQueryable() .SingleOrDefaultAsync(x => x.DBDiscordID == discordID.ToString() && x.Guild == guild); if (user is null) { await ReplyAsync("User not found in the database."); return; } context.Remove(user); await context.SaveChangesAsync(); } await ReplyAsync("User removed"); }
public async Task UpdateRanksAsync() { using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); var guild = await context.Guilds .AsQueryable() .Include(x => x.Ranks) .SingleOrDefaultAsync(x => x.DBDiscordID == Context.Guild.Id.ToString()); if (guild is null) { await ReplyAsync("Guild was not found in the database"); return; } var users = context.Users .Include(x => x.Rank) .Where(x => x.Guild.DBDiscordID == Context.Guild.Id.ToString()) .OrderByDescending(x => x.TotalPoints) .AsAsyncEnumerable(); await ReplyAsync("Updating user ranks"); await foreach (var user in users) { if (!user.RankChanged()) { continue; } var newRank = guild.GetRank(user.TotalPoints); if (newRank is null) { await ReplyAsync($"Failed to update {user.DiscordID} rank"); continue; } user.Rank = newRank; var guildUser = Context.Guild.GetUser(user.DiscordID); if (!(await Misc.DiscordUtils.TryAddRoleAsync(guildUser, newRank)).Key) { await ReplyAsync($"Updated {user.DiscordID} rank, but failed to get guild user. Update user's roles manually"); await Task.Delay(100); continue; } await ReplyAsync($"Updated {user.DiscordID} rank"); await Task.Delay(100); } await context.SaveChangesAsync(); } await ReplyAsync("Finished updating user ranks"); }
public async Task InitializeAsync() { using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); var guilds = await context.Guilds .Include(x => x.Users) .ToListAsync(); foreach (var guild in guilds) { if (guild.Users is null || guild.Users.Count == 0) { continue; } var users = new List <IUser>(guild.Users); var guildUsers = new Dictionary <ulong, Privileges>(); foreach (var user in users) { if (guildUsers.ContainsKey(user.DiscordID)) { continue; } guildUsers.Add(user.DiscordID, user.Privileges); } entries.Add(guild.DiscordID, guildUsers); } } }
private async Task HandleCommandAsync(SocketMessage arg) { if (arg is not SocketUserMessage msg) return; if (msg.Author.Id == _client.CurrentUser.Id || msg.Author.IsBot) return; var pos = 0; var prefix = "!"; if (arg.Channel is ITextChannel channel) { await using var guildContext = new GuildContext(); var guild = guildContext.Guilds.Single(g => g.Id == channel.GuildId); prefix = guild.Prefix ?? "!"; } if (msg.HasStringPrefix(prefix, ref pos) || msg.HasMentionPrefix(_client.CurrentUser, ref pos)) { var context = new SocketCommandContext(_client, msg); var result = await _commands.ExecuteAsync(context, pos, _services, MultiMatchHandling.Best); if (!result.IsSuccess && result.Error != CommandError.UnknownCommand) { Logger.ErrorS($"Error executing command: {result.ErrorReason}"); await msg.Channel.SendMessageAsync("An unknown error has occurred."); } } }
public async Task GetPlayerAsync(IGuildUser guildUser) { using (var context = new GuildContext()) { var users = context.Users .Include(x => x.Rank) .Where(x => x.Guild.DBDiscordID == Context.Guild.Id.ToString() && (x.PointDisplay != PointDisplay.HideAll || x.PointDisplay != PointDisplay.HideTotal)) .OrderByDescending(x => x.TotalPoints) .AsAsyncEnumerable(); ProfessorMewData.Interfaces.Guild.IUser user = null; int ranking = 0; await foreach (var entry in users) { if (entry.DiscordID == guildUser.Id) { user = entry; user.GuildRanking = ranking; break; } ranking++; } if (user is null) { await ReplyAsync("User was not found in the database."); return; } var embed = EmbedUtils.CreatePlayerDataEmbed(user); await ReplyAsync(embed : embed); } }
public async Task <IUserMessage> SendPaginatedMessageAsync(GuildContext context, PaginatedMessage pager, ICriterion <SocketReaction> criterion = null) { var callback = new PaginatedMessageCallback(this, context, pager, criterion); await callback.DisplayAsync(); return(callback.Message); }
public async Task Prefix(params string[] args) { if (Guild == null) { await ReplyAsync("This command can only be used in a server channel."); return; } await using var guildContext = new GuildContext(); var guild = guildContext.Guilds.Single(g => g.Id == Guild.Id); var prefix = string.Join(" ", args); if (string.IsNullOrWhiteSpace(prefix)) { guild.Prefix = null; await guildContext.SaveChangesAsync(); await ReplyAsync("Command prefix reset to the default, `!`"); return; } guild.Prefix = prefix; await guildContext.SaveChangesAsync(); await ReplyAsync($"Command prefix changed to `{prefix}`"); }
public async Task UpdatePointLeaderboardAsync() { const int topLeaderboardCount = 10; const int monthlyLeaderboardCount = 3; using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); var guild = await context.Guilds .Include(x => x.Users) .ThenInclude(x => x.Rank) .Include(x => x.Channels) .SingleOrDefaultAsync(x => x.DBDiscordID == Context.Guild.Id.ToString()); if (guild is null) { await ReplyAsync("Guild was not found in the database"); return; } var savedChannel = guild.GetChannel("Points"); var textChannel = Context.Guild.GetTextChannel(savedChannel.DiscordID); await Misc.DiscordUtils.DeleteMessagesAsync(textChannel, 2); var playersMonthly = guild.GetUsers(PointDisplay.ShowAll, PointDisplay.HideTotal).ToList(); var playersTotal = guild.GetUsers(PointDisplay.ShowAll, PointDisplay.HideMonthly).ToList(); if (playersMonthly is not null || playersMonthly.Count > 0) { playersMonthly.RemoveNonExistingUsers(Context); playersMonthly.SetNames(Context, false); playersMonthly.Sort(delegate(ProfessorMewData.Interfaces.Guild.IUser u1, ProfessorMewData.Interfaces.Guild.IUser u2) { return(u2.MonthPoints.CompareTo(u1.MonthPoints)); }); } if (playersTotal is not null || playersTotal.Count > 0) { playersTotal.RemoveNonExistingUsers(Context); playersTotal.SetNames(Context, false); playersTotal.Sort(delegate(ProfessorMewData.Interfaces.Guild.IUser u1, ProfessorMewData.Interfaces.Guild.IUser u2) { return(u2.TotalPoints.CompareTo(u1.TotalPoints)); }); } var monthlyEmbed = EmbedUtils.CreatePointLeaderboardEmbed("The Crystal Wolves monthly leaderboard", "Here you can see the top 3 players who have earned the most points this month so far", Discord.Color.DarkBlue, playersMonthly, monthlyLeaderboardCount); var totalEmbed = EmbedUtils.CreatePointLeaderboardEmbed("The Crystal Wolves leaderboard", "Here you can see the top 10 players in our guild", Discord.Color.DarkPurple, playersTotal, topLeaderboardCount); if (monthlyEmbed is not null) { await textChannel.SendMessageAsync(embed : totalEmbed); } if (totalEmbed is not null) { await textChannel.SendMessageAsync(embed : monthlyEmbed); } } }
public async Task <IUserMessage> ReplyAndDeleteAsync(GuildContext context, string content, bool isTTS = false, Embed embed = null, TimeSpan?timeout = null, RequestOptions options = null) { timeout = timeout ?? _defaultTimeout; var message = await context.Channel.SendMessageAsync(content, isTTS, embed, options); _ = Task.Delay(timeout.Value).ContinueWith(_ => message.DeleteAsync()); return(message); }
public async Task UpdateAsync() { using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); _guilds = await context.Guilds.ToListAsync(); } }
public async Task AddRoleAsync(string roleName) { using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); var guild = await context.Guilds .Include(x => x.Roles) .Include(x => x.Ranks) .SingleOrDefaultAsync(x => x.DBDiscordID == Context.Guild.Id.ToString()); if (guild is null) { await ReplyAsync("Error"); return; } var role = guild.GetRoleToUpper(roleName); if (role is null) { await ReplyAsync("Role not found"); return; } var response = await Misc.DiscordUtils.TryAddRoleAsync(Context.User as SocketGuildUser, role); await ReplyAsync(response.Value); if (role.AddUserToDatabase) { var user = await context.Users .SingleOrDefaultAsync(x => x.DBDiscordID == Context.User.Id.ToString() && x.Guild == guild); if (user is not null) { return; } var defaultRank = guild.GetDefaultRank(); user = new User() { DiscordID = Context.User.Id, TotalPoints = 0, MonthPoints = 0, LastUpdate = DateTime.UtcNow, PointDisplay = PointDisplay.ShowAll, Privileges = Privileges.None, Rank = defaultRank, Guild = guild }; await context.AddAsync(user); await context.SaveChangesAsync(); } } }
public async Task GetPlayerDPSProfileAsync() { using (var raidContext = new RaidContext()) using (var guildContext = new GuildContext()) { await raidContext.Database.EnsureCreatedAsync(); await guildContext.Database.EnsureCreatedAsync(); var user = await raidContext.Users .Include(x => x.Records) .SingleOrDefaultAsync(x => x.DBDiscordID == Context.User.Id.ToString() && x.Guild.DBDiscordID == Context.Guild.Id.ToString()); var guildUser = await guildContext.Users .AsQueryable() .SingleOrDefaultAsync(x => x.DBDiscordID == Context.User.Id.ToString() && x.Guild.DBDiscordID == Context.Guild.Id.ToString()); if (user is null || guildUser is null) { await ReplyAsync(embed : EmbedUtils.CreatePlayerNotFoundEmbed()); return; } var benches = raidContext.RaidBenches .AsQueryable() .Where(x => x.Guild.DBDiscordID == Context.Guild.Id.ToString()) .AsAsyncEnumerable(); await user.Records.UpdateRecordStatusesAsync(benches); guildUser.AvatarUrl = guildUser.GetAvatarUrl(Context); user.AccountName = guildUser.GetName(Context); var profilePic = await guildUser.DownloadAvatarAsync(Services.GetRequiredService <HttpClient>()); System.Drawing.Image.FromStream(profilePic).Save($"{AppDomain.CurrentDomain.BaseDirectory}Data/Temp/{user.DBDiscordID}.jpg"); try { string imgPath = await RaidProfile.CreateRaidProfileImageAsync(user, $"{AppDomain.CurrentDomain.BaseDirectory}Data/Temp/{user.DBDiscordID}.jpg"); await Context.Channel.SendFileAsync(imgPath); System.IO.File.Delete(imgPath); } catch (Exception ex) { Console.WriteLine(ex.Message); var paging = new Pager <IRaidRecord>(user.Records.ToList(), 5); var records = paging.GetPage(0).ToList(); await records.UpdateRecordStatusesAsync(benches); await Context.Channel.SendMessageAsync(embed : EmbedUtils.CreateDPSProfileEmbed(records, 1, paging.PageCount)); } } }
public async Task GetPlayerProfileAsync() { using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); var users = context.Users .Include(x => x.Rank) .Where(x => x.Guild.DBDiscordID == Context.Guild.Id.ToString() && (x.PointDisplay != PointDisplay.HideAll || x.PointDisplay != PointDisplay.HideTotal)) .OrderByDescending(x => x.TotalPoints) .AsAsyncEnumerable(); ProfessorMewData.Interfaces.Guild.IUser user = null; int ranking = 0; await foreach (var entry in users) { if (entry.DiscordID == Context.User.Id) { user = entry; user.GuildRanking = ranking; break; } ranking++; } if (user is null) { await ReplyAsync("User was not found in the database."); return; } user.AvatarUrl = user.GetAvatarUrl(Context); user.Name = user.GetName(Context); var profilePicture = await user.DownloadAvatarAsync(Services.GetRequiredService <HttpClient>()); //string path = PointsProfileOLD.CreatePlayerProfile(user); //try //{ // await Context.Channel.SendFileAsync(path); //} //catch (Exception) //{ // await Context.Channel.SendMessageAsync(embed: EmbedUtils.CreatePointsProfileEmbed(user)); //} try { await Context.Channel.SendFileAsync(await PointsProfile.CreateProfileImage(user, profilePicture)); } catch { await Context.Channel.SendMessageAsync(embed : EmbedUtils.CreatePointsProfileEmbed(user)); } } }
public async Task InitializeAsync() { await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services); using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); _guilds = await context.Guilds.ToListAsync(); } }
public PaginatedMessageCallback(InteractiveService interactive, GuildContext context, PaginatedMessage pager, ICriterion <SocketReaction> criterion = null) { Interactive = interactive; Context = context; Criterion = criterion ?? new EmptyCriterion <SocketReaction>(); _pager = pager; _pages = _pager.Pages.Count(); }
private async Task OnGuildAvailable(SocketGuild arg) { await using var db = new GuildContext(); if (db.Guilds.Any(guild => guild.Id == arg.Id)) { return; } db.Add(new Guild {Id = arg.Id}); await db.SaveChangesAsync(); }
public async Task <bool> JudgeAsync(GuildContext context, T parameter) { foreach (var criterion in _critiera) { var result = await criterion.JudgeAsync(context, parameter).ConfigureAwait(false); if (!result) { return(false); } } return(true); }
public async Task TestExceptionAsync() { using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); /*var guild = await context.Guilds * .Include(x => x.Roles) * .Include(x => x.Ranks) * .SingleOrDefaultAsync(x => x.DBDiscordID == Context.Guild.Id.ToString()); * guild.TestException();*/ } }
public Task <SocketMessage> NextMessageAsync(GuildContext context, bool fromSourceUser = true, bool inSourceChannel = true, TimeSpan?timeout = null) { var criterion = new Criteria <SocketMessage>(); if (fromSourceUser) { criterion.AddCriterion(new EnsureSourceUserCriterion()); } if (inSourceChannel) { criterion.AddCriterion(new EnsureSourceChannelCriterion()); } return(NextMessageAsync(context, criterion, timeout)); }
public async Task InitializeAsync() { using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); _guilds = await context.Guilds .Include(x => x.Channels) .Include(x => x.Users) .ToListAsync(); } SetupTimer(); if (!_timer.Enabled) { _timer.Start(); } }
public async Task CreateNewUserAsync(ulong discordID) { using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); var guild = await context.Guilds .Include(x => x.Ranks) .SingleOrDefaultAsync(x => x.DBDiscordID == Context.Guild.Id.ToString()); if (guild is null) { await ReplyAsync("Guild not found.\nRun startup command first."); return; } var user = await context.Users .AsQueryable() .SingleOrDefaultAsync(x => x.DBDiscordID == discordID.ToString() && x.Guild == guild); if (user is not null) { await ReplyAsync("User already exists."); return; } user = new User() { DiscordID = discordID, TotalPoints = 0, MonthPoints = 0, LastUpdate = DateTime.UtcNow, PointDisplay = PointDisplay.ShowAll, Privileges = Privileges.None, Rank = guild.GetDefaultRank(), Guild = guild }; await context.AddAsync(user); await context.SaveChangesAsync(); } await ReplyAsync("User added"); }
public async Task MainAsync() { applicationSettings = new ApplicationSettings(new SettingsConfiguration()); var repoSettings = applicationSettings.GetTripleZeroRepositorySettings(); IMapper mapper = new MappingConfiguration().GetConfigureMapper(); // var aaaa = new MongoDBContext(repoSettings.MongoDBSettings); //var repo = new GuildConfigRepository(new MongoDBConnectionHelper(repoSettings.MongoDBSettings),mapper); //var result = repo.GetAll(); //var repo = new PlayerRepository(new MongoDBConnectionHelper(repoSettings.MongoDBSettings), mapper); //var result = repo.Get("saf"); //var context = new PlayerContext(repoSettings, new MemoryCache(new MemoryCacheOptions()), mapper); //var player = context.GetPlayerData(462747278); var guildContext = new GuildContext(repoSettings, new MemoryCache(new MemoryCacheOptions()), mapper); var guild = guildContext.GetGuildData(462747278); /////////////initialize autofac //autoFacContainer = AutofacConfig.ConfigureContainer(); //using (var scope = autoFacContainer.BeginLifetimeScope()) //{ // applicationSettings = scope.Resolve<ApplicationSettings>(); // var appSettings = applicationSettings.GetTripleZeroBotSettings(); // playerContext = scope.Resolve<IPlayerContext>(); // //memoryCache = scope.Resolve<IMemoryCache>(); // //var aaa = scope.Resolve<Authentication>(); //} //var result = playerContext.GetPlayerData(124141); //var cache = new MemoryCache(new MemoryCacheOptions()); //var a = new Authentication(new TripleZero.Repository.SWGoHHelp.Dto.UserSettings() {username="******", password="******", client_id="abc", client_secret="123" }, cache ); //var resulta = a.GetToken(); //var b = new Authentication(new TripleZero.Repository.SWGoHHelp.Dto.UserSettings() { username = "******", password = "******", client_id = "abc", client_secret = "123" }, cache); //var resultb = a.GetToken(); //var resultc = b.GetToken(); }
public async Task GetWinnerAsync([Remainder] string prizes) { if (string.IsNullOrEmpty(prizes)) { await ReplyAsync("Error"); return; } var splitPrizes = new List <string>(prizes.Split(',')); using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); var guild = await context.Guilds .Include(x => x.Channels) .Include(x => x.Links) .Include(x => x.LotteryUsers) .ThenInclude(x => x.User) .SingleOrDefaultAsync(x => x.DBDiscordID == Context.Guild.Id.ToString()); if (guild is null) { await ReplyAsync("Guild not found."); return; } var users = guild.LotteryUsers.ToList(); var savedChannel = guild.GetChannel("Lottery"); var channel = Context.Guild.GetTextChannel(savedChannel.DiscordID); var savedLink = guild.GetLink("LotteryWinner"); var lotteryGame = new LotteryGame(users, splitPrizes); var winners = lotteryGame.GetWinners(splitPrizes.Count, true); winners.ForEach(x => x.Name = x.User.GetName(Context)); await channel.SendMessageAsync(embed : EmbedUtils.CreateWinnerEmbed(winners, splitPrizes, savedLink.URL)); guild.LotteryUsers.Clear(); await context.SaveChangesAsync(); } }
public async Task ChangePermissionsAsync(IGuildUser guildUser, Privileges privileges) { using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); var guild = await context.Guilds .AsQueryable() .SingleOrDefaultAsync(x => x.DBDiscordID == Context.Guild.Id.ToString()); if (guild is null) { await ReplyAsync("Guild was not found in the database"); return; } var user = await context.Users .AsQueryable() .SingleOrDefaultAsync(x => x.DBDiscordID == guildUser.Id.ToString() && x.Guild == guild); var executingUser = await context.Users .AsQueryable() .SingleOrDefaultAsync(x => x.DBDiscordID == Context.User.Id.ToString() && x.Guild == guild); if (user is null || executingUser is null) { await ReplyAsync("User not found in the database"); return; } if (executingUser.Privileges < privileges) { await ReplyAsync("Insufficient permissions"); return; } user.Privileges = privileges; await context.SaveChangesAsync(); } await Services.GetRequiredService <Services.UserPrivilegeService>().UpdateAsync(); await ReplyAsync("Value changed"); }
private async Task CommandExecutedResultAsync(IResult result, GuildContext context) { if (result.IsSuccessful) { return; } switch (result) { case ExecutionFailedResult _: case CommandResult _: return; case CommandNotFoundResult _: await context.Message.AddReactionAsync(new Emoji("\u2754")); break; } }
public async Task ReducePointsAsync(ulong discordID, int points, bool reduceMonthly = true) { using (var context = new GuildContext()) { await context.Database.EnsureCreatedAsync(); var guild = await context.Guilds .Include(x => x.Ranks) .Include(x => x.Links) .SingleOrDefaultAsync(x => x.DBDiscordID == Context.Guild.Id.ToString()); if (guild is null) { await ReplyAsync("Guild was not found in the database."); return; } var user = await context.Users .Include(x => x.Rank) .SingleOrDefaultAsync(x => x.DBDiscordID == discordID.ToString() && x.Guild == guild); if (user is null) { await ReplyAsync("User was not found in the database"); return; } user.ReducePoints(points, reduceMonthly); if (user.RankChanged()) { var newRank = guild.GetRank(user.TotalPoints); var link = guild.GetLink("Rankdown"); user.Rank = newRank; var guildUser = Context.Guild.GetUser(user.DiscordID); await guildUser.SendMessageAsync(embed : EmbedUtils.CreateRankDownEmbed(user, link.URL)); await ReplyAsync((await Misc.DiscordUtils.TryAddRoleAsync(guildUser, newRank)).Value); } await context.SaveChangesAsync(); } await ReplyAsync($"<@{discordID}> lost {points} points"); }