Пример #1
0
        public async Task ShowGroups()
        {
            if (!await IsAdmin())
            {
                return;
            }
            var embed = new EmbedBuilder().WithTitle("📜 Groups 📜").WithColor(Color.Blue);

            embed.WithDescription("Delete a role handler using `{Bot.CommandPrefix}deletegroup groupName` [ADMIN ONLY]");
            var groups = await GroupHandler.GetAllGroupHandlerFromGuild(Context.Guild.Id);

            var i = 1;

            foreach (var group in groups)
            {
                foreach (var pair in group.RoleDict)
                {
                    var str   = $"{i++}. {group.GroupName} group:";
                    var inStr = "";
                    inStr += $" Requirement -> hold {BigNumber.FormatUint(pair.Value.Requirement, group.TokenDecimal)}";
                    var mention = Context.Guild.GetRole(ulong.Parse(pair.Key)).Mention;
                    embed.AddField(str + inStr, $"{mention} | type `{Bot.CommandPrefix}claim {pair.Value.ClaimName}` to claim");
                }
                if (group.RoleDict.Count == 0)
                {
                    embed.AddField($"{i++}. {group.GroupName} group:", $"none");
                }
            }
            await ReplyAsync(embed : embed.Build());
        }
Пример #2
0
        public async Task UpdateGroupRole(string gName, string req, string cName)
        {
            if (!await IsAdmin())
            {
                return;
            }
            if (Context.Guild == null)
            {
                await ReplyAsync("You must issue this command inside a server!");

                return;
            }
            var group = await GroupHandler.GetGroupHandler(Context.Guild.Id, gName);

            if (BigNumber.IsValidValue(req, group.TokenDecimal))
            {
                await group.UpdateRole(cName, req);

                await Context.Message.AddReactionAsync(new Emoji("✅"));
            }
            else
            {
                await ReplyAsync("Wrong token value in respect to decimals");
            }
        }
Пример #3
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("❌"));
            }
        }
Пример #4
0
        public async Task ClaimGroupRoleFor(KeyValuePair <string, GroupRole> pair, GroupHandler group, IUser user)
        {
            if (Context.Guild == null || Context.Guild.Id != group.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 balance = BigInteger.Zero;

            foreach (var address in addresses)
            {
                balance += await Blockchain.ChainWatcher.GetBalanceOf(group.TokenAddress, address);
            }
            var usedBalance = BigInteger.Zero;
            var roleReq     = BigInteger.Parse(pair.Value.Requirement);
            var guildUser   = user as IGuildUser;
            var userRoles   = guildUser.RoleIds;

            foreach (var role in group.RoleDict)
            {
                if (userRoles.Contains(ulong.Parse(role.Key)))
                {
                    usedBalance += BigInteger.Parse(role.Value.Requirement);
                }
            }
            var eligible = balance >= usedBalance + roleReq;
            await Context.Message.RemoveReactionAsync(Emote.Parse("<a:loading:726356725648719894>"), Context.Client.CurrentUser.Id);

            if (eligible)
            {
                var roleUser = user as SocketGuildUser;
                var aRole    = Context.Guild.GetRole(ulong.Parse(pair.Key));
                try {
                    await roleUser.AddRoleAsync(aRole);
                }
                catch (Exception e) { Console.WriteLine(e.Message); }
                await Context.Message.AddReactionAsync(new Emoji("✅"));
            }
            else
            {
                await Context.Message.AddReactionAsync(new Emoji("❌"));
            }
        }
Пример #5
0
        public async Task CheckGroupRoles(ulong user)
        {
            if (!await IsAdmin())
            {
                return;
            }
            //var (pair, group) = await GroupHandler.GetGroupRoleFromClaimName(claim, Context.Guild.Id);
            var group = await GroupHandler.GetGroupHandler(Context.Guild.Id, "whalegroup");

            await group.CheckOne(user);
        }
Пример #6
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;
                }
            }
        }
Пример #7
0
        public async Task AddRoleFor(IUser user, string claim)
        {
            if (!await IsAdmin())
            {
                return;
            }
            var(pair, group) = await GroupHandler.GetGroupRoleFromClaimName(claim, Context.Guild.Id);

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

                return;
            }
        }
Пример #8
0
        public async Task RemoveGroup(string gName)
        {
            if (!await IsAdmin())
            {
                return;
            }
            if (Context.Guild == null)
            {
                await ReplyAsync("You must issue this command inside a server!");

                return;
            }
            await GroupHandler.RemoveGroupHandler(Context.Guild.Id, gName);

            await Context.Message.AddReactionAsync(new Emoji("✅"));
        }
Пример #9
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);
            }
        }
Пример #10
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());
        }
Пример #11
0
        public async Task RemoveGroupRole(string gName, string cName)
        {
            if (!await IsAdmin())
            {
                return;
            }
            if (Context.Guild == null)
            {
                await ReplyAsync("You must issue this command inside a server!");

                return;
            }
            var group = await GroupHandler.GetGroupHandler(Context.Guild.Id, gName);

            var groupRole = group.RoleDict.Where(r => r.Value.ClaimName == cName.ToLower()).FirstOrDefault();

            if (groupRole.Value != null)
            {
                await group.RemoveRole(ulong.Parse(groupRole.Key));

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