public static async Task <IEnumerable <RestUserGuild> > GetUserGuilds(HttpContext context) { var access_token = await context.GetTokenAsync("access_token"); var clientConfig = new DiscordRestConfig() { LogLevel = LogSeverity.Debug, DefaultRetryMode = RetryMode.AlwaysRetry }; var client = new DiscordRestClient(clientConfig); await client.LoginAsync(TokenType.Bearer, access_token).ConfigureAwait(false); while (client.LoginState != LoginState.LoggedIn) { await Task.Delay(1); } var summaryModels = await client.GetGuildSummariesAsync().FlattenAsync().ConfigureAwait(false); var userGuilds = summaryModels; await client.LogoutAsync(); return(userGuilds); }
public async Task <(bool isVetMember, RestSelfUser user)> GetVetMember(string accessToken) { var dc = new DiscordRestClient(); await dc.LoginAsync(Discord.TokenType.Bearer, accessToken); var gs = dc.GetGuildSummariesAsync(); var isVetMember = (await gs.ToArrayAsync()).SelectMany(c => c).Any(c => c.Id == StaticSettings.LoginCheckDiscordServerId); return(isVetMember, dc.CurrentUser); }
// this has to be unique per user public async Task <DiscordUserInfo> GetAuthenticatedUserInfoAsync() { var token = await HttpContext.GetTokenAsync("Discord", "access_token"); if (token == null) { return(null); } using var client = new DiscordRestClient(); await client.LoginAsync(TokenType.Bearer, token, true); var guildSummaries = await client.GetGuildSummariesAsync().FlattenAsync(); var targetGuild = guildSummaries.FirstOrDefault(x => x.Id == GuildId); var result = new DiscordUserInfo() { Guild = targetGuild, CurrentUser = client.CurrentUser, }; return(result); }