示例#1
0
        public IHttpResponse Follow(int id)
        {
            var channel = this.Context.Channels.FirstOrDefault(c => c.Id == id);

            if (channel == null)
            {
                return(this.BadRequestError("Invalid channel id."));
            }

            var userUsername = this.User.Username;
            var user         = this.Context.Users.First(u => u.Username == userUsername);

            var userChannel = new UserChannel
            {
                Channel = channel,
                User    = user
            };

            this.Context.UsersChannels.Add(userChannel);

            try
            {
                this.Context.SaveChanges();
            }
            catch (Exception e)
            {
                return(this.BadRequestErrorWithView(e.Message));
            }

            return(this.Redirect("/"));
        }
示例#2
0
        public async Task IncrementMessageStats(SocketGuild guild, SocketUser user, ISocketMessageChannel channel)
        {
            var userEntity = await GrillBotRepository.UsersRepository.GetOrCreateUserAsync(guild.Id, user.Id, UsersIncludes.Channels);

            var channelEntity = userEntity.Channels.FirstOrDefault(o => o.ChannelIDSnowflake == channel.Id);

            if (channelEntity == null)
            {
                channelEntity = new UserChannel()
                {
                    ChannelIDSnowflake = channel.Id,
                    Count         = 1,
                    LastMessageAt = DateTime.Now,
                };

                userEntity.Channels.Add(channelEntity);
            }
            else
            {
                channelEntity.Count++;
                channelEntity.LastMessageAt = DateTime.Now;
            }

            await GrillBotRepository.CommitAsync();
        }
示例#3
0
        public async Task Create(ChannelCreateRequest values)
        {
            var user = await dataContext.Users.FirstOrDefaultAsync(u => u.Username == userAccessor.GetCurrentUsername());

            if (await dataContext.Channels.AnyAsync(c => c.Name == values.Name))
            {
                throw new RestException(HttpStatusCode.BadRequest, new { details = "Channel name is already used" });
            }

            var channel = new Channel
            {
                Id             = values.Id,
                HashedPassword = values.Password.ToSHA256(),
                Name           = values.Name
            };

            var userChannel = new UserChannel
            {
                User      = user,
                Channel   = channel,
                IsCreator = true
            };
            await dataContext.UserChannels.AddAsync(userChannel);

            var success = await dataContext.SaveChangesAsync() > 0;

            if (!success)
            {
                throw new Exception("Problem occured during saving changes.");
            }
        }
        public async Task <ActionResult> GoogleOAuth(string code)
        {
            var userId = int.Parse(Session["CurrentUserId"].ToString());
            var token  = await gmailService.GetToken(code);

            if (!token.HasError)
            {
                var isConnected = gmailService.IsConnected(token.Result);
                if (isConnected)
                {
                    var emailChannel = mapper.Map <ChannelEmail>(token.Result);
                    emailChannel.CreatedDate = DateTime.UtcNow;
                    emailChannel.Id          = channelEmailService.Create(emailChannel);

                    var userEmailChannel = new UserChannel()
                    {
                        UserId      = userId,
                        ChannelId   = emailChannel.Id,
                        ChannelType = Shared.Enums.ChannelType.Email,
                        IsActive    = true,
                    };
                    userEmailChannel.Id = userChannelSerivce.Create(userEmailChannel);

                    var userMagentoChannel = userChannelSerivce.FindUserChannels(userId).SingleOrDefault(channel => channel.ChannelType == Shared.Enums.ChannelType.Magento && channel.IsActive == true);

                    if (userMagentoChannel != null)
                    {
                        CreateConnection(userEmailChannel.Id, userMagentoChannel.Id);
                    }
                }
            }
            return(RedirectToAction("Index", new { userId = userId }));
        }
        //must set the 'Accept url' on eBay Developer page as https://<domain-name>/ServiceConnection/EBayLoginAgree
        public ActionResult EBayLoginAgree(string ebaytkn, string tknexp, string username)
        {
            var userId = int.Parse(Session["CurrentUserId"].ToString());
            var token  = ebayService.GetToken(eBaySessionId);

            if (!token.HasError)
            {
                var tokenStatus = ebayService.GetTokenStatus(token.Result);
                var channeleBay = new ChannelEbay
                {
                    Token       = token.Result,
                    ExpiredDate = tokenStatus.Result.ExpirationTime,
                    CreatedDate = DateTime.UtcNow
                };
                channeleBay.Id = channelEbayService.Create(channeleBay);

                var userEbayChannel = new UserChannel()
                {
                    UserId      = userId,
                    ChannelId   = channeleBay.Id,
                    ChannelType = Shared.Enums.ChannelType.Ebay,
                    IsActive    = true,
                };
                userEbayChannel.Id = userChannelSerivce.Create(userEbayChannel);

                var userMagentoChannel = userChannelSerivce.FindUserChannels(userId).SingleOrDefault(channel => channel.ChannelType == Shared.Enums.ChannelType.Magento && channel.IsActive == true);
                if (userMagentoChannel != null)
                {
                    CreateConnection(userEbayChannel.Id, userMagentoChannel.Id);
                }
            }
            return(RedirectToAction("Index", new { userId = userId }));
        }
示例#6
0
        public static AppletUser CreateInstance(
            string openId,
            string organizationId,
            string appId,
            UserChannel channel = UserChannel.WeChat,
            string nickName     = "",
            string userPortrait = "",
            string userId       = "")
        {
            var result = new AppletUser
            {
                ApplicationId  = appId,
                Channel        = channel,
                NickName       = nickName,
                OpenId         = openId,
                OrganizationId = organizationId,
                UserId         = userId,
                UserPortrait   = userPortrait,
                CreatedOn      = DateTime.Now,
                LastUpdOn      = DateTime.Now
            };

            result.GenerateId();

            return(result);
        }
示例#7
0
        public IHttpResponse Follow(int id)
        {
            var user = this.DbContext.Users.FirstOrDefault(u => u.Username == this.User.Username);

            var channel = this.DbContext.Channels.FirstOrDefault(c => c.Id == id);

            if (channel == null)
            {
                return(this.BadRequestErrorWithView($"Channel with id {id} not found."));
            }

            var userChannel = new UserChannel()
            {
                UserId    = user.Id,
                ChannelId = channel.Id,
            };

            this.DbContext.UserChannels.Add(userChannel);
            try
            {
                this.DbContext.SaveChanges();
            }
            catch (Exception e)
            {
                return(this.ServerError(e.Message));
            }

            return(this.Redirect("/"));
        }
示例#8
0
        public bool Follow(int channelId, string username)
        {
            var user    = this.context.Users.SingleOrDefault(p => p.Username == username);
            var channel = this.context.Channels.SingleOrDefault(p => p.Id == channelId);

            if (user == null || channel == null)
            {
                return(false);
            }

            if (this.context.UserChannels.Any(p => p.UserId == user.Id && p.ChannelId == channelId))
            {
                return(false);
            }

            var userChannel = new UserChannel
            {
                User    = user,
                Channel = channel
            };

            user.ChannelsFollowing.Add(userChannel);
            context.SaveChanges();
            channel.Followers.Add(userChannel);
            context.SaveChanges();

            return(true);
        }
示例#9
0
        public bool SavePerson(string channelId, string userId, Person person)
        {
            var userChannel = new UserChannel {
                ChannelId = channelId, UserId = userId
            };
            var user = GetUserByUserChannel(userChannel);

            if (user != null)
            {
                _dbContext.Entry(user).State = EntityState.Modified;
            }
            else
            {
                user = new User {
                    Channels = new List <UserChannel> {
                        userChannel
                    }
                };
                _dbContext.Users.Add(user);
            }

            user.Name     = person.Name;
            user.WorkArea = person.WorkArea;
            user.Age      = person.Age;
            user.Gender   = person.Gender;

            return(_dbContext.SaveChanges() > 0);
        }
示例#10
0
        /// <summary>
        /// Adds user to a specific channel and notifies all other channel members
        /// </summary>
        /// <param name="username"></param>
        /// <param name="channelId"></param>
        /// <returns></returns>
        public async Task Join(string username, string channelId)
        {
            var userId         = Context.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value;
            var queriedChannel = await _context.Channel.FindAsync(channelId);

            if (string.IsNullOrEmpty(userId) || queriedChannel == null)
            {
                throw new HubException("Invalid user or channel id provided.");
            }

            await Groups.AddToGroupAsync(Context.ConnectionId, channelId);

            // If user first time joining, notify other chat members and save to the db
            var queriedUserChannel = await _context.UserChannel.FindAsync(userId, channelId);

            if (queriedUserChannel == null)
            {
                await Clients.Group(channelId).SendAsync("Join", BuildNotification(channelId, $"{username} à rejoint le canal."));

                var newUserChannel = new UserChannel
                {
                    UserId    = userId,
                    ChannelId = channelId
                };

                await _context.UserChannel.AddAsync(newUserChannel);

                await _context.SaveChangesAsync();
            }
        }
示例#11
0
        public Person GetPerson(string channelId, string userId)
        {
            var userChannel = new UserChannel {
                ChannelId = channelId, UserId = userId
            };

            return(GetUserByUserChannel(userChannel));
        }
示例#12
0
        public ServiceResult <bool> assignChannelToUser(long idChannel, string username)
        {
            var newAssing = new UserChannel
            {
                idChannel = idChannel,
                userTag   = username
            };

            _userChannelRepository.Add(newAssing);
            _userChannelRepository.saveChanges();
            return(ServiceResult <bool> .SuccessResult(true));
        }
示例#13
0
        public IActionResult PutUser([FromRoute] int id, [FromBody] User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != user.UserID)
            {
                return(BadRequest("There is no match between the user id and id. "));
            }

            if (!UserExists(id))
            {
                return(NotFound("There is no user with the requested id."));
            }

            _context.Entry(user).State = EntityState.Modified;

            try
            {
                _context.SaveChanges();
                var channelsByUser = _context.UserChannels.Where(s => s.UserID.Equals(id));
                _context.UserChannels.RemoveRange(channelsByUser);
                _context.SaveChanges();
                if (user.UsersChannels != null)
                {
                    foreach (var el in user.UsersChannels.Where(s => s.ChannelID > 0))
                    {
                        if (ChannelExists(el.ChannelID) && ChannelExists(el.Name))
                        {
                            var userchannel = new UserChannel {
                                UserID = user.UserID, ChannelID = el.ChannelID
                            };
                            _context.UserChannels.Add(userchannel);
                            _context.SaveChanges();
                        }
                        else
                        {
                            return(BadRequest("Channel model is not valid."));
                        }
                    }
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(CreatedAtAction("GetUser", new { id = user.UserID }, user));
        }
示例#14
0
        public IActionResult PutChannel([FromRoute] int id, [FromBody] Channel channel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != channel.ChannelID)
            {
                return(BadRequest("There is no match between the channel id and id. "));
            }

            if (!ChannelExists(id))
            {
                return(NotFound("There is no channel with the requested id."));
            }

            _context.Entry(channel).State = EntityState.Modified;

            try
            {
                _context.SaveChanges();
                var usersBychannel = _context.UserChannels.Where(s => s.ChannelID.Equals(id));
                _context.UserChannels.RemoveRange(usersBychannel);
                _context.SaveChanges();
                if (channel.ChannelUsers != null)
                {
                    foreach (var el in channel.ChannelUsers.Where(s => s.UserID > 0))
                    {
                        if (UserExists(el.UserID) && UserExists(el.Name))
                        {
                            var userchannel = new UserChannel {
                                UserID = el.UserID, ChannelID = id
                            };
                            _context.UserChannels.Add(userchannel);
                            _context.SaveChanges();
                        }
                        else
                        {
                            return(BadRequest("User model is not valid."));
                        }
                    }
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;
            }

            return(CreatedAtAction("Getchannel", new { id = channel.ChannelID }, channel));
        }
示例#15
0
        public async Task <UserChannel> AddNewUserToGeneral(string username)
        {
            var user = await userManager.FindByNameAsync(username);

            var newUC = new UserChannel
            {
                UserId      = user.Id,
                ChannelName = "General",
            };

            _context.UserChannels.Add(newUC);
            await _context.SaveChangesAsync();

            return(newUC);
        }
示例#16
0
        public void FollowChannel(int channelId, string username)
        {
            var user    = this.context.Users.FirstOrDefault(u => u.Username == username);
            var channel = this.context.Channels.FirstOrDefault(ch => ch.Id == channelId);

            var userChannel =
                new UserChannel {
                ChannelId = channelId, Channel = channel, UserId = user.Id, User = user
            };

            this.context.UsersChannels.Add(userChannel);
            user.FollowedChannels.Add(userChannel);
            channel.Followers.Add(userChannel);
            this.context.SaveChanges();
        }
        public void UnfollowChannel(int channelId, string username)
        {
            using (var db = new MishMashDbContext())
            {
                int userId = db.Users.FirstOrDefault(u => u.Username == username).Id;

                UserChannel userChannel = db.UserChannels
                                          .FirstOrDefault(uc => uc.UserId == userId && uc.ChannelId == channelId);

                if (userChannel != null)
                {
                    db.UserChannels.Remove(userChannel);

                    db.SaveChanges();
                }
            }
        }
        public IHttpResponse Follow(string id)
        {
            var user = this.ApplicationDbContext
                       .Users
                       .FirstOrDefault(x => x.Username == this.User.Username);

            var channel = this.ApplicationDbContext
                          .Channels
                          .FirstOrDefault(x => x.Id == id);
            //Many-to-many relation, take user, take channel, save 2 ids so for every user there is channel id even if its the same user
            var userChannel = new UserChannel
            {
                Channel = channel,
                User    = user
            };

            user.FollowedChannels.Add(userChannel);
            this.ApplicationDbContext.SaveChanges();
            return(this.Redirect("/"));
        }
示例#19
0
        public async Task SetCurrentProxy(Proxy proxy, BotUser botUser, ulong channelId)
        {
            using (var db = GetDataContext())
            {
                var dbUser = await GetUser(db, botUser);

                if (dbUser != null)
                {
                    var dbProxy = dbUser.Proxies.FirstOrDefault(p => p.Id == proxy.Id);
                    var uc      = dbUser.Channels.FirstOrDefault(c => c.Channel.DiscordId == channelId);

                    if (proxy.IsGlobal && dbUser.IsAllowedGlobal)
                    {
                        dbUser.LastGlobalProxy = dbProxy;
                    }
                    else
                    {
                        if (uc == null)
                        {
                            uc = new UserChannel
                            {
                                Channel = await db.Channels.FirstOrDefaultAsync(c => c.DiscordId == channelId) ??
                                          new Channel
                                {
                                    DiscordId = channelId
                                },
                                BotUser = dbUser,
                            };
                            dbUser.Channels.Add(uc);
                        }

                        uc.LastProxy = dbProxy;
                    }
                }

                await db.SaveChangesAsync();
            }
        }
示例#20
0
        public IHttpResponse Follow(int Id)
        {
            if (!this.DbContext.Channels.Any(ch => ch.Id == Id))
            {
                return(this.BadRequestError("Channel doesn't exist!"));
            }

            int         userId      = this.DbContext.Users.Where(u => u.Username == this.User).First().Id;
            UserChannel userChannel = new UserChannel()
            {
                UserId    = userId,
                ChannelId = Id
            };

            if (this.DbContext.UserChannels.Any(uc => uc.UserId == userId && uc.ChannelId == Id))
            {
                return(this.BadRequestError("You have already followed this channel!"));
            }
            this.DbContext.UserChannels.Add(userChannel);
            this.DbContext.SaveChanges();

            return(this.Redirect("/"));
        }
示例#21
0
        protected override void InitializeDistributedService()
        {
            base.InitializeDistributedService();
            if (IsUser == false)
            {
                this.FocusMap = new Dictionary <IUserModel, TFocus>();
            }

            this.ShardAddFocus    = CreateShardChannel <FocusPacket>("add");
            this.ShardRemoveFocus = CreateShardChannel <FocusPacket>("remove");
            this.ShardUpdateFocus = CreateShardChannel <FocusPacket>("update");

            this.ShardAddRegion    = CreateShardChannel <RegionPacket>("add");
            this.ShardRemoveRegion = CreateShardChannel <RegionPacket>("remove");
            this.ShardUpdateRegion = CreateShardChannel <RegionPacket>("update");

            this.UserAddRegion    = CreateUserChannel <RegionPacket>("add");
            this.UserRemoveRegion = CreateUserChannel <RegionPacket>("remove");
            this.UserUpdateRegion = CreateUserChannel <RegionPacket>("update");

            this.UserSetFocus    = CreateUserChannel <FocusPacket>("set");
            this.UserUpdateFocus = CreateUserChannel <FocusPacket>("update");
        }
        public ActionResult MagentoConnect(ChannelMagentoViewModel model)
        {
            var userId      = int.Parse(Session["CurrentUserId"].ToString());
            var isConnected = magentoService.IsConnected(model.Host, model.Username, model.Password);

            if (isConnected)
            {
                var channelMagento = mapper.Map <ChannelMagento>(model);
                channelMagento.CreatedDate = DateTime.UtcNow;
                channelMagento.Id          = channelMagentoService.Create(channelMagento);

                var userMagentoChannel = new UserChannel()
                {
                    UserId      = userId,
                    ChannelId   = channelMagento.Id,
                    ChannelType = Shared.Enums.ChannelType.Magento,
                    IsActive    = true,
                };

                userMagentoChannel.Id = userChannelSerivce.Create(userMagentoChannel);

                var userEbayChannel = userChannelSerivce.FindUserChannels(userId).SingleOrDefault(userChannel => userChannel.ChannelType == Shared.Enums.ChannelType.Ebay && userChannel.IsActive);

                if (userEbayChannel != null)
                {
                    CreateConnection(userEbayChannel.Id, userMagentoChannel.Id);
                }

                var userEmailChannel = userChannelSerivce.FindUserChannels(userId).SingleOrDefault(userChannel => userChannel.ChannelType == Shared.Enums.ChannelType.Email && userChannel.IsActive);
                if (userEmailChannel != null)
                {
                    CreateConnection(userEmailChannel.Id, userMagentoChannel.Id);
                }
            }

            return(RedirectToAction("Index", new { userId = userId }));
        }
示例#23
0
        public IActionResult PostUser([FromBody] User user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Users.Add(user);
            try
            {
                _context.SaveChanges();
                if (user.UsersChannels != null)
                {
                    foreach (var ls in user.UsersChannels.Where(s => s.ChannelID > 0))
                    {
                        if (ChannelExists(ls.ChannelID) && ChannelExists(ls.Name))
                        {
                            var userchannel = new UserChannel {
                                UserID = user.UserID, ChannelID = ls.ChannelID
                            };
                            _context.UserChannels.Add(userchannel);
                            _context.SaveChanges();
                        }
                        else
                        {
                            return(BadRequest("Channel model is not valid."));
                        }
                    }
                }
            }
            catch (DbUpdateConcurrencyException)
            {
                throw;// "Error during insert entry in many-many table"
            }

            return(CreatedAtAction("GetUser", new { id = user.UserID }, user));
        }
示例#24
0
        public async Task Leave(Guid id)
        {
            var userChannel = await dataContext.UserChannels.FirstOrDefaultAsync(uc => uc.ChannelId == id && uc.User.Username == userAccessor.GetCurrentUsername());

            if (userChannel == null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { details = "Could not leave channel" });
            }

            UserChannel newCreator = null;

            if (userChannel.IsCreator)
            {
                newCreator = await dataContext.UserChannels.FirstOrDefaultAsync(uc => uc.ChannelId == id && !uc.IsCreator);

                if (newCreator != null)
                {
                    newCreator.IsCreator = true;
                }
                else
                {
                    dataContext.Remove(userChannel.Channel);
                }
            }

            if (newCreator != null)
            {
                dataContext.UserChannels.Remove(userChannel);
            }

            var success = await dataContext.SaveChangesAsync() > 0;

            if (!success)
            {
                throw new Exception("Problem occured during saving changes.");
            }
        }
示例#25
0
        protected override void InitializeDistributedService()
        {
            base.InitializeDistributedService();
            SendMessages = true;

            ShardAddModel    = CreateShardChannel <AddModel>();
            ShardRemoveModel = CreateShardChannel <RemoveModel>();
            ShardUpdateModel = CreateShardChannel <UpdateModel>();
            ShardUpdateSet   = CreateShardChannel <UpdateSet>();

            ShardAddModel.Receive    += addModel;
            ShardRemoveModel.Receive += removeModel;
            ShardUpdateModel.Receive += updateModel;
            ShardUpdateSet.Receive   += updateSet;

            UserAddModel    = CreateUserChannel <AddModel>();
            UserRemoveModel = CreateUserChannel <RemoveModel>();
            UserUpdateModel = CreateUserChannel <UpdateModel>();
            UserUpdateSet   = CreateUserChannel <UpdateSet>();

            UserAddModel.Receive    += addModel;
            UserRemoveModel.Receive += removeModel;
            UserUpdateModel.Receive += updateModel;
            UserUpdateSet.Receive   += updateSet;

            Models = new ModelTrackerCollection <TModel>();
            Models.ModelAddedEvent   += OnModelAdded;
            Models.ModelRemovedEvent += OnModelRemoved;
            Models.ModelUpdatedEvent += OnModelUpdated;

            if (IsRouter)
            {
                RouterController.ShardController.NetUserConnected += OnShardConnected;
                RouterController.UserController.NetUserConnected  += OnUserConnected;
            }
        }
示例#26
0
        public static User CreateInstance(string userName, string mobile, string email, string password, string nickName, string operatedBy, UserPartition partition = UserPartition.JianPing, UserChannel channel = UserChannel.JianPingApp)
        {
            var now = DateTime.Now;

            return(new User
            {
                Mobile = mobile,
                Channel = channel,
                CreatedBy = operatedBy,
                CreatedOn = now,
                Email = email,
                NickName = nickName,
                Partition = partition,
                Password = SecretProvider.EncryptToMD5(password),
                UpdatedBy = operatedBy,
                UpdatedOn = now,
                UserName = userName,
                IsSuspend = false
            });
        }
示例#27
0
 public ChannelStatItem(IChannel channel, UserChannel userChannel)
 {
     Count         = userChannel.Count;
     LastMessageAt = userChannel.LastMessageAt;
     Channel       = channel;
 }
示例#28
0
 private User GetUserByUserChannel(UserChannel userChannel)
 {
     return(_dbContext.Users.FirstOrDefault(u => u.Channels.Any(c => c.EqualByMembers(userChannel))));
 }
示例#29
0
        }                        // Json

        public async Task <bool> ConnectAsync(ICommandContext Context = null, IVoiceChannel Channel = null)
        {
            if (Context == null)
            {
                if (VoiceChannelId == 0)
                {
                    return(false);
                }
                else
                {
                    if (Global.Client.GetChannel(VoiceChannelId) is IVoiceChannel channel)
                    {
                        try
                        {
                            Client = await channel.ConnectAsync();

                            State = PlayerState.Connected;
                            return(true);
                        }
                        catch { }
                    }
                    return(false);
                }
            }
            await DisconnectAsync();

            LanguageEntry Language = Context.GetSettings().GetLanguage();

            if (Channel != null)
            {
                try
                {
                    Client = await Channel.ConnectAsync();

                    VoiceChannelId = Channel.Id;
                    await Context.Channel.SendMessageAsync(Language.GetEntry("MusicHandler:ConnectedTo", "NAME", Channel.Name));
                }
                catch (Exception e)
                {
                    string msg = $"```${ e }```";
                    if (Global.Client.GetChannel(Global.Settings.DevServer.ErrorReportChannelId) is ITextChannel errChannel)
                    {
                        await Global.SendMessageAsync(msg, errChannel);
                    }
                    await Context.Channel.SendMessageAsync(Language.GetEntry("MusicHandler:CannotConnectToChannel"));

                    return(false);
                }
            }
            else if ((Context.User as IGuildUser).VoiceChannel is IVoiceChannel UserChannel)
            {
                try
                {
                    Client = await UserChannel.ConnectAsync();

                    VoiceChannelId = UserChannel.Id;
                    await Context.Channel.SendMessageAsync(Language.GetEntry("MusicHandler:ConnectedTo", "NAME", UserChannel.Name));
                }
                catch (Exception e)
                {
                    string msg = $"```${ e }```";
                    if (Global.Client.GetChannel(Global.Settings.DevServer.ErrorReportChannelId) is ITextChannel errChannel)
                    {
                        await Global.SendMessageAsync(msg, errChannel);
                    }
                    await Context.Channel.SendMessageAsync(Language.GetEntry("MusicHandler:CannotConnectToUser"));

                    return(false);
                }
            }
            else
            {
                IReadOnlyCollection <IVoiceChannel> Channels = await Context.Guild.GetVoiceChannelsAsync();

                IEnumerator <IVoiceChannel> enumerator = Channels.GetEnumerator();
                bool Connected = false;

                for (int i = 0; i < Channels.Count; i++)
                {
                    enumerator.MoveNext();

                    try
                    {
                        Client = await enumerator.Current.ConnectAsync();

                        await Context.Channel.SendMessageAsync(Language.GetEntry("MusicHandler:ConnectedTo", "NAME", enumerator.Current.Name));

                        VoiceChannelId = enumerator.Current.Id;
                        Connected      = true;
                        break;
                    }
                    catch { } // has no permission to connect
                }
                if (!Connected)
                {
                    await Context.Channel.SendMessageAsync(Language.GetEntry("MusicHandler:CannotConnectToAny"));
                }
            }

            State = PlayerState.Connected;

            // Assumption: only triggered when exception
            Client.Disconnected += (e) =>
            {
                if (!DisconnectInvoked)
                {
                    SetDisconnected();
                }
                return(Task.CompletedTask);
            };
            return(true);
        }