Exemplo n.º 1
0
        public async Task ClaimeRole(string claim)
        {
            var(pair, group) = await GroupHandler.GetGroupRoleFromClaimName(claim, Context.Guild.Id);

            if (group != null)
            {
                await ClaimGroupRole(pair, group);

                return;
            }
            var nftRole = await NFTRoleHandler.GetRoleByClaimName(claim, Context.Guild.Id);

            if (nftRole != null)
            {
                await ClaimNFTRole(nftRole);
            }
            var role = await RoleHandler.GetRoleByClaimName(claim);

            if (role == null)
            {
                return;
            }
            if (Context.Guild == null || Context.Guild.Id != role.guildId)
            {
                await ReplyAsync("Please use command in the correct server.");

                return;
            }
            var addresses = await User.GetUserAddresses(Context.Message.Author.Id);

            if (addresses.Count == 0)
            {
                await ReplyAsync($"User has not binded an address. Please Bind an address using command `{Bot.CommandPrefix}verify`");

                return;
            }
            var give = false;

            foreach (var add in addresses)
            {
                if (await Blockchain.ChainWatcher.GetBalanceOf(role.TokenAddress, add) >= BigInteger.Parse(role.GetBN()))
                {
                    give = true;
                    break;
                }
            }
            if (give)
            {
                var user = Context.Message.Author as SocketGuildUser;
                await user.AddRoleAsync(Context.Guild.GetRole(role.RoleId));

                await Context.Message.AddReactionAsync(new Emoji("✅"));
            }
            else
            {
                await Context.Message.AddReactionAsync(new Emoji("❌"));
            }
        }
Exemplo n.º 2
0
        //[Command("testClaimFor", RunMode = RunMode.Async)]
        //public async Task TestClaimRole(ulong id, string claim) {
        //    var user = await Context.Guild.GetUserAsync(id);
        //    var nftRole = await NFTRoleHandler.GetRoleByClaimName(claim, Context.Guild.Id);
        //    if (nftRole != null)
        //        await TestClaimNFTRole(nftRole, user);
        //}

        //public async Task TestClaimNFTRole(NFTRoleHandler role, IGuildUser user) {
        //    if (Context.Guild == null || Context.Guild.Id != role.guildId) {
        //        await ReplyAsync("Please use command in the correct server.");
        //        return;
        //    }
        //    var addresses = await User.GetUserAddresses(user.Id);
        //    if (addresses.Count == 0) {
        //        await ReplyAsync($"User has not binded an address. Please Bind an address using command `{Bot.CommandPrefix}verify`");
        //        return;
        //    }
        //    await Context.Message.AddReactionAsync(Emote.Parse("<a:loading:726356725648719894>"));
        //    var eligible = false;
        //    foreach (var add in addresses) {
        //        switch (role.RequirementType) {
        //            case NFTReqType.HoldX:
        //                eligible = await Blockchain.ChainWatcher.GetBalanceOf(role.NFTAddress, add) >= role.HoldXValue;
        //                break;
        //            case NFTReqType.InRange:
        //                eligible = (await Blockchain.OpenSea.CheckNFTInRange(add, role.NFTAddress, role.MinRange, role.MaxRange, role.HoldXValue));
        //                break;
        //            case NFTReqType.Custom:
        //                break;
        //        }
        //        if (eligible)
        //            break;
        //    }
        //    await Context.Message.RemoveReactionAsync(Emote.Parse("<a:loading:726356725648719894>"), Context.Client.CurrentUser.Id);
        //    if (eligible) {
        //        //var user = Context.Message.Author as SocketGuildUser;
        //        var aRole = Context.Guild.GetRole(role.RoleId);
        //        try {
        //            //await user.AddRoleAsync(aRole);
        //        }
        //        catch (Exception e) { Console.WriteLine(e.Message); }
        //        await Context.Message.AddReactionAsync(new Emoji("✅"));
        //    }
        //    else
        //        await Context.Message.AddReactionAsync(new Emoji("❌"));
        //}


        public async Task ClaimNFTRole(NFTRoleHandler role)
        {
            if (Context.Guild == null || Context.Guild.Id != role.guildId)
            {
                await ReplyAsync("Please use command in the correct server.");

                return;
            }
            var addresses = await User.GetUserAddresses(Context.Message.Author.Id);

            if (addresses.Count == 0)
            {
                await ReplyAsync($"User has not binded an address. Please Bind an address using command `{Bot.CommandPrefix}verify`");

                return;
            }
            await Context.Message.AddReactionAsync(Emote.Parse("<a:loading:726356725648719894>"));

            var eligible = false;

            foreach (var add in addresses)
            {
                switch (role.RequirementType)
                {
                case NFTReqType.HoldX:
                    eligible = await Blockchain.ChainWatcher.GetBalanceOf(role.NFTAddress, add) >= role.HoldXValue;

                    break;

                case NFTReqType.InRange:
                    eligible = (await Blockchain.OpenSea.CheckNFTInRange(add, role.NFTAddress, role.MinRange, role.MaxRange, role.HoldXValue));
                    break;

                case NFTReqType.Custom:
                    break;
                }
                if (eligible)
                {
                    break;
                }
            }
            await Context.Message.RemoveReactionAsync(Emote.Parse("<a:loading:726356725648719894>"), Context.Client.CurrentUser.Id);

            if (eligible)
            {
                var user  = Context.Message.Author as SocketGuildUser;
                var aRole = Context.Guild.GetRole(role.RoleId);
                try {
                    await user.AddRoleAsync(aRole);
                }
                catch (Exception e) { Console.WriteLine(e.Message); }
                await Context.Message.AddReactionAsync(new Emoji("✅"));
            }
            else
            {
                await Context.Message.AddReactionAsync(new Emoji("❌"));
            }
        }
Exemplo n.º 3
0
        public async Task RemoveRoleUser(string claim)
        {
            if (Context.Guild == null)
            {
                return;
            }
            var user    = Context.Message.Author as IGuildUser;
            var roleIds = user.RoleIds;

            var(pair, group) = await GroupHandler.GetGroupRoleFromClaimName(claim, Context.Guild.Id);

            if (group != null)
            {
                var role = Context.Guild.GetRole(ulong.Parse(pair.Key));
                if (roleIds.Contains(ulong.Parse(pair.Key)))
                {
                    await user.RemoveRoleAsync(role);

                    await Context.Message.AddReactionAsync(new Emoji("✅"));
                }
                return;
            }
            var nftRole = await NFTRoleHandler.GetRoleByClaimName(claim, Context.Guild.Id);

            if (nftRole != null)
            {
                var role = Context.Guild.GetRole(nftRole.RoleId);
                if (roleIds.Contains(nftRole.RoleId))
                {
                    await user.RemoveRoleAsync(role);

                    await Context.Message.AddReactionAsync(new Emoji("✅"));
                }
                return;
            }
            var tokenRole = await RoleHandler.GetRoleByClaimName(claim);

            if (tokenRole != null)
            {
                if (Context.Guild.Id == tokenRole.guildId)
                {
                    var role = Context.Guild.GetRole(tokenRole.RoleId);
                    if (roleIds.Contains(tokenRole.RoleId))
                    {
                        await user.RemoveRoleAsync(role);

                        await Context.Message.AddReactionAsync(new Emoji("✅"));
                    }
                    return;
                }
            }
        }
Exemplo n.º 4
0
        public async Task DeleteNFTRole(IRole role)
        {
            if (!await IsAdmin())
            {
                return;
            }
            if (Context.Guild == null)
            {
                await ReplyAsync("You must issue this command inside a server!");

                return;
            }
            await NFTRoleHandler.RemoveRoleHandler(role.Id);

            await Context.Message.AddReactionAsync(new Emoji("✅"));
        }
Exemplo n.º 5
0
        public static async Task RunDailyChecks()
        {
            try{
                while (true)
                {
                    Console.WriteLine("Start checking");
                    await CheckAllRolesReq();

                    await GroupHandler.CheckAllRolesReq();

                    await NFTRoleHandler.CheckAllRolesReq();

                    Console.WriteLine("Done checking");
                    await Task.Delay(1000 * 3600 * 24);
                }
            }
            catch (Exception e) {
                Logger.Log("Run check error : " + e.Message);
            }
        }
Exemplo n.º 6
0
        public async Task ShowRoles()
        {
            var roles = await RoleHandler.GetAllRoles();

            roles = roles.Where(r => r.guildId == Context.Guild.Id).ToList();
            var embed = new EmbedBuilder().WithTitle("📜 Roles 📜").WithColor(Color.Blue);

            embed.WithDescription($"Delete a role handler using `{Bot.CommandPrefix}deleteRole @role`or `{Bot.CommandPrefix}deleteNFTRoles @role` [ADMIN ONLY]");

            int i = 1;

            foreach (var role in roles)
            {
                var mention = Context.Guild.GetRole(role.RoleId).Mention;
                embed.AddField($"{i++}. Requirement: {BigNumber.FormatUint(role.Requirement, role.tokenDecimal)} {role.TokenName}", $"{mention} | type `{Bot.CommandPrefix}claim {role.ClaimName}` to claim");
            }

            var nftRoles = await NFTRoleHandler.GetAllRoles();

            nftRoles = nftRoles.Where(r => r.guildId == Context.Guild.Id).ToList();
            foreach (var role in nftRoles)
            {
                var mention = Context.Guild.GetRole(role.RoleId).Mention;
                var range   = role.RequirementType == NFTReqType.InRange ? $" in range [{role.MinRange};{role.MaxRange}]" : "";
                embed.AddField($"{i++}. Requirement: hold {role.HoldXValue} {role.TokenName}{range}", $"{mention} | type `{Bot.CommandPrefix}claim {role.ClaimName}` to claim");
            }
            var groups = await GroupHandler.GetAllGroupHandlerFromGuild(Context.Guild.Id);

            foreach (var group in groups)
            {
                foreach (var pair in group.RoleDict)
                {
                    var str   = $"{i++}. {group.GroupName} group:";
                    var inStr = "";
                    inStr += $" Requirement -> cost {BigNumber.FormatUint(pair.Value.Requirement, group.TokenDecimal)} {group.TokenName}";
                    var mention = Context.Guild.GetRole(ulong.Parse(pair.Key)).Mention;
                    embed.AddField(str + inStr, $"{mention} | type `{Bot.CommandPrefix}claim {pair.Value.ClaimName}` to claim");
                }
            }
            await ReplyAsync(embed : embed.Build());
        }
Exemplo n.º 7
0
        public async Task ClaimAll()
        {
            if (Context.Guild == null)
            {
                await ReplyAsync("Please use command in the correct server.");

                return;
            }
            var addresses = await User.GetUserAddresses(Context.Message.Author.Id);

            if (addresses.Count == 0)
            {
                await ReplyAsync("User has not binded an address. Please Bind an address using command `{Bot.CommandPrefix}verify`");

                return;
            }
            await Context.Message.AddReactionAsync(Emote.Parse("<a:loading:726356725648719894>"));

            var tokenRoles = await RoleHandler.GetAllRolesByGuild(Context.Guild.Id);

            foreach (var role in tokenRoles)
            {
                var give = false;
                foreach (var add in addresses)
                {
                    if (await Blockchain.ChainWatcher.GetBalanceOf(role.TokenAddress, add) >= BigInteger.Parse(role.GetBN()))
                    {
                        give = true;
                        break;
                    }
                }
                if (give)
                {
                    var user = Context.Message.Author as SocketGuildUser;
                    await user.AddRoleAsync(Context.Guild.GetRole(role.RoleId));
                }
            }
            var nftRoles = await NFTRoleHandler.GetAllRolesByGuild(Context.Guild.Id);

            foreach (var role in nftRoles)
            {
                var eligible = false;
                foreach (var add in addresses)
                {
                    switch (role.RequirementType)
                    {
                    case NFTReqType.HoldX:
                        eligible = await Blockchain.ChainWatcher.GetBalanceOf(role.NFTAddress, add) >= role.HoldXValue;

                        break;

                    case NFTReqType.InRange:
                        eligible = (await Blockchain.OpenSea.CheckNFTInRange(add, role.NFTAddress, role.MinRange, role.MaxRange, role.HoldXValue));
                        break;

                    case NFTReqType.Custom:
                        break;
                    }
                    if (eligible)
                    {
                        break;
                    }
                }
                if (eligible)
                {
                    var user  = Context.Message.Author as SocketGuildUser;
                    var aRole = Context.Guild.GetRole(role.RoleId);
                    try {
                        await user.AddRoleAsync(aRole);
                    }
                    catch (Exception e) { Console.WriteLine(e.Message); }
                }
            }
            //var groupRoles = await GroupHandler.GetAllGroupHandlerFromGuild(Context.Guild.Id);

            //foreach (var role in groupRoles) {
            //    var balance = BigInteger.Zero;
            //    var usedBalance = BigInteger.Zero;
            //    var role
            //    foreach (var add in addresses)
            //        balance += await Blockchain.ChainWatcher.GetBalanceOf(role.TokenAddress, add);
            //}
            await Context.Message.RemoveReactionAsync(Emote.Parse("<a:loading:726356725648719894>"), Context.Client.CurrentUser.Id);

            await Context.Message.AddReactionAsync(new Emoji("✅"));
        }
Exemplo n.º 8
0
        public async Task AddNFTRole(IRole role, params string[] input)
        {
            if (!await IsAdmin())
            {
                return;
            }
            if (Context.Guild == null)
            {
                await ReplyAsync("You must issue this command inside a server!");

                return;
            }
            if (input.Length > 7)
            {
                return;
            }
            var        tokenName  = input[0];
            var        nftAddress = input[1];
            var        reqType    = input[2];
            var        value      = Convert.ToInt32(input[3]);
            var        claimName  = input[input.Length - 1];
            var        inRange    = "";
            var        rangeValue = "";
            NFTReqType type       = NFTReqType.HoldX;
            var        min        = 0;
            var        max        = 0;

            if (reqType.ToLower().StartsWith("hold"))
            {
                type = NFTReqType.HoldX;
            }
            if (input.Length > 5)
            {
                inRange    = input[4];
                rangeValue = input[5];
                if (inRange.ToLower() == "range")
                {
                    if (rangeValue[0] == '[' && rangeValue[rangeValue.Length - 1] == ']')
                    {
                        rangeValue = rangeValue.Substring(1, rangeValue.Length - 2);
                        var arr = rangeValue.Split(';');
                        if (arr.Length == 2 && int.TryParse(arr[0], out min) && int.TryParse(arr[1], out max) && min < max)
                        {
                            type = NFTReqType.InRange;
                        }
                        else
                        {
                            await ReplyAsync("Wrong range format");

                            return;
                        }
                    }
                    else
                    {
                        await ReplyAsync("Wrong range format");

                        return;
                    }
                }
            }
            await NFTRoleHandler.AddRoleHandler(Context.Guild.Id, role.Id, nftAddress, type, claimName, tokenName, value, min, max);

            await Context.Message.AddReactionAsync(new Emoji("✅"));
        }