Example #1
0
        public async Task <List <BotGearUser> > getServerMembersbyServerId(string id)
        {
            try
            {
                List <BotGearUser> ap = null;
                if (id != null && await this.ServerExists(id) == true)
                {
                    BotGearServer srv = await this.getServerbyId(id);

                    List <BotGearUsersServers> usrvs = db.UsersServers.ToList().FindAll(x => x.ServerId == id);
                    if (usrvs != null)
                    {
                        ap = new List <BotGearUser>();
                        foreach (var u in usrvs)
                        {
                            BotGearUser user = await usrmngr.GetUserbyId(u.UserId);

                            if (user != null)
                            {
                                ap.Add(user);
                            }
                        }
                    }
                }

                return(ap);
            }
            catch (Exception ex)
            {
                CommonTools.ErrorReporting(ex);
                return(null);
            }
        }
        public BotGearServer IGuildToBotGearServer(IGuild iguild)
        {
            try
            {
                BotGearServer btuset = null;

                if (iguild != null)
                {
                    btuset = new BotGearServer();
                    // btuset.AvatarId = iuser.AvatarId;
                    btuset.CreatedAt = iguild.CreatedAt.DateTime;
                    btuset.Id        = Convert.ToString(iguild.Id);
                    btuset.OwnerId   = Convert.ToString(iguild.OwnerId);
                    btuset.Name      = iguild.Name;
                }


                return(btuset);
            }
            catch (Exception ex)
            {
                CommonTools.ErrorReporting(ex);
                return(null);
            }
        }
Example #3
0
        public async Task <List <BotGearServer> > getServerbymeMeberId(string memid)
        {
            try
            {
                List <BotGearServer> ap = null;
                if (memid != null)
                {
                    var servusr = db.UsersServers.ToList().FindAll(x => x.UserId == memid).ToList();
                    if (servusr != null)
                    {
                        ap = new List <BotGearServer>();
                        foreach (var s in servusr)
                        {
                            BotGearServer serv = await this.getServerbyId(s.ServerId);

                            if (serv != null)
                            {
                                ap.Add(serv);
                            }
                        }
                    }
                }

                return(ap);
            }
            catch (Exception ex)
            {
                CommonTools.ErrorReporting(ex);
                return(null);
            }
        }
Example #4
0
        public async Task addUser(IUser iuser, DateTime birthday, IGuild iguild)
        {
            try
            {
                if (iuser != null && birthday != null && iguild != null)
                {
                    BotGearUser user   = conv.IUserToBotGearUser(iuser);
                    BotGearUser exuser = await this.GetUserbyId(user.Id);

                    BotGearServer srv = this.conv.IGuildToBotGearServer(iguild);

                    if (user != null && exuser == null && srv != null)
                    {
                        if (await srvMngr.ServerExists(srv.Id) != true)
                        {
                            await this.srvMngr.addServer(iguild);
                        }
                        else
                        {
                            string id = srv.Id;
                            srv = await srvMngr.getServerbyId(id);
                        }

                        user.Birthday     = birthday;
                        user.RegisteredAt = DateTime.Now;

                        db.Users.Add(user);
                        db.SaveChanges();
                        user = await this.GetUserbyId(user.Id);

                        if (await srvMngr.IsMembersToServer(srv.Id, user.Id) == false)
                        {
                            await this.srvMngr.AddMemberToServer(iguild, iuser);
                        }
                    }
                    else if (user != null && exuser != null && srv != null)
                    {
                        if (await srvMngr.ServerExists(srv.Id) != true)
                        {
                            await this.srvMngr.addServer(iguild);
                        }
                        else
                        {
                            string id = srv.Id;
                            srv = await srvMngr.getServerbyId(id);
                        }
                        if (await srvMngr.IsMembersToServer(srv.Id, exuser.Id) == false)
                        {
                            await this.srvMngr.AddMemberToServer(iguild, iuser);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CommonTools.ErrorReporting(ex);
            }
        }
        public async Task GetUserList()
        {
            try
            {
                string msg = "";

                UserManager     usrmngr = new UserManager();
                var             tusers  = usrmngr.GetUsers();
                ModuleConverter conv    = new ModuleConverter();
                BotGearServer   srv     = conv.IGuildToBotGearServer(Context.Guild);
                ServerManager   srvMngr = new ServerManager();
                if (tusers != null && srv != null)
                {
                    var users = await srvMngr.getServerMembersbyServerId(srv.Id);

                    if (users != null)
                    {
                        StringBuilder bld = new StringBuilder();
                        bld.AppendLine("Registered users with the bot in server : " + Context.Guild.Name);
                        foreach (var c in users)
                        {
                            bld.AppendFormat("\nId :{0}", c.Id);
                            bld.AppendFormat("\nUserName :{0}", c.Username);
                            bld.AppendFormat("\nBirthday  :{0}", c.Birthday);
                            bld.AppendFormat("\nCreated at :{0}", c.CreatedAt);
                            bld.AppendFormat("\nRegisted at: :{0}", c.RegisteredAt);
                            bld.AppendFormat("\nDiscriminator :{0}", c.Discriminator);
                            bld.AppendFormat("\nDiscriminator Value :{0}", c.DiscriminatorValue);

                            bld.AppendLine();
                        }
                        msg = bld.ToString();
                    }
                }
                else
                {
                    StringBuilder bld = new StringBuilder();
                    bld.AppendLine("Registered users with the bot in server : " + Context.Guild.Name);
                    bld.AppendLine("There are no users  ");
                    msg = bld.ToString();
                }


                var channel = await Context.User.GetOrCreateDMChannelAsync();

                if (channel != null)
                {
                    await channel.SendMessageAsync(msg);
                }


                //await ReplyAsync(msg);
            }
            catch (Exception ex)
            {
                CommonTools.ErrorReporting(ex);
            }
        }
Example #6
0
 public async Task addServer(IGuild iguild)
 {
     try
     {
         BotGearServer srv = conv.IGuildToBotGearServer(iguild);
         if (srv != null && iguild != null && await this.ServerExists(srv.Id) == false)
         {
             db.Servers.Add(srv);
             db.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         CommonTools.ErrorReporting(ex);
     }
 }
Example #7
0
        public async Task <BotGearServer> getServerbyId(string id)
        {
            try
            {
                BotGearServer ap = null;
                if (id != null)
                {
                    ap = db.Servers.FirstOrDefault(x => x.Id == id);
                }

                return(ap);
            }
            catch (Exception ex)
            {
                CommonTools.ErrorReporting(ex);
                return(null);
            }
        }
Example #8
0
        public async Task  deleteServerbyId(string id)
        {
            try
            {
                if (id != null && await  this.ServerExists(id) == true)
                {
                    BotGearServer srv = await this.getServerbyId(id);

                    if (srv != null)
                    {
                        db.Servers.Remove(srv);
                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                CommonTools.ErrorReporting(ex);
            }
        }
Example #9
0
        public async Task EditServerInfo(string id, IGuild iguild)
        {
            try
            {
                BotGearServer srv = conv.IGuildToBotGearServer(iguild);
                if (srv != null && iguild != null && await this.ServerExists(id) == false)
                {
                    BotGearServer srv0 = await this.getServerbyId(id);

                    if (srv0 != null)
                    {
                        db.Entry(srv0).CurrentValues.SetValues(srv);

                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                CommonTools.ErrorReporting(ex);
            }
        }
Example #10
0
        public async Task <Boolean> ServerExists(string id)
        {
            try
            {
                Boolean ap = false;
                if (id != null)
                {
                    BotGearServer serv = await this.getServerbyId(id);

                    if (serv != null)
                    {
                        ap = true;
                    }
                }

                return(ap);
            }
            catch (Exception ex)
            {
                CommonTools.ErrorReporting(ex);
                return(false);;
            }
        }
Example #11
0
        public async Task banUser(string iuser, string reason, IGuild iguild)
        {
            try
            {
                if (iuser != null && reason != null && iguild != null)
                {
                    BotGearPreBannedUser exuser = await this.GetPreBannedUserbyIdAndServerId(iuser, Convert.ToString(iguild.Id));

                    BotGearServer srv = this.conv.IGuildToBotGearServer(iguild);

                    if (exuser == null && srv != null)
                    {
                        if (await srvMngr.ServerExists(srv.Id) != true)
                        {
                            await this.srvMngr.addServer(iguild);
                        }
                        else
                        {
                            string id = srv.Id;
                            srv = await srvMngr.getServerbyId(id);
                        }
                        exuser          = new BotGearPreBannedUser();
                        exuser.ServerId = srv.Id;
                        exuser.UserId   = iuser;
                        exuser.Date     = DateTime.Now;
                        exuser.Reason   = reason;
                        db.PreBannedUsers.Add(exuser);

                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                CommonTools.ErrorReporting(ex);
            }
        }