public async Task AuthorizeUser(IUser user) { await UserDataService.EnsureCreated(user, Context.Guild); var server = await _serverRepository.FindAsync(Context.Guild.Id, (query, _) => query .Include(s => s.ServerUsers) .Include(s => s.ServerBotRoles)); var adminRole = server.ServerBotRoles.FirstOrDefault(role => role.RoleId == (int)BotRoleLevel.Admin); var serverUser = server.ServerUsers.FirstOrDefault(usr => usr.UserId == user.Id); serverUser.Role = adminRole; await _serverRepository.SaveAllChangesAsync(); ReplyAsync("User authorized"); }
public async Task AssignItem(IUser user, [Remainder] string itemName) { UserDataService.EnsureCreated(user, Context.Guild); var server = await _serverRepository.FindAsync(Context.Guild.Id, (qry, context) => qry.Include(s => s.ServerUsers)); var items = (await _itemRepository.QueryItem(itemName)).OrderByDescending(item => item.ItemLevel).ToList(); if (!items.Any()) { await ReplyAsync($"\"{itemName}\" returned no results."); return; } var item = items.First(); if (items.Count > 1) { var selection = await _queryService.SendOptionSelectQuery( $"\"{itemName}\" yielded multiple results. Please select below", items, item => item.Name, Context.Channel, CancellationToken.None); if (selection == -1) { await ReplyAsync("Operation cancelled"); return; } item = items[selection]; } await ReplyAsync("", false, CreateItemEmbed(item)); }