private void GameStateChangedHandler(object sender, GameStateChangedEventArgs e) { if (e.NewState == GameState.DISCUSSION) { var alivePlayers = AmongUsReader.getInstance().GetAlivePlayers(); foreach (var player in alivePlayers) { //TODO: will act odd if a lot of people have the same name var member = dataStore.members.First(member => member.amongUsName.Equals(player.Key, StringComparison.OrdinalIgnoreCase)); if (member != null) { muteUser(voiceChannel.Users.Where(x => x.Id == member.discordId).First(), false); } else { IEnumerable <SocketGuildUser> user = voiceChannel.Users.Where((x) => { return(x.Username.Equals(player.Key, StringComparison.OrdinalIgnoreCase)); }); if (user.Count() == 1) { muteUser(user.First(), false); } } } } else if (e.NewState == GameState.TASKS) { muteUsers(voiceChannel.Users, true); } else if (e.NewState == GameState.LOBBY) { muteUsers(voiceChannel.Users, false); } }
public Task PingAsync() { var voiceChannels = Context.Guild.VoiceChannels.Where(channel => channel.Users.Any(a => a.Id.Equals(Context.Message.Author.Id))); if (voiceChannels.Count() != 1) { return(ReplyAsync($"{Context.Message.Author.Mention} You must be connected to a voice channel before starting a game")); } ReplyAsync("connecting to local among us instance..."); Task.Factory.StartNew(() => AmongUsReader.getInstance().Run()); AmongUsReader.getInstance().GameStateChanged += GameStateChangedHandler; AmongUsReader.getInstance().PlayerChanged += PlayerChangedHandler; AmongUsReader.getInstance().JoinedLobby += JoinedLobbyHandler; AmongUsReader.getInstance().ChatMessageAdded += ChatMessageHandler; channel = Context.Channel; lobbyCreator = Context.User; voiceChannel = voiceChannels.First(); return(ReplyAsync("Sucessfully connected to local among us instance. Use `set-name {name}` to set your in game name if it is different then your discord name")); }