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;
                }
            }
        }