Esempio n. 1
0
        private Task VoiceStateUpdated(DiscordClient sender, VoiceStateUpdateEventArgs e)
        {
            if (e.Guild.Id != this._Guild.Id)
            {
                return(Task.CompletedTask);
            }

            // handle user info
            var oldChannel = e.Before?.Channel;
            var newChannel = e.After?.Channel;

            var oldRoom = (oldChannel != null && Game.Rooms.ContainsKey(oldChannel.Name)) ? Game.Rooms[oldChannel.Name] : default;
            var newRoom = (newChannel != null && Game.Rooms.ContainsKey(newChannel.Name)) ? Game.Rooms[newChannel.Name] : default;

            if (oldRoom == newRoom)
            {
                return(Task.CompletedTask);
            }

            // Do not wait for these
            Task.Run(async() =>
            {
                var member  = await this._Guild.GetMemberAsync(e.User.Id);
                var player  = await GetOrCreatePlayer(member);
                player.Room = newRoom;

                Game.RaisePlayerChangedRoom(player, oldRoom);
            });

            return(Task.CompletedTask);
        }
Esempio n. 2
0
        internal static Task VoiceUpdate(DiscordClient _1, VoiceStateUpdateEventArgs e)
        {
            _ = Task.Run(async() =>
            {
                if (e.Guild.Id != 699555747591094344)
                {
                    return;
                }

                DiscordEmbedBuilder embed = new DiscordEmbedBuilder()
                                            .WithTimestamp(DateTime.Now)
                                            .WithThumbnail(e.User.AvatarUrl);
                if (e.Before is null)
                {
                    embed.WithDescription($"<:add:930501217187156018> {e.User.Mention} ({e.User.Id}) joined voice channel\n" +
                                          $"{e.Channel.Mention}")
                    .WithColor(DiscordColor.Green);
                }
                else if (e.After.Channel is null)
                {
                    embed.WithDescription($"<:remove:930501216889360425> {e.User.Mention} ({e.User.Id}) left voice channel\n" +
                                          $"{e.Before.Channel.Mention}")
                    .WithColor(DiscordColor.Red);
                }
                else
                {
                    embed.WithDescription($":information_source: {e.User.Mention} ({e.User.Id}) changed voice channel\n" +
                                          $"from {e.Before.Channel.Mention} to {e.After.Channel.Mention}")
                    .WithColor(DiscordColor.Blurple);
                }

                await DiscordObjectService.Instance.LogsChannel.SendMessageAsync(new DiscordMessageBuilder().WithEmbed(embed).WithAllowedMentions(Mentions.None));
            });
            return(Task.CompletedTask);
        }
Esempio n. 3
0
        private async Task Discord_VoiceStateUpdated(VoiceStateUpdateEventArgs e)
        {
            var gld = e.Guild;

            if (gld == null)
            {
                return;
            }

            if (e.User == null)
            {
                return;
            }

            if (e.User.Id == this.Discord.CurrentUser.Id)
            {
                if (e.After.Channel == null && this.ConnectedGuilds.TryRemove(gld.Id, out var gc) && this.IsConnected)
                {
                    gc.ManuallyDisconnected = true;
                    await gc.DisconnectAsync().ConfigureAwait(false);
                }

                if (this.ConnectedGuilds.TryGetValue(e.Guild.Id, out var lvlgc))
                {
                    lvlgc.VoiceStateUpdate = e;
                }

                if (!string.IsNullOrWhiteSpace(e.SessionId) && e.Channel != null && this.VoiceStateUpdates.TryRemove(gld.Id, out var xe))
                {
                    xe.SetResult(e);
                }
            }
        }
Esempio n. 4
0
        private Task Client_VoiceStateUpdate(VoiceStateUpdateEventArgs e)
        {
            var gld = e.Guild;

            if (gld == null)
            {
                return(Task.CompletedTask);
            }

            if (e.User == null)
            {
                return(Task.CompletedTask);
            }

            if (e.User.Id == this.Client.CurrentUser.Id && this.ActiveConnections.TryGetValue(e.Guild.Id, out var vnc))
            {
                vnc.Channel = e.Channel;
            }

            if (!string.IsNullOrWhiteSpace(e.SessionId) && e.User.Id == this.Client.CurrentUser.Id && e.Channel != null && this.VoiceStateUpdates.ContainsKey(gld.Id))
            {
                this.VoiceStateUpdates.TryRemove(gld.Id, out var xe);
                xe.SetResult(e);
            }

            return(Task.CompletedTask);
        }
Esempio n. 5
0
        private async Task VoiceStateUpdated(DiscordClient client, VoiceStateUpdateEventArgs e)
        {
            VoiceNextConnection vnc = _voiceNextExtension.GetConnection(e.Guild);

            if (vnc == null)
            {
                return;
            }

            if (e.User.Id == client.CurrentUser.Id)
            {
                if (!e.After.IsServerDeafened)
                {
                    DiscordMember member = await e.Guild.GetMemberAsync(e.User.Id);

                    await member.ModifyAsync(member => member.Deafened = true);
                }
            }
            else
            {
                if (e.Before?.Channel != null && e.Before.Channel.Id == vnc.TargetChannel.Id && e.Before.Channel.Users.Where(u => !u.IsBot).Count() == 0)
                {
                    vnc.Disconnect();
                }
            }
        }
Esempio n. 6
0
        private async Task Discord_VoiceStateUpdated(VoiceStateUpdateEventArgs e)
        {
            if (e.User == this.Discord.CurrentUser)
            {
                return;
            }

            var music = this.Services.GetService <MusicService>();
            var gmd   = await music.GetOrCreateDataAsync(e.Guild);

            var chn = gmd.Channel;

            if (chn == null || chn != e.Before.Channel)
            {
                return;
            }

            var usrs = chn.Users;

            if (gmd.IsPlaying && usrs.Count() == 1 && usrs.First() == this.Discord.CurrentUser)
            {
                e.Client.DebugLogger.LogMessage(LogLevel.Info, LOG_TAG, $"All users left voice in {e.Guild.Name}, pausing playback", DateTime.Now);
                await gmd.PauseAsync();

                if (gmd.CommandChannel != null)
                {
                    await gmd.CommandChannel.SendMessageAsync($"{DiscordEmoji.FromName(e.Client, ":play_pause:")} All users left the channel, playback paused. You can resume it by joining the channel and using the `resume` command.");
                }
            }
        }
        private Task Client_VoiceStateUpdate(DiscordClient client, VoiceStateUpdateEventArgs e)
        {
            var gld = e.Guild;

            if (gld == null)
            {
                return(Task.CompletedTask);
            }

            if (e.User == null)
            {
                return(Task.CompletedTask);
            }

            if (e.User.Id == this.Client.CurrentUser.Id)
            {
                if (e.After.Channel == null && this.ActiveConnections.TryRemove(gld.Id, out var ac))
                {
                    ac.Disconnect();
                }

                if (this.ActiveConnections.TryGetValue(e.Guild.Id, out var vnc))
                {
                    vnc.Channel = e.Channel;
                }

                if (!string.IsNullOrWhiteSpace(e.SessionId) && e.Channel != null && this.VoiceStateUpdates.TryRemove(gld.Id, out var xe))
                {
                    xe.SetResult(e);
                }
            }

            return(Task.CompletedTask);
        }
        private async Task Discord_VoiceStateUpdated(DiscordClient sender, VoiceStateUpdateEventArgs e)
        {
            if (e.User == this.Discord.CurrentUser)
            {
                return;
            }

            var music = this.Services.GetService <MusicService>();
            var gmd   = await music.GetOrCreateDataAsync(e.Guild);

            var chn = gmd.Channel;

            if (chn == null || chn != e.Before.Channel)
            {
                return;
            }

            var usrs = chn.Users;

            if (gmd.IsPlaying && !usrs.Any(x => !x.IsBot))
            {
                sender.Logger.LogInformation(LogEvent, $"All users left voice in {e.Guild.Name}, pausing playback", DateTime.Now);
                await gmd.PauseAsync();

                if (gmd.CommandChannel != null)
                {
                    await gmd.CommandChannel.SendMessageAsync($"{DiscordEmoji.FromName(sender, ":play_pause:")} All users left the channel, playback paused. You can resume it by joining the channel and using the `resume` command.");
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        ///     The asynchronous method which is triggered when a voice state updated was received
        ///     from the discord gateway.
        /// </summary>
        /// <param name="sender">the event sender (unused here)</param>
        /// <param name="args">the event arguments</param>
        /// <returns>a task that represents the asynchronous operation</returns>
        protected virtual async Task VoiceStateUpdated(object sender, VoiceStateUpdateEventArgs args)
        {
            // ignore other users except the bot
            if (args.UserId != _discordClient.CurrentUserId)
            {
                return;
            }

            var guildId = args.VoiceState?.GuildId ?? args.OldVoiceState.GuildId;

            if (!Players.TryGetValue(guildId, out var player))
            {
                return;
            }

            // connect to a voice channel
            if (args.OldVoiceState.VoiceChannelId == null && args.VoiceState.VoiceChannelId != null)
            {
                await player.UpdateAsync(args.VoiceState);
            }

            // disconnect from a voice channel
            else if (args.OldVoiceState.VoiceChannelId != null && args.VoiceState.VoiceChannelId == null)
            {
                player.Dispose();
                Players.Remove(guildId);
            }

            // reconnected to a voice channel
            else if (args.OldVoiceState.VoiceChannelId != null && args.VoiceState.VoiceChannelId != null &&
                     args.OldVoiceState.VoiceChannelId == args.VoiceState.VoiceChannelId)
            {
                await player.UpdateAsync(args.VoiceState);
            }
        }
Esempio n. 10
0
        private Task HandleVoiceStateEvent(DiscordClient client, VoiceStateUpdateEventArgs e)
        {
            /*  3 possible events:
             *      A: User joins a voice channel.
             *              -> Dispatch one JoinedVoiceChannel event.
             *      B: User switches from one channel to another.
             *              -> Dispatch one JoinedVoiceChannel event.
             *              -> Dispatch one LeftVoiceChannel event.
             *      C: User disconnects from voice.
             *              -> Dispatch one LeftVoiceChannel event.
             */
            if (e.Before?.Channel == null && e.After?.Channel != null)
            {
                this.HandleJoinVoiceChat(e.Guild, e.User, e.Channel);
            }
            if (e.Before?.Channel != null && e.After?.Channel == null)
            {
                this.HandleLeaveVoiceChat(e.Guild, e.User, e.Before.Channel);
            }
            return(Task.CompletedTask);

            /*
             *      Exmaple:  Xorander joins General Voice 01 -> Notify IonSprite.
             *                      Ripple joins General Voice 02 -> No additional notification.
             *                      And only when all voice channels in #General are empty again can a new notification be send.
             */
        }
        private Task Discord_VoiceStateUpdated(VoiceStateUpdateEventArgs e)
        {
            var gld = e.Guild;

            if (gld == null)
            {
                return(Task.Delay(0));
            }

            if (e.User == null)
            {
                return(Task.Delay(0));
            }

            if (e.User.Id == this.Discord.CurrentUser.Id && this.ConnectedGuilds.TryGetValue(e.Guild.Id, out var lvlgc))
            {
                lvlgc.Channel = e.Channel;
            }

            if (!string.IsNullOrWhiteSpace(e.SessionId) && e.User.Id == this.Discord.CurrentUser.Id && this.VoiceStateUpdates.ContainsKey(gld.Id))
            {
                this.VoiceStateUpdates.TryRemove(gld.Id, out var xe);
                xe.SetResult(e);
            }

            return(Task.Delay(0));
        }
Esempio n. 12
0
        /// <summary>
        ///     The asynchronous method which is triggered when a voice state updated was received
        ///     from the discord gateway.
        /// </summary>
        /// <param name="sender">the event sender (unused here)</param>
        /// <param name="args">the event arguments</param>
        /// <returns>a task that represents the asynchronous operation</returns>
        protected virtual async Task VoiceStateUpdated(object sender, VoiceStateUpdateEventArgs args)
        {
            EnsureNotDisposed();

            // ignore other users except the bot
            if (args.UserId != _discordClient.CurrentUserId)
            {
                return;
            }

            // try getting affected player
            if (!Players.TryGetValue(args.VoiceState.GuildId, out var player))
            {
                return;
            }

            var voiceState    = args.VoiceState;
            var oldVoiceState = player.VoiceState;

            // connect to a voice channel
            if (oldVoiceState?.VoiceChannelId is null && voiceState.VoiceChannelId != null)
            {
                await player.UpdateAsync(voiceState);
                await OnPlayerConnectedAsync(new PlayerConnectedEventArgs(player, voiceState.VoiceChannelId.Value));
            }
Esempio n. 13
0
 private async Task OnVoiceStateUpdated(VoiceStateUpdateEventArgs e)
 {
     if (VoiceStateUpdated != null)
     {
         await VoiceStateUpdated(e);
     }
 }
Esempio n. 14
0
        public static async Task LeftAlone(DiscordClient client, VoiceStateUpdateEventArgs e)
        {
            try
            {
                if (!Bot.Guilds.Any(x => x.Key == e.Guild.Id))
                {
                    return;
                }
                var g = Bot.Guilds[e.Guild.Id];
                if (g.musicInstance == null ||
                    g.musicInstance?.guildConnection?.IsConnected == false)
                {
                    return;
                }
                if ((e.After?.Channel?.Users.Where(x => !x.IsBot).Count() == 0 ||
                     e.Before?.Channel?.Users.Where(x => !x.IsBot).Count() == 0 ||
                     e.Channel?.Users.Where(x => !x.IsBot).Count() == 0) &&
                    (e.After?.Channel?.Users.Contains(e.Guild.Members[client.CurrentUser.Id]) == true ||
                     e.Before?.Channel?.Users.Contains(e.Guild.Members[client.CurrentUser.Id]) == true ||
                     e.Channel?.Users.Contains(e.Guild.Members[client.CurrentUser.Id]) == true) &&
                    g.musicInstance?.guildConnection?.Channel?.Users.Where(x => !x.IsBot).Count() == 0)
                {
                    if (g.musicInstance.playstate == Playstate.Playing)
                    {
                        await g.musicInstance.guildConnection.PauseAsync();

                        g.musicInstance.playstate = Playstate.Paused;
                        try
                        {
                            await g.musicInstance.usedChannel.SendMessageAsync(embed : new DiscordEmbedBuilder().WithDescription("**Paused** since everyone left the VC, connect back and use m%resume to continue playback otherwise I will disconnect in 5 min").Build());
                        }
                        catch { }
                    }
                    else
                    {
                        try
                        {
                            await g.musicInstance.usedChannel.SendMessageAsync(embed : new DiscordEmbedBuilder().WithDescription("Since everyone left the VC I will disconnect too in 5 min").Build());
                        }
                        catch { }
                    }
                    g.musicInstance.aloneTime = DateTime.UtcNow;
                    g.musicInstance.aloneCTS  = new CancellationTokenSource();
                    g.AloneCheckThread        = Task.Run(g.CheckAlone);
                }
                else if (e.After?.Channel?.Users.Where(x => !x.IsBot).Count() != 0 && e.After?.Channel?.Users.Contains(e.Guild.Members[client.CurrentUser.Id]) == true)
                {
                    if (g.musicInstance != null && g.musicInstance?.aloneCTS != null)
                    {
                        g.musicInstance.aloneCTS.Cancel();
                    }
                }
            }
            catch (Exception ex)
            {
                client.Logger.LogError(ex.Message);
                client.Logger.LogError(ex.StackTrace);
            }
        }
 private Task HandleVoiceStateEvent(DiscordClient client, VoiceStateUpdateEventArgs e)
 {
     if (e.Before?.Channel != null && e.After?.Channel == null)
     {
         this.HandleLeaveVoiceChat(e.Guild, e.Before.Channel);
     }
     return(Task.CompletedTask);
 }
        private Task OnVoiceStateUpdated(SocketUser user, SocketVoiceState oldSocketVoiceState, SocketVoiceState socketVoiceState)
        {
            var guildId       = socketVoiceState.VoiceChannel?.Guild?.Id ?? oldSocketVoiceState.VoiceChannel.Guild.Id;
            var oldVoiceState = new VoiceState(oldSocketVoiceState.VoiceChannel?.Id, guildId, oldSocketVoiceState.VoiceSessionId);
            var voiceState    = new VoiceState(socketVoiceState.VoiceChannel?.Id, guildId, socketVoiceState.VoiceSessionId);
            var args          = new VoiceStateUpdateEventArgs(user.Id, voiceState, oldVoiceState);

            return(VoiceStateUpdated.InvokeAsync(this, args));
        }
Esempio n. 17
0
        /// <summary>
        /// VoiceChannel update redirects to a registered guild
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        private async Task Client_VoiceStateUpdated(VoiceStateUpdateEventArgs e)
        {
            var g = State.Guilds.FirstOrDefault(g => g.Guild.Id == e.Guild.Id);

            if (g != null)
            {
                await g.VoiceStateUpdated(e).ConfigureAwait(false);
            }
        }
Esempio n. 18
0
        public static async Task LogOnVoiceError(DiscordClient client, VoiceStateUpdateEventArgs e)
        {
            if (!e.Guild.VoiceStates.Values.Any(x => x.User.Id == e.User.Id))
            {
                client.Logger.LogError($"User: {e.User.Username} Channel: {e.Channel?.Name} Before: {e.Before?.Channel?.Name} " +
                                       $"After: {e.After?.Channel?.Name} In VoiceStates: {e.Guild.VoiceStates.Values.Any(x => x.User.Id == e.User.Id)} " +
                                       $"In channels: {e.Guild.Channels.Values.Where(x => x.Type == ChannelType.Category).Any(x => x.Children.Any(y => y.Users.Any(u => u.Id == e.User.Id)))}");
            }

            await Task.CompletedTask;
        }
Esempio n. 19
0
 public static async Task PrivateOnVoiceStateUpdated(DiscordClient client, VoiceStateUpdateEventArgs e)
 {
     if (e.Channel != null &&
         e.Channel.ParentId == Bot.BotSettings.PrivateCategory)
     {
         var ship = PrivateShip.GetByChannel(e.Channel.Id);
         if (ship != null)
         {
             ship.LastUsed = DateTime.Now;
         }
     }
     await Task.CompletedTask;
 }
Esempio n. 20
0
        private async Task GetVoiceStateUpdatedHandler(DiscordClient s, VoiceStateUpdateEventArgs e)
        {
            //check for clone
            ulong roleCloneID    = GetCloneRole(e.Guild.Roles);
            ulong roleTemplateID = GetTemplateRole(e.Guild.Roles);

            //Leaving Channel got deleted or has no category
            if (e.Before is null)
            {
            }
            else if (e.Before.Channel is null || e.Before.Channel.Parent is null)
            {
            }
Esempio n. 21
0
        internal LavalinkGuildConnection(LavalinkNodeConnection node, DiscordChannel channel, VoiceStateUpdateEventArgs vstu)
        {
            this.Node             = node;
            this.VoiceStateUpdate = vstu;
            this.CurrentState     = new LavalinkPlayerState();

            Volatile.Write(ref this._isDisposed, false);

            this._playerUpdated    = new AsyncEvent <PlayerUpdateEventArgs>(this.Node.Discord.EventErrorHandler, "LAVALINK_PLAYER_UPDATE");
            this._playbackFinished = new AsyncEvent <TrackFinishEventArgs>(this.Node.Discord.EventErrorHandler, "LAVALINK_PLAYBACK_FINISHED");
            this._trackStuck       = new AsyncEvent <TrackStuckEventArgs>(this.Node.Discord.EventErrorHandler, "LAVALINK_TRACK_STUCK");
            this._trackException   = new AsyncEvent <TrackExceptionEventArgs>(this.Node.Discord.EventErrorHandler, "LAVALINK_TRACK_EXCEPTION");
        }
Esempio n. 22
0
        private async Task VoiceState_Updated(VoiceStateUpdateEventArgs e)
        {
            // first check if the bot itself enters or leaves the channel
            if (e.User == Discord.CurrentUser)
            {
                return;
            }
            // then get the music data service
            music = Services.GetService <MusicData>();

            // get the voice channel the bot is in
            var vchannel = music.VoiceChannel;

            // Do nothing if bot is not connected, OR a user moves/joins a different channel the bot is not on from a channel the bot is not on, OR the user disconnects from a different channel than the bot
            if (vchannel == null || (e.After.Channel != vchannel && e.After.Channel != null && e.Before.Channel != vchannel) || (e.After.Channel == null && e.Before.Channel != vchannel))
            {
                return;
            }

            var users = vchannel.Users;

            // The disconnect timer was started but someone joined the channel
            if (users.Count() > 1 && disconnectTimer != null)
            {
                // Reset the timer
                Console.WriteLine("Timer was going but someone joined - stopping the timer!");
                disconnectTimer.Dispose();
                disconnectTimer = null;
            }

            // if it is playing and it is the only one left in the channel
            if ((users.Count() == 1 && users.First().Id == this.Discord.CurrentUser.Id))
            {
                if (music.IsPlaying)
                {
                    await music.Pause();
                }

                if (music.TextChannel != null)
                {
                    await music.TextChannel.SendMessageAsync($"{DiscordEmoji.FromName(this.Discord, ":warning:")} All members have left the voice channel - Playback paused.\nResume playback by joining the channel and using `!play`.\nAuto-Disconnecting in 5 minutes");

                    if (this.disconnectTimer == null)
                    {
                        Console.WriteLine("Setting up auto leave - starting the timer");
                        disconnectTimer = new Timer(this.DisconnectTimerCallback, e.Client, (int)TimeSpan.FromMinutes(5).TotalMilliseconds, Timeout.Infinite);
                    }
                }
            }
            // pause the player
        }
        private Task Client_VoiceStateUpdated(VoiceStateUpdateEventArgs e)
        {
            try
            {
                e.Client.DebugLogger.LogMessage(LogLevel.Info, "BotApp",
                                                $"{e.User.Username} updated voice in {e.Channel.Name} ({e.Guild.Name})", DateTime.Now);
            }
            catch (Exception)
            {
                Console.WriteLine();
            }

            return(Task.CompletedTask);
        }
Esempio n. 24
0
        private static async Task VoiceStateUpdatedEvent(VoiceStateUpdateEventArgs e)
        {
            var ch = await discord.GetChannelAsync(BotConfig.GetContext.TextChannelID);

            if (e.Channel.Name == ch.Guild.Channels[4].Name && !loggedInUser.Exists(x => { return(x.user == e.User && DateTime.Now.Date == x.stamp.Date); }))
            {
                await ch.SendMessageAsync($@"ยินดีต้อนรับกลับสู่ {ch.Guild.Channels[4].Name}, {e.User.Mention}!");

                loggedInUser.Add(new DiscordUserStamp()
                {
                    user = e.User, stamp = DateTime.Now
                });
            }
        }
Esempio n. 25
0
        private async Task Client_VoiceStateUpdated(DiscordClient client, VoiceStateUpdateEventArgs args)
        {
            if (args.After.Channel?.Id == _voiceConfig.ClickChannelId)
            {
                await AddNewVoiceChannelAsync(args.Channel, await args.Guild.GetMemberAsync(args.User.Id));
            }

            if (args.Before?.Channel != null)
            {
                if (args.Before.Channel.Id != _voiceConfig.ClickChannelId)
                {
                    await DeleteUnusedVoiceChannelAsync(args.Before.Channel);
                }
            }
        }
Esempio n. 26
0
        private Task Client_VoiceStateUpdate(VoiceStateUpdateEventArgs e)
        {
            var gid = e.GuildID;

            if (gid == 0)
            {
                return(Task.Delay(0));
            }

            if (this.VoiceStateUpdates.ContainsKey(gid))
            {
                this.VoiceStateUpdates[gid].SetResult(e);
            }

            return(Task.Delay(0));
        }
Esempio n. 27
0
        private Task Client_VoiceStateUpdate(VoiceStateUpdateEventArgs e)
        {
            var gld = e.Guild;

            if (gld == null)
            {
                return(Task.Delay(0));
            }

            if (this.VoiceStateUpdates.ContainsKey(gld.Id))
            {
                this.VoiceStateUpdates[gld.Id].SetResult(e);
            }

            return(Task.Delay(0));
        }
Esempio n. 28
0
        private static async Task Discord_VoiceStateUpdated(VoiceStateUpdateEventArgs e)
        {
            try
            {
                if (e.User.Id == DiscordClient.CurrentUser.Id)
                {
                    return;
                }
                if (e.Channel == null)
                {
                    currentlyOnVoiceChannelUsers.Remove(e.User.Id);
                    var ch = await DiscordClient.GetDefaultChannelAsync();

                    await ch.SendDisposableMessageAsync($"{e.User.Mention} ออกจากห้องแล้ว");
                }
                else if (e.Channel != null && !currentlyOnVoiceChannelUsers.Contains(e.User.Id))
                {
                    currentlyOnVoiceChannelUsers.Add(e.User.Id);
                    var ch = await DiscordClient.GetDefaultChannelAsync();

                    var voiceCh = ch.Guild.Channels.FirstOrDefault(x => x.Value.Type == ChannelType.Voice && x.Value.Id == AppConfiguration.Content.Discord.ActiveVoiceChannelId);
                    if (e.Channel?.Id == voiceCh.Value?.Id)
                    {
                        {
                            await ch.SendDisposableMessageAsync($@"ยินดีต้อนรับกลับมาขอรับ {e.User.Mention}!");
                        }
                    }
                }
                if (currentlyOnVoiceChannelUsers.Count > 0)
                {
                    await DiscordClient.UpdateStatusAsync(new DiscordActivity()
                    {
                        Name = $"กำลังดูแลแขก {currentlyOnVoiceChannelUsers.Count} ท่านในขณะนี้"
                    });;
                }
                else
                {
                    await DiscordClient.UpdateStatusAsync(DiscordGameExtension.GetRandomActivity());
                }
                Console.WriteLine($"[VoiceState] : Trigger by {e.User.Id}");
            }
            catch (Exception ex)
            {
                Service.Context.ExceptionLog.Insert(new Models.ExceptionLog(nameof(Discord_VoiceStateUpdated), ex));
            }
        }
Esempio n. 29
0
        private static Task _discord_VoiceStateUpdated(VoiceStateUpdateEventArgs e)
        {
            var user = e.User.Username;

            var voicechannel = e.Guild.GetChannel(359651553973370880);
            var textchannel  = e.Guild.GetChannel(359645522601967617);

            textchannel.SendMessageAsync(user + " joined " + $"{e.Channel.Name}" + "!");


            /*if (voicechannel != "development")
             * {
             *  textchannel.SendMessageAsync(user + " left " + voicechannelname + "!");
             * }*/

            return(Task.CompletedTask);
        }
Esempio n. 30
0
        private Task Client_VoiceStateUpdated(DiscordClient sender, VoiceStateUpdateEventArgs e)
        {
            //TODO test this
            DiscordMember member          = (DiscordMember)e.After.User;    //a veces esto peta y no se por que
            bool          isuserconnected = !(member.VoiceState.Channel is null);

            if (isuserconnected)
            {
                member.GrantRoleAsync(onVC);
            }
            else
            {
                member.RevokeRoleAsync(onVC);
            }

            return(Task.CompletedTask);
        }