示例#1
0
 /// <summary>
 ///     check the rank of the specified user corresponds with their score.
 /// </summary>
 /// <param name="server">current server</param>
 /// <param name="user">user to modify</param>
 /// <param name="subject">user profile</param>
 /// <returns></returns>
 public async Task CheckRank(Servers.Server server, IUser user, Servers.Server.User subject)
 {
     foreach (var role in server.Ranks)
     {
         var u = user as IGuildUser;
         var r = Context.Guild.GetRole(role.RoleId);
         if (u != null && u.RoleIds.Contains(role.RoleId))
         {
             await u.RemoveRoleAsync(r);
         }
     }
     try
     {
         var toprole = server.Ranks.Where(x => x.Points <= subject.Points).Max(x => x.Points);
         var top     = server.Ranks.Where(x => x.Points == toprole);
         try
         {
             var first = top.FirstOrDefault();
             if (first != null)
             {
                 var newrole = Context.Guild.GetRole(first.RoleId);
                 await((IGuildUser)user).AddRoleAsync(newrole);
             }
         }
         catch
         {
             //role has been deleted
         }
     }
     catch
     {
         // No available roles
     }
 }
示例#2
0
        public async Task Register(IUser user, [Remainder] string username = null)
        {
            var embed = new EmbedBuilder();

            if (username == null)
            {
                embed.AddField("ERROR", "Please specify a name to be registered with");
                embed.WithColor(Color.Red);
                await ReplyAsync("", false, embed.Build());
            }
            else
            {
                var usr = new Servers.Server.User
                {
                    UserId   = user.Id,
                    Username = username,
                    Points   = 0
                };

                var server = Servers.ServerList.First(x => x.ServerId == Context.Guild.Id);
                if (server.UserList.Count >= 20)
                {
                    if (!server.IsPremium)
                    {
                        embed.AddField("ERROR",
                                       "Free User limit has been hit. To upgrade the limit from 20 users to unlimited users, Purchase premium here: https://rocketr.net/buy/0e79a25902f5");
                        await ReplyAsync("", false, embed.Build());

                        return;
                    }
                }

                if (server.UserList.Any(member => member.UserId == user.Id))
                {
                    embed.AddField("ERROR", "User is already registered");
                    embed.WithColor(Color.Red);
                    await ReplyAsync("", false, embed.Build());

                    return;
                }
                server.UserList.Add(usr);
                embed.AddField($"{user.Username} registered as {username}", $"{server.Registermessage}");
                embed.WithColor(Color.Blue);
                try
                {
                    await UserRename(server.UsernameSelection, user, username, 0);
                }
                catch
                {
                    embed.AddField("ERROR", "Username Unable to be modified (Permissions are above the bot)");
                }
                if (server.RegisterRole != 0)
                {
                    try
                    {
                        var serverrole = Context.Guild.GetRole(server.RegisterRole);
                        try
                        {
                            await((IGuildUser)user).AddRoleAsync(serverrole);
                        }
                        catch
                        {
                            embed.AddField("ERROR", "User Role Unable to be modified");
                        }
                    }
                    catch
                    {
                        embed.AddField("ERROR", "Register Role is Unavailable");
                    }
                }
                await ReplyAsync("", false, embed.Build());
            }
        }
示例#3
0
        public async Task Register([Remainder] string username = null)
        {
            var embed = new EmbedBuilder();

            if (username == null)
            {
                embed.AddField("ERROR", "Please specify a name to be registered with");
                embed.WithColor(Color.Red);
                await ReplyAsync("", false, embed.Build());

                return;
            }

            if (username.Length > 20)
            {
                embed.AddField("ERROR", "Username Must be 20 characters or less");
                embed.WithColor(Color.Red);
                await ReplyAsync("", false, embed.Build());

                return;
            }

            var server = Servers.ServerList.First(x => x.ServerId == Context.Guild.Id);

            if (server.UserList.Count >= 20 && !server.IsPremium)
            {
                embed.AddField("ERROR",
                               "Free User limit has been hit. To upgrade the limit from 20 users to unlimited users, Purchase premium here: https://rocketr.net/buy/0e79a25902f5");
                await ReplyAsync("", false, embed.Build());

                return;
            }

            try
            {
                if (server.UserList.Any(member => member.UserId == Context.User.Id))
                {
                    var userprofile = server.UserList.FirstOrDefault(x => x.UserId == Context.User.Id);

                    if (userprofile == null)
                    {
                        await ReplyAsync("ERROR: User not registered!");

                        return;
                    }

                    if (!((IGuildUser)Context.User).RoleIds.Contains(server.RegisterRole) && server.RegisterRole != 0)
                    {
                        try
                        {
                            var serverrole = Context.Guild.GetRole(server.RegisterRole);
                            try
                            {
                                await((IGuildUser)Context.User).AddRoleAsync(serverrole);
                            }
                            catch
                            {
                                embed.AddField("ERROR", "User Role Unable to be modified");
                            }
                        }
                        catch
                        {
                            embed.AddField("ERROR", "Register Role is Unavailable");
                        }
                    }

                    try
                    {
                        await UserRename(server.UsernameSelection, Context.User, username, userprofile.Points);


                        userprofile.Username = username;
                    }
                    catch
                    {
                        embed.AddField("ERROR", "Username Unable to be modified (Permissions are above the bot)");
                    }


                    embed.AddField("ERROR", "User is already registered, role and name have been updated accordingly");

                    embed.WithColor(Color.Red);

                    await ReplyAsync("", false, embed.Build());

                    return;
                }
            }
            catch
            {
                //
            }


            var user = new Servers.Server.User
            {
                UserId   = Context.User.Id,
                Username = username,
                Points   = 0
            };

            server.UserList.Add(user);
            embed.AddField($"{Context.User.Username} registered as {username}", $"{server.Registermessage}");
            embed.WithColor(Color.Blue);
            try
            {
                await UserRename(server.UsernameSelection, Context.User, user.Username, 0);
            }
            catch
            {
                embed.AddField("ERROR", "Username Unable to be modified (Permissions are above the bot)");
            }
            if (server.RegisterRole != 0)
            {
                try
                {
                    var serverrole = Context.Guild.GetRole(server.RegisterRole);
                    try
                    {
                        await((IGuildUser)Context.User).AddRoleAsync(serverrole);
                    }
                    catch
                    {
                        embed.AddField("ERROR", "User Role Unable to be modified");
                    }
                }
                catch
                {
                    embed.AddField("ERROR", "Register Role is Unavailable");
                }
            }
            await ReplyAsync("", false, embed.Build());
        }