Example #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());
        }
Example #2
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());
        }
Example #3
0
        public async Task CheckAllRoleReq()
        {
            try {
                var guild     = Bot.DiscordClient.GetGuild(guildId) as IGuild;
                var role      = guild.GetRole(RoleId);
                var roleUsers = (await guild.GetUsersAsync());
                Console.WriteLine($"Checking requirements for {role.Name}");
                foreach (var user in roleUsers)
                {
                    if (user.RoleIds.Contains(role.Id) && !user.IsBot)
                    {
                        var addresses = await User.GetUserAddresses(user.Id);

                        if (addresses == null)
                        {
                            continue;
                        }
                        var remove = true;
                        if (addresses != null)
                        {
                            foreach (var address in addresses)
                            {
                                if (await Blockchain.ChainWatcher.GetBalanceOf(TokenAddress, address) >= BigInteger.Parse(GetBN()))
                                {
                                    remove = false;
                                    break;
                                }
                            }
                        }
                        if (addresses == null)
                        {
                            await user.RemoveRoleAsync(role);

                            await user.SendMessageAsync($"Hello!\nYour role `{role.Name}` in the `{guild.Name}` was removed as we couldn't find your verified address, please re-verify!");

                            var message = "**Follow this link to verify your ethereum address**";
                            var embed   = new EmbedBuilder().WithTitle("Follow this link to verify your address").WithDescription(message);
                            embed.WithColor(Color.DarkMagenta);
                            embed.WithUrl("https://discord.com/api/oauth2/authorize?client_id=778946094804762644&redirect_uri=https%3A%2F%2Fnft42-next.vercel.app%2F&response_type=code&scope=identify");
                            await user.SendMessageAsync(embed : embed.Build());
                        }
                        else if (remove)
                        {
                            await user.RemoveRoleAsync(role);

                            await user.SendMessageAsync($"Hello!\nYour role `{role.Name}` in the `{guild.Name}` was removed as your token balance went below the requirement of {BigNumber.FormatUint(Requirement, tokenDecimal)} {TokenName.ToUpper()}."
                                                        + "To reclaim the role, please make sure to make the minimum requirement in your wallet!");
                        }
                    }
                }
                Console.WriteLine("Done\n");
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }