public async Task GetPeepsFromVoice() { EmbedBuilder _embed = new(); IVoiceChannel s = (Context.User as IVoiceState).VoiceChannel; if (s != null) { _embed.Color = Color.Teal; _embed.Description += DateTime.Now.ToString("yy/MM/dd hh:mm tt\n"); _embed.Description += $"Channel: {s.Name}\n\n"; await foreach (var item in s.GetUsersAsync()) { foreach (SocketGuildUser usr in item) { _embed.Description += $"{usr.Nickname}\n"; } } } else { _embed.Color = Color.Orange; _embed.Description += "enter a voice chat and reuse command"; } await ReplyAsync(embed : _embed.Build()); }
public async Task Roulette() { var audioClient = await audio.ConnectAudio(Context); if (audioClient == null) { return; } SocketGuildUser user = Context.User as SocketGuildUser; IVoiceChannel chan = user.VoiceChannel; IEnumerable <IGuildUser> boysArr = await chan.GetUsersAsync().FlattenAsync(); IGuildUser[] boys = boysArr.ToArray(); Random random = new Random(); int randomNumber = random.Next(0, boys.Length); audio.SendAsync(audioClient, config.GetSongDir() + @"\jaws.mp3"); await Task.Delay(10000); await Context.Channel.SendMessageAsync(boys[randomNumber].Username); await boys[randomNumber].ModifyAsync(change => { change.Channel = Context.Guild.AFKChannel; }); await Context.Guild.AFKChannel.ConnectAsync(); }
public async Task <TriviaServiceResult> StartQuiz() { if (_audioConnection == null || _audioConnection.ConnectionState != ConnectionState.Connected) { _audioConnection = await _channel.ConnectAsync(); } var channelMembers = await _channel.GetUsersAsync().FlattenAsync(); foreach (IGuildUser member in channelMembers) { if (!member.IsBot) { _mapPlayersToScores.Add(member.Id, 0); _mapIdsToUsernames.Add(member.Id, member.Username); } } EmbedBuilder builder = new EmbedBuilder(); builder.WithTitle("Starting Music Quiz!"); builder.WithColor(kEmbedColor); builder.WithDescription("Get ready! There are 15 songs, you have 30 seconds to guess either the singer/band or the name of the song. Good Luck! You can end the quiz using the end-trivia command"); await(_textChannel as ISocketMessageChannel).SendMessageAsync("", false, builder.Build()); PlaySnippet(_questions[0]); return(TriviaServiceResult.Success); }
public async Task Move(IVoiceChannel src, IVoiceChannel dst) { var k = await src.GetUsersAsync().FlattenAsync(); foreach (IGuildUser u in k) { await u.ModifyAsync(x => { x.Channel = new Optional <IVoiceChannel>(dst); }); await ReplyAsync(u.Username + ": :ok_hand:"); } }
public async Task <bool> CheckIfConnectedToChannelAsync(IMessageChannel channel, IVoiceChannel voicechannel) { var users = await voicechannel.GetUsersAsync(CacheMode.AllowDownload).Flatten(); if (users.ToList().Count > 1) { return(true); } return(false); }
private async void CheckChannelState(object state) { if (voiceChannel != null && (await voiceChannel.GetUsersAsync().Flatten()).Count() < 2) { await Close(); timer.Dispose(); timer = null; } }
public async Task <bool> CanJoinChannel(IVoiceChannel voiceChannel) { var permissions = await GetPermissionsAsync(voiceChannel); if (voiceChannel.UserLimit.HasValue) { var userCount = await voiceChannel.GetUsersAsync().CountAsync(); return(permissions.Connect && (voiceChannel.UserLimit < userCount + 1)); } return(permissions.Connect); }
private async Task ListenToUsersAsync() { var users = await _voiceChannel.GetUsersAsync().ToListAsync(); foreach (var v in users[0]) { //only play users audio data if (!v.IsBot) { var socketUser = v as SocketGuildUser; var userAudioStream = socketUser.AudioStream; _ = Task.Run(() => { ListenUserAsync(userAudioStream, socketUser.Id); }); } } }
private async void CheckVoiceChannelState(object state) { IVoiceChannel voiceChannel; IVoiceChannel channel = voiceChannel = (state as IVoiceChannel); if (voiceChannel != null && (await channel.GetUsersAsync().FlattenAsync()).Count() < 2) { await LeaveAudioAsync(channel.Guild); if (VoiceChannelTimer != null) { VoiceChannelTimer.Dispose(); VoiceChannelTimer = null; } } }
public async Task UpdateVC(IVoiceChannel VC) { int watchinPos = VC.Guild.GetVoiceChannelsAsync().Result.Where(chan => chan.Name == "Watchin").FirstOrDefault().Position; if (watchinPos <= VC.Position) { return; } string defaultVCName = $"Lobby {VC.Position + 1}"; var users = await VC.GetUsersAsync().FirstOrDefault(); if (users.Count == 0 && VC.Name == defaultVCName) { return; } string newName = users.Count == 0 ? defaultVCName : users.First().Game?.Name ?? defaultVCName; if (newName != "Lobby") { foreach (IGuildUser user in users) { if (user.IsBot) { continue; } if (user.Game?.Name != newName) { newName = defaultVCName; } } } if (!(char.IsUpper(newName[0]))) { newName = Char.ToUpperInvariant(newName[0]) + newName.Remove(0, 1); } void ChangeVCName(VoiceChannelProperties properties) => properties.Name = newName; await VC.ModifyAsync(new Action <VoiceChannelProperties>(ChangeVCName)); }
public async Task Timeout([Remainder, Summary("Username")] string user) { try { var guildId = (null == Context.Guild ? Context.Channel.Id : Context.Guild.Id); if (StateCache.Guilds[guildId].timeoutUser != 0) { throw new Exception($"Timeout vote already in progress!"); } //get all users in voice IVoiceChannel channel = (Context.Message.Author as IGuildUser).VoiceChannel; if (null == channel) { throw new Exception($"{user} is not in a voice channel."); } var users = channel.GetUsersAsync(); var collection = await users.FirstOrDefault(); foreach (IUser u in collection) { if (0 == string.Compare(u.Username, user, true)) { StateCache.Guilds[guildId].timeoutUser = u.Id; StateCache.Guilds[guildId].timeoutNumUsers = collection.Count(); StateCache.Guilds[guildId].channelTimeout = Context.Channel; StateCache.Guilds[guildId].afkChannel = await Context.Guild.GetAFKChannelAsync(); await Context.Channel.SendMessageAsync($"Timeout vote for user {u.Username} started for 2 minutes. Type !vote yes/no to vote."); StateCache.Guilds[guildId].timerTimeout.Start(); } StateCache.Guilds[guildId].timeoutVoters[u] = false; } if (StateCache.Guilds[guildId].timeoutUser == 0) { throw new Exception($"User {user} not found."); } } catch (Exception ex) { await Context.Channel.SendMessageAsync($"Error starting a timeout vote. {ex.Message}"); } }
public async Task ReleaseVoiceChannel([Summary("The id of the observed voice channel")] ulong voiceChannelId) { IReadOnlyCollection <IVoiceChannel> guildVoiceChannels = await Context.Guild.GetVoiceChannelsAsync(); IVoiceChannel voiceChannel = guildVoiceChannels.FirstOrDefault(currentVoiceChannel => currentVoiceChannel.Id == voiceChannelId); if (voiceChannel == null) { await Context.Channel.SendMessageAsync($"Voice channel with id {voiceChannelId} not found on this guild."); } else if (!_observedVoiceChannelsCache.TryGetValue(voiceChannelId, out ObservedVoiceChannel observedVoiceChannel)) { await Context.Channel.SendMessageAsync($"Voice channel {voiceChannel.Name} hasn't been observed."); } else { if (observedVoiceChannel.IsMuted) { IEnumerable <IGuildUser> voiceChannelUsers = await voiceChannel .GetUsersAsync() .FlattenAsync(); IEnumerable <Task> unmuteTasks = voiceChannelUsers .Where(voiceChannelUser => { SocketGuildUser socketGuildUser = voiceChannelUser as SocketGuildUser; bool userIsMuted = socketGuildUser.VoiceState?.IsMuted == true; bool userNotOffline = socketGuildUser.Status != UserStatus.Offline; return(userIsMuted && userNotOffline); }) .Select(voiceChannelUser => voiceChannelUser.ModifyAsync(guildUserProperties => guildUserProperties.Mute = false)); await Task.WhenAll(unmuteTasks); } _observedVoiceChannelsCache.Remove(voiceChannelId); await Context.Channel.SendMessageAsync($"Voice channel {voiceChannel.Name} has been released from observation."); } }
// The actual code which connects our name determinant function to renaming the channel. // I didn't want to make the function which determines the name async, as it's more of a utility, // so all of the async work is done here. public static async Task UpdateVoiceChannel(IVoiceChannel Channel) { // If the setting is off - don't bother if (!Settings.GetGuildSetting <bool>(Channel.Guild, "RenameVoiceChannels")) { return; } // Don't mess with the AFK channel. Nobody plays games in it anyway...hence AFK if (Channel.Id == Channel.Guild.AFKChannelId) { return; } string NewName = GetVoiceChannelName(await Channel.GetUsersAsync().Flatten()); try { await Channel.ModifyAsync(x => x.Name = NewName); } catch (Exception e) { // If my checks haven't caught someone trying to (most likely) change the voice channel name to something // that it shouldn't be, then we can handle that to avoid crashing the bot AuxillaryLogger.Log(LogSeverity.Error, "VoiceChannelRename", $"Failed to change the voice channel's name to: {NewName} ({e.ToString()}: {e.Message})"); } }
public async Task OnReactionAdded( Cacheable <IUserMessage, ulong> cacheable, ISocketMessageChannel socketMessageChannel, SocketReaction socketReaction) { ObservedVoiceChannelOptions observedVoiceChannelOptions = _observedVoiceChannelOptionsMonitor.CurrentValue; string emoteName = socketReaction.Emote.Name; bool emoteIsMutedEmoji = emoteName == observedVoiceChannelOptions.MutedEmoji; bool emoteIsUnMutedEmoji = emoteName == observedVoiceChannelOptions.UnMutedEmoji; if (emoteIsMutedEmoji || emoteIsUnMutedEmoji) { ObservedVoiceChannel observedVoiceChannel = _observedVoiceChannelsCache.Values.FirstOrDefault(currentObservedVoiceChannel => currentObservedVoiceChannel.MessageId == socketReaction.MessageId); if (observedVoiceChannel != null) { IMessage message = await socketMessageChannel.GetMessageAsync(cacheable.Id); if (message.Reactions[socketReaction.Emote].ReactionCount > 1) { SocketGuildChannel socketGuildChannel = socketMessageChannel as SocketGuildChannel; SocketVoiceChannel socketVoiceChannel = socketGuildChannel.Guild.GetVoiceChannel(observedVoiceChannel.VoiceChannelId); IVoiceChannel voiceChannel = socketVoiceChannel as IVoiceChannel; IEnumerable <IGuildUser> voiceChannelUsers = await voiceChannel .GetUsersAsync() .FlattenAsync(); Emoji mutedEmoji = new Emoji(observedVoiceChannelOptions.MutedEmoji); Emoji unMutedEmoji = new Emoji(observedVoiceChannelOptions.UnMutedEmoji); if (observedVoiceChannel.IsMuted && emoteIsUnMutedEmoji) { List <Task> tasks = voiceChannelUsers .Where(voiceChannelUser => { SocketGuildUser socketGuildUser = voiceChannelUser as SocketGuildUser; bool userIsMuted = socketGuildUser.VoiceState?.IsMuted == true; bool userNotOffline = socketGuildUser.Status != UserStatus.Offline; return(userIsMuted && userNotOffline); }) .Select(voiceChannelUser => voiceChannelUser.ModifyAsync(guildUserProperties => guildUserProperties.Mute = false)) .ToList(); tasks.Add(message.RemoveAllReactionsForEmoteAsync(unMutedEmoji)); tasks.Add(message.AddReactionAsync(mutedEmoji)); await Task.WhenAll(tasks); observedVoiceChannel.IsMuted = false; } else if (!observedVoiceChannel.IsMuted && emoteIsMutedEmoji) { List <Task> tasks = voiceChannelUsers .Where(voiceChannelUser => { SocketGuildUser socketGuildUser = voiceChannelUser as SocketGuildUser; bool userNotMuted = socketGuildUser.VoiceState?.IsMuted == false; bool userNotOffline = socketGuildUser.Status != UserStatus.Offline; return(userNotMuted && userNotOffline); }) .Select(voiceChannelUser => voiceChannelUser.ModifyAsync(guildUserProperties => guildUserProperties.Mute = true)) .ToList(); tasks.Add(message.RemoveAllReactionsForEmoteAsync(mutedEmoji)); tasks.Add(message.AddReactionAsync(unMutedEmoji)); await Task.WhenAll(tasks); observedVoiceChannel.IsMuted = true; } } } } }