Exemple #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("❌"));
            }
        }
Exemple #2
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;
                }
            }
        }
Exemple #3
0
        public async Task Dlete(IRole role)
        {
            if (!await IsAdmin())
            {
                return;
            }
            if (Context.Guild == null)
            {
                await ReplyAsync("You must issue this command inside a server!");

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

            await Context.Message.AddReactionAsync(new Emoji("✅"));
        }
Exemple #4
0
        public async Task UpdateRole(IRole role, string req)
        {
            if (!await IsAdmin())
            {
                return;
            }
            if (Context.Guild == null)
            {
                await ReplyAsync("You must issue this command inside a server!");

                return;
            }
            await RoleHandler.UpdateRoleHandler(Context.Guild.Id, role.Id, req);

            await Context.Message.AddReactionAsync(new Emoji("✅"));
        }
Exemple #5
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());
        }
Exemple #6
0
        public async Task AddRole(IRole role, string tokenName, string token, string req, int dec, string name)
        {
            if (!await IsAdmin())
            {
                return;
            }
            if (Context.Guild == null)
            {
                await ReplyAsync("You must issue this command inside a server!");

                return;
            }
            if (BigNumber.IsValidValue(req, dec))
            {
                await RoleHandler.AddRoleHandler(Context.Guild.Id, role.Id, token, req, dec, name, tokenName);

                await Context.Message.AddReactionAsync(new Emoji("✅"));
            }
            else
            {
                await ReplyAsync("Wrong token value in respect to decimals");
            }
        }
Exemple #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("✅"));
        }