private async Task ProcessFollowedChannelMessageAsync(SocketMessage message, CancellationToken cancellationToken = default) { if (!(message is SocketUserMessage msg)) { return; } // attempt to get nickname, but use username if unavailable string authorName = message.Author.Username; SocketGuild guild = (msg.Channel as SocketGuildChannel)?.Guild; if (guild != null) { SocketGuildUser guildUser = await guild.GetGuildUserAsync(message.Author).ConfigureAwait(false); if (guildUser != null) { authorName = guildUser.Nickname ?? authorName; } } // trim to # int hashIndex = authorName.IndexOf('#'); string gameName = hashIndex < 0 ? authorName : authorName.Remove(hashIndex).TrimEnd(); _log.LogTrace("Received followed channel webhook for game {GameName}", gameName); await PingGameAsync(message, gameName, cancellationToken); }
private async ValueTask <bool> IsAuthorizedAsync(SocketCommandContext context, GameServer server) { if (server.IsPublic) { return(true); } if (server.AuthorizedUserIDs.Contains(context.User.Id)) { return(true); } // scan server roles foreach (ulong guildID in _gameServersOptions.RoleScanGuildIDs) { SocketGuild guild = context.Client.GetGuild(guildID); if (guild == null) { continue; } SocketGuildUser guildUser = await guild.GetGuildUserAsync(context.User.Id).ConfigureAwait(false); if (guildUser == null) { continue; } if (guildUser.Roles.Any(role => server.AuthorizedRoleIDs.Contains(role.Id))) { return(true); } } return(false); }