private async Task BotMoved(SocketUser user, SocketVoiceState preState, SocketVoiceState postState) { SocketGuildUser bot = _client.Guilds.First().CurrentUser; if (user != bot) { return; } if (_player == null) { return; } if (_player.PlayerState != PlayerState.Paused) { return; } if (!_alone) { return; } if (postState.VoiceChannel.Users.Count() == 1) { return; } await PauseAsync(); await _player.TextChannel.SendMessageAsync(":arrow_forward: Resumed playback."); _alone = false; }
public async Task ClientMoved(SocketUser user, SocketVoiceState state1, SocketVoiceState state2) { if (state1.VoiceChannel?.Name == voiceChannel || state2.VoiceChannel?.Name == voiceChannel) { await UsersChanged(); } }
private Task ClientOnUserVoiceStateUpdated(SocketUser usr, SocketVoiceState oldState, SocketVoiceState newState) { var gusr = usr as SocketGuildUser; if (gusr == null) { return(Task.CompletedTask); } var oldVc = oldState.VoiceChannel; var newVc = newState.VoiceChannel; var _ = Task.Run(async() => { try { if (oldVc != newVc) { ulong guildId; guildId = newVc?.Guild.Id ?? oldVc.Guild.Id; if (VcRoles.TryGetValue(guildId, out ConcurrentDictionary <ulong, IRole> guildVcRoles)) { //remove old if (oldVc != null && guildVcRoles.TryGetValue(oldVc.Id, out IRole role)) { if (gusr.Roles.Contains(role)) { try { await gusr.RemoveRoleAsync(role).ConfigureAwait(false); await Task.Delay(500).ConfigureAwait(false); } catch { await Task.Delay(200).ConfigureAwait(false); await gusr.RemoveRoleAsync(role).ConfigureAwait(false); await Task.Delay(500).ConfigureAwait(false); } } } //add new if (newVc != null && guildVcRoles.TryGetValue(newVc.Id, out role)) { if (!gusr.Roles.Contains(role)) { await gusr.AddRoleAsync(role).ConfigureAwait(false); } } } } } catch (Exception ex) { _log.Warn(ex); } }); return(Task.CompletedTask); }
public async Task UserVoiceStateUpdatedForCreateVoiceChannel(SocketUser user, SocketVoiceState voiceStateBefore, SocketVoiceState voiceStateAfter) { var userAccount = _accounts.GetAccount(user); if (userAccount.VoiceChannelList.Count <= 0) { return; } if (voiceStateAfter.VoiceChannel?.Id != userAccount.VoiceChannelList[0].VoiceChannelId && voiceStateBefore.VoiceChannel.Id != userAccount.VoiceChannelList[0].VoiceChannelId) { return; } var voiceChannelId = userAccount.VoiceChannelList[0].VoiceChannelId; var guildId = userAccount.VoiceChannelList[0].GuildId; if (voiceStateAfter.VoiceChannel != null && voiceStateAfter.VoiceChannel.Users.Contains(user)) { var newVoice = new AccountSettings.CreateVoiceChannel(DateTime.UtcNow.AddHours(10), voiceChannelId, guildId); userAccount.VoiceChannelList[0] = newVoice; } if (voiceStateAfter.VoiceChannel == null || !voiceStateAfter.VoiceChannel.Users.Contains(user)) { var newVoice = new AccountSettings.CreateVoiceChannel(DateTime.UtcNow, voiceChannelId, guildId); userAccount.VoiceChannelList[0] = newVoice; } }
private async Task OnUserVoiceStateChanged(SocketUser user, SocketVoiceState voiceStateBefore, SocketVoiceState voiceStateAfter) { var guildId = await _servers.GetUserLogChannel(((SocketGuildUser)user).Guild.Id); if (!(_client.GetChannel(guildId) is ISocketMessageChannel messageChannel)) { return; } if (!Equals(voiceStateBefore.VoiceChannel, voiceStateAfter.VoiceChannel) && voiceStateAfter.VoiceChannel != null && voiceStateBefore.VoiceChannel == null) { await EventExtension.UserVoiceJoined(user, voiceStateAfter.VoiceChannel, messageChannel); } else if (!Equals(voiceStateAfter.VoiceChannel, voiceStateBefore.VoiceChannel) && voiceStateBefore.VoiceChannel != null && voiceStateAfter.VoiceChannel == null) { await EventExtension.UserVoiceLeft(user, voiceStateBefore.VoiceChannel, messageChannel); } else if (!Equals(voiceStateAfter.VoiceChannel, voiceStateBefore.VoiceChannel) && voiceStateBefore.VoiceChannel != null && voiceStateAfter.VoiceChannel != null) { await EventExtension.UserVoicejumped(user, voiceStateBefore.VoiceChannel, voiceStateAfter.VoiceChannel, messageChannel); } }
private async Task ChannelChanged(SocketUser user, SocketVoiceState before, SocketVoiceState after) { if (before.VoiceChannel == after.VoiceChannel) { return; } if (Globals.deleteGuard) { return; } if (!Globals.vcCreators.ContainsKey(user.Id)) { return; } if (before.VoiceChannel.Name != Globals.vcCreators[user.Id]) { return; } await before.VoiceChannel.DeleteAsync(); Globals.vcCreators.Remove(user.Id); }
async Task doStuff(SocketUser arg1, SocketVoiceState arg2, SocketVoiceState arg3) { string folder = getUserFolder(arg1); if (!Directory.Exists(folder)) { return; } if (arg3.VoiceChannel != null && arg2.VoiceChannel?.Id != arg3.VoiceChannel?.Id) { string file = getMediaType(arg1, "join"); if (!File.Exists(file)) { return; } var vc = await getAudioClient(arg3.VoiceChannel); await SendAsync(vc, getMediaType(arg1, "join")); if (waiting <= 1) { await arg3.VoiceChannel.DisconnectAsync(); clients.Remove(arg3.VoiceChannel.Guild); } Thread.Sleep(250); } }
private async Task OnVoiceUpdated(SocketUser user, SocketVoiceState oldState, SocketVoiceState newState) { if (newState.VoiceChannel != null) { await newState.VoiceChannel.DisconnectAsync(); } }
public AudioService(SocketVoiceState socketVoiceState) { this.Guild = socketVoiceState.VoiceChannel.Guild; this.VoiceChannel = null; this.VoiceState = socketVoiceState; AudioServices.Add(this); }
internal async Task UserVoiceStateUpdated(SocketUser arg1, SocketVoiceState arg2, SocketVoiceState arg3) { if (arg1.Id == _discordSocketClient.CurrentUser.Id) { return; } if (arg3.VoiceChannel.Guild.Id == EnvManager.XpcJapanId) { #region for XPC-JP if (!EqualVoiceChannel(arg2.VoiceChannel, arg3.VoiceChannel)) { ulong textChannelId; if (JsonManager.VoiceChatToTextChannel.TryGetValue(arg3.VoiceChannel.Id, out textChannelId)) { var textChannel = _discordSocketClient.GetChannel(textChannelId) as SocketTextChannel; var m = XPCFaucetBot.Utils.JsonManager.VoiceChatJoinMessages[ _random.Next(XPCFaucetBot.Utils.JsonManager.VoiceChatJoinMessages.Length)]; var message = await textChannel.SendMessageAsync(string.Format(m, arg1.Mention)); Debug.Log( $"send {string.Format(m, $"{arg1.Username}:{arg1.Mention}")} in {textChannel.Name}:{textChannel.Id}"); Delete(message); } } #endregion } }
private static async void Client_UserVoiceStateUpdated(SocketUser iusr, SocketVoiceState oldState, SocketVoiceState newState) { var usr = iusr as SocketGuildUser; if (usr == null || oldState.VoiceChannel == newState.VoiceChannel) { return; } MusicPlayer player; if (!MusicPlayers.TryGetValue(usr.Guild.Id, out player)) { return; } try { var users = await player.PlaybackVoiceChannel.GetUsersAsync().Flatten().ConfigureAwait(false); if ((player.PlaybackVoiceChannel == newState.VoiceChannel && //if joined first, and player paused, unpause player.Paused && users.Count() == 2) || // keep in mind bot is in the channel (+1) (player.PlaybackVoiceChannel == oldState.VoiceChannel && // if left last, and player unpaused, pause !player.Paused && users.Count() == 1)) { player.TogglePause(); } } catch { } }
private async Task UserVCUpdated(SocketUser arg1, SocketVoiceState arg2, SocketVoiceState arg3) { if (arg3.VoiceChannel != null) { await _workerService.AddWorkerToChannel(arg3.VoiceChannel); } }
public Task ShameTachire(SocketUser user, SocketVoiceState oldState, SocketVoiceState newState) { TachireShame tachireShame = new TachireShame(); tachireShame.ShameTachire(user, oldState, newState); return(Task.CompletedTask); }
private async Task OnUserVoiceStateUpdated(SocketUser user, SocketVoiceState previous, SocketVoiceState current) { if (!(user is SocketGuildUser guildUser)) { return; } var voiceChannel = current.VoiceChannel ?? previous.VoiceChannel; if (voiceChannel.Guild.Id != Constants.TutorialGuildId) { return; } var role = voiceChannel.Guild.GetRole(Constants.VoiceChatRoleId); if (role == null) { return; } bool hasRole = guildUser.Roles.Any(x => x.Id == Constants.VoiceChatRoleId); if (current.VoiceChannel?.Id == Constants.VoiceChannelId && !hasRole) { await guildUser.AddRoleAsync(role); } else if (previous.VoiceChannel?.Id == Constants.VoiceChannelId && hasRole) { await guildUser.RemoveRoleAsync(role); } }
private async Task OnUserVoiceStateUpdated(SocketUser user, SocketVoiceState before, SocketVoiceState after) { if (Channel == null) { return; } if (user.Id == _client.CurrentUser.Id) { return; } //Ensure we can get all users in this channel await _client.DownloadUsersAsync(new [] { Channel.Guild }); //If there are other users in the channel stay in the channel var count = await Channel.GetUsersAsync().Select(a => a.Count).Sum(); if (count > 1) { return; } //No one is listening :( await Stop(); }
/// <summary> /// The event that handles users when the join after a playtest session has started /// </summary> /// <param name="user">User who joined voice</param> /// <param name="lefState">Information on what channel they left</param> /// <param name="joinedState">What channel they joined</param> /// <returns></returns> private Task UserVoiceStateUpdated(SocketUser user, SocketVoiceState lefState, SocketVoiceState joinedState) { //If leftState and joinedState are the same, the event was fired from a modified event. if (lefState.VoiceChannel == joinedState.VoiceChannel) { return(Task.CompletedTask); } var guildUser = _dataService.GetSocketGuildUser(user.Id); //User joined if (joinedState.VoiceChannel != null && joinedState.VoiceChannel.Id == _dataService.LevelTestVoiceChannel.Id) { //Don't re-mute a muted user if (guildUser.IsMuted) { return(Task.CompletedTask); } _ = ProcessMute(true, guildUser); return(Task.CompletedTask); } //If a user leaves the channel, remove from the queue. if (lefState.VoiceChannel != null && lefState.VoiceChannel.Id == _dataService.LevelTestVoiceChannel.Id) { _ = RemoveUser(user.Id); } return(Task.CompletedTask); }
private async Task HandleVoiceStateChanged(SocketUser user, SocketVoiceState beforeChangeState, SocketVoiceState afterChangeState) { var beforeChannel = beforeChangeState.VoiceChannel; var afterChannel = afterChangeState.VoiceChannel; var action = string.Empty; if (beforeChannel != null && afterChannel == null) { action = $"left `{beforeChannel.Name}`"; } if (beforeChannel != null && afterChannel != null) { action = $"switched from `{beforeChannel.Name}` to `{afterChannel.Name}`"; } if (beforeChannel == null && afterChannel != null) { action = $"joined `{afterChannel.Name}`"; } if (beforeChannel?.Id == afterChannel?.Id) { return; } await _announcementChannel.SendMessageAsync($"{user.Username} {action}.", isTTS : true); }
async Task UserMovedVc(SocketGuildUser user, SocketVoiceState fState, SocketVoiceState tState) { var from = fState.VoiceChannel; var to = tState.VoiceChannel; if (Pairings.TryGetValue(from, out var thing)) { var pairings = from.Users.Count(x => x.Id != user.Id && hasEnabledPairing(x, fState.IsSelfMuted || tState.IsSelfMuted)); if (pairings == 0) { Pairings.Remove(from); var text = from.Guild.GetTextChannel(thing); if (text != null) { await text.ModifyAsync(x => { x.CategoryId = to.CategoryId; x.Position = 999; x.Topic = $"Channel paired to <#{to.Id}>"; x.Name = "pair-" + to.Name; }); await text.SendMessageAsync($"Channel is now paired to <#{to.Id}> as user moved."); Pairings.Remove(from); Pairings[to] = thing; } OnSave(); return; } } await UserJoinedVc(user, tState); }
public async Task UserJoinedOrLeftChannel(SocketUser user, SocketVoiceState voiceState1, SocketVoiceState voiceState2) { var account = UserAccounts.GetAccount(user); //adding xp for joining/leaving voice channel string voiceState1String = voiceState1.ToString(); TimeSpan timeDif = DateTime.Now.Subtract(account.TimeConnected); Console.WriteLine(String.Format("{0:G}", DateTime.Now) + $" : {user} connected to {voiceState2} from {voiceState1}"); if (voiceState1String != "Unknown" && voiceState1String != "AFK") { int i = 0; double timeDiffMinutes = timeDif.TotalMinutes; while (timeDiffMinutes >= 3) { UserLeveling.AddXp(user, 1); //adding XP timeDiffMinutes -= 3; i++; } UserLeveling.TotalTimeConntected(user); //adding total minutes to account if (timeDif.TotalMinutes > 3) { Console.WriteLine(String.Format("{0:G}", DateTime.Now) + $" : {user} gained {i * 1} XP by staying in {voiceState1} for {timeDif.TotalMinutes}"); } } UserLeveling.LastActivity(user); //setting new LastActivity }
private async Task Client_UserVoiceStateUpdated(SocketUser arg1, SocketVoiceState arg2, SocketVoiceState arg3) { if (!(arg1 is SocketGuildUser user)) { return; } if (TTTGame.IsTTTVoice(arg2.VoiceChannel) || TTTGame.IsTTTVoice(arg3.VoiceChannel)) { return; } if (user.IsBot) { return; } if (arg3.VoiceChannel == null) { await UserLeftVc(user, arg2); } else if (arg2.VoiceChannel == null) { await UserJoinedVc(user, arg3); } else if (arg2.VoiceChannel.Id != arg3.VoiceChannel.Id) { await UserMovedVc(user, arg2, arg3); } }
// implement a queue of sorts for when multiple people join public static Task PlayIntroMusic(SocketUser user, SocketVoiceState previousState, SocketVoiceState newState) { Task.Run(async() => { // Stops this from triggering when a user is muted or deafened bool sameChannel = previousState.VoiceChannel == newState.VoiceChannel; if (user.IsBot || sameChannel || newState.VoiceChannel == null) { return; } User userData = User.GetUser(user.Id); Guild guildData = Guild.GetGuildData(newState.VoiceChannel.Guild); if (userData.IntroSong == null || guildData == null || !guildData.EnableIntroMusic) { return; } AudioService audioService = AudioService.GetAudioService(newState.VoiceChannel.Guild); if (audioService == null) { audioService = new AudioService(newState); } await audioService.ConnectToVoiceAsync(); await audioService.StreamToVoiceAsync(userData.IntroSong); }); return(Task.CompletedTask); }
/// <summary>Fired whenever someone joins/leaves a voice channel. /// <para>Used to automatically disconnect bot if bot is left alone in voice channel</para> /// </summary> public async Task UserVoiceStateUpdated(SocketUser user, SocketVoiceState oldState, SocketVoiceState newState) { if (!_lavaNode.HasPlayer(((SocketGuildUser)user).Guild)) { return; } if (user.IsBot) { return; } if (oldState.VoiceChannel == null) { return; } if (!oldState.VoiceChannel.Users.Contains(((SocketGuildUser)user).Guild.CurrentUser)) { return; } if (oldState.VoiceChannel == (newState.VoiceChannel)) { return; } //We count every user in the channel that isn't a bot, and put that result in 'users' variable int users = oldState.VoiceChannel.Users.Count(u => !u.IsBot); //If there are no users left in the voice channel, we make the bot leave if (users < 1) { var player = _lavaNode.GetPlayer(((SocketGuildUser)user).Guild); await player.StopAsync(); await _lavaNode.LeaveAsync(player.VoiceChannel); } }
private Task Client_UserVoiceStateUpdated(SocketUser usr, SocketVoiceState oldState, SocketVoiceState newState) { var _ = Task.Run(async() => { try { if (!(usr is SocketGuildUser gUser)) { return; } var game = gUser.Activity?.Name; if (oldState.VoiceChannel == newState.VoiceChannel || newState.VoiceChannel == null) { return; } if (!GameVoiceChannels.Contains(newState.VoiceChannel.Id) || string.IsNullOrWhiteSpace(game)) { return; } await TriggerGvc(gUser, game); } catch (Exception ex) { _log.Warn(ex); } }); return(Task.CompletedTask); }
private static Task Client_UserVoiceStateUpdated(SocketUser arg1, SocketVoiceState old, SocketVoiceState updated) { SocketGuildUser user = arg1 as SocketGuildUser; if (user != null) { if (TryGetLogChannel(user.Guild, DiscordEventType.UserVoiceStatusUpdated, out SocketTextChannel channel, out EmbedBuilder embed)) { StringBuilder description = new StringBuilder(); if (old.VoiceChannel == null && updated.VoiceChannel != null) { description.AppendLine($"Joined {updated.VoiceChannel}"); } else if (old.VoiceChannel != null && updated.VoiceChannel == null) { description.AppendLine($"Left {old.VoiceChannel}"); } else if (old.VoiceChannel != null && old.VoiceChannel != updated.VoiceChannel) { description.AppendLine($"Moved from {old.VoiceChannel} to {updated.VoiceChannel}"); } if (description.Length > 0) { embed.Title = $"{arg1} Voice Update"; embed.Description = description.ToString(); return(channel.SendEmbedAsync(embed)); } } } return(Task.CompletedTask); }
private async Task ProcessVoiceChannelChange(SocketUser user, SocketVoiceState oldChannel, SocketVoiceState newChannel) { await UpdateConsole($"{user == null} {oldChannel} {newChannel}"); if (oldChannel.VoiceChannel.Id != newChannel.VoiceChannel.Id) { TVroom roomToUse = await GetRoom(newChannel.VoiceChannel); TVroom roomLeft = await GetRoom(oldChannel.VoiceChannel); if (roomToUse != null && roomLeft == roomToUse) { await roomToUse.Modify(user); } else { if (roomToUse != null) { await roomToUse.Add(user); } if (roomLeft != null) { await roomLeft.Remove(user); if ((await roomLeft.GetRoomCount()) == 0) { await RemoveRoom(roomLeft.TvChannel); } } } } }
private SocketVoiceChannel GetVoiceChannel(SocketUser user, SocketVoiceState oldState, SocketVoiceState newState) { SocketVoiceChannel channel = oldState.VoiceChannel ?? newState.VoiceChannel; SocketGuildUser botUser = channel.Guild.CurrentUser; if (oldState.VoiceChannel != botUser.VoiceChannel && newState.VoiceChannel != botUser.VoiceChannel) { return(null); } switch (newState.VoiceChannel) { case null: if (oldState.VoiceChannel != null && user.Id != this._baseSocketClient.CurrentUser.Id) { return(oldState.VoiceChannel); } break; default: if (user.Id == this._baseSocketClient.CurrentUser.Id) { return(newState.VoiceChannel); } if (botUser.VoiceChannel == newState.VoiceChannel) { return(newState.VoiceChannel); } break; } return(channel); }
private Task _client_OnUserVoiceStateUpdated(SocketUser socketUser, SocketVoiceState before, SocketVoiceState after) { if (!(socketUser is SocketGuildUser user) || user.IsBot) { return(Task.CompletedTask); } var _ = Task.Run(() => { if (before.VoiceChannel != null) { ScanChannelForVoiceXp(before.VoiceChannel); } if (after.VoiceChannel != null && after.VoiceChannel != before.VoiceChannel) { ScanChannelForVoiceXp(after.VoiceChannel); } else if (after.VoiceChannel == null) { // In this case, the user left the channel and the previous for loops didn't catch // it because it wasn't in any new channel. So we need to get rid of it. UserLeftVoiceChannel(user, before.VoiceChannel); } }); return(Task.CompletedTask); }
private static Task OnUserVoiceStateUpdated(SocketUser user, SocketVoiceState before, SocketVoiceState after) { if (before.VoiceChannel != after.VoiceChannel) { Core.Log.Write(Core.Log.Type.USER, $"{user.GetShownName ()} moved from voice channel {before.VoiceChannel.GetPath ()} to {after.VoiceChannel.GetPath ()}"); } else { if (before.IsDeafened != after.IsDeafened) { Core.Log.Write(Core.Log.Type.USER, $"{user.GetShownName()} had deafened toggled: {after.IsDeafened}."); } if (before.IsMuted != after.IsMuted) { Core.Log.Write(Core.Log.Type.USER, $"{user.GetShownName()} had muted toggled: {after.IsMuted}."); } if (before.IsSelfDeafened != after.IsSelfDeafened) { Core.Log.Write(Core.Log.Type.USER, $"{user.GetShownName()} had self-deafened toggled: {after.IsSelfDeafened}."); } if (before.IsSelfMuted != after.IsSelfMuted) { Core.Log.Write(Core.Log.Type.USER, $"{user.GetShownName()} had self-muted toggled: {after.IsSelfMuted}."); } if (before.IsSuppressed != after.IsSuppressed) { Core.Log.Write(Core.Log.Type.USER, $"{user.GetShownName()} had supressed toggled: {after.IsSuppressed}."); } } return(Task.CompletedTask); }
private Task UserVoiceStateUpdated(SocketUser user, SocketVoiceState leftState, SocketVoiceState joinedState) { //If leftState and joinedState are the same, the event was fired from a modified user event. if (leftState.VoiceChannel == joinedState.VoiceChannel) { return(Task.CompletedTask); } _ = _log.LogMessage($"{user} - `{user.Id}`" + $"\nleftState: `{leftState}`" + $"\njoinedState: `{joinedState}`", console: false, color: ConsoleColor.Red); var guildUser = _dataService.GetSocketGuildUser(user.Id); if (joinedState.VoiceChannel != null) { //If we joined the testing channel, and feedback is active, don't unmute if (_playtestService.FeedbackSession != null && joinedState.VoiceChannel.Id == _dataService.LevelTestVoiceChannel.Id) { return(Task.CompletedTask); } guildUser.ModifyAsync(x => x.Mute = false); } return(Task.CompletedTask); }
public async Task UserVoiceUpdate(SocketUser user, SocketVoiceState before, SocketVoiceState after) { var userName = _discordContext.GetUserNickname(user.Id); var sb = new StringBuilder(); sb.Append($"[{DateTime.Now} - {this.GetType().Name}]: "); if (before.VoiceChannel == null && after.VoiceChannel != null) { sb.AppendLine($"{userName} has join channel:"); sb.AppendLine($"\t#{after.VoiceChannel.Name}"); } else if (before.VoiceChannel != null && after.VoiceChannel == null) { sb.AppendLine($"{userName} has left channel:"); sb.AppendLine($"\t#{before.VoiceChannel.Name}"); } else { if (string.Equals(before.VoiceChannel.Name, after.VoiceChannel.Name, StringComparison.OrdinalIgnoreCase)) { return; } sb.AppendLine($"{userName} has switched channel:"); sb.AppendLine($"\tfrom: #{before.VoiceChannel.Name}"); sb.AppendLine($"\tto: #{after.VoiceChannel.Name}"); } if (before.VoiceChannel != null) { await MusicPlayerAutoLeave(before.VoiceChannel); } await _logger.WriteLog(sb.ToString()); }