Beispiel #1
0
        public static async Task EditLevelRole(InteractionContext ctx, DiscordRole role, long level)
        {
            await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);

            var usr = await ctx.Guild.GetMemberAsync(ctx.User.Id);

            var perms = (usr.PermissionsIn(ctx.Channel) & Permissions.BanMembers) != 0;

            if (!perms)
            {
                await ctx.DeleteResponseAsync();

                return;
            }

            using var db = new LiteDatabase(@$ "global.db");
            var col = db.GetCollection <ServerSettings>("servers");

            var server = col.FindOne(x => x.Id == ctx.Guild.Id);

            if (server == null)
            {
                server = new ServerSettings()
                {
                    Id = ctx.Guild.Id
                };
                col.Insert(server);
            }

            if (level == -1)
            {
                if (server.RoleLevels.ContainsKey(role.Id))
                {
                    await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Role level removed"));
                }
                else
                {
                    await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Role level does not exist"));
                }
            }
            else if (level > 0)
            {
                server.RoleLevels ??= new Dictionary <ulong, long>();
                if (server.RoleLevels.TryAdd(role.Id, level))
                {
                    await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Role level added"));
                }
                else
                {
                    await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Role level already exists"));
                }
            }
            else
            {
                await ctx.DeleteResponseAsync();
            }

            col.Update(server);
        }
Beispiel #2
0
        public async Task UnBan(InteractionContext ctx,
                                [Option("user", "User to unban")] DiscordUser user, [Option("reason", "reason for ban")] string reason)
        {
            await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);

            var usr = await ctx.Guild.GetMemberAsync(ctx.User.Id);

            var perms = (usr.PermissionsIn(ctx.Channel) & Permissions.BanMembers) != 0;


            if (!perms || user.Id == ctx.User.Id)
            {
                await ctx.Client.SendMessageAsync(ctx.Guild.GetChannel(607392574235344928),
                                                  $"{ctx.User.Mention} tried to use the unban command on {user.Mention} for reason {reason} but was denied\n(►˛◄’!)");

                await ctx.DeleteResponseAsync();

                return;
            }

            try
            {
                await ctx.Guild.UnbanMemberAsync(user.Id, reason);
            }
            catch (Exception e)
            {
                await ctx.EditResponseAsync(
                    new DiscordWebhookBuilder().WithContent($"Failed to unban {user.Mention}."));

                return;
            }

            await ctx.EditResponseAsync(
                new DiscordWebhookBuilder().WithContent($"{user.Mention} has been unbanned."));
        }
Beispiel #3
0
        public static async Task GetLevel(InteractionContext ctx,
                                          DiscordUser user = null !)
        {
            await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);

            using var db = new LiteDatabase(@$ "{ctx.Guild.Id}.db");
            var col = db.GetCollection <UserData>("users");

            if (user == null)
            {
                user = ctx.User;
            }
            var userData = col.FindOne(x => x.Id == user.Id);

            if (userData != null)
            {
                var embed = new DiscordEmbedBuilder();
                embed.AddField("Level", userData.Level.ToString());
                embed.AddField("Message Count", userData.MessageCount.ToString());

                await ctx.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(embed));

                return;
            }

            await ctx.DeleteResponseAsync();
        }
Beispiel #4
0
        public static async Task ResetLevel(InteractionContext ctx, DiscordUser user)
        {
            await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);

            var usr = await ctx.Guild.GetMemberAsync(ctx.User.Id);

            var perms = (usr.PermissionsIn(ctx.Channel) & Permissions.BanMembers) != 0;

            if (!perms)
            {
                await ctx.DeleteResponseAsync();

                return;
            }

            using var db = new LiteDatabase(@$ "{ctx.Guild.Id}.db");
            var col = db.GetCollection <UserData>("users");

            var userData = col.FindOne(x => x.Id == user.Id);

            if (userData != null)
            {
                userData.MessageCount = 0;
                userData.Level        = 0;

                await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Users level reset"));

                return;
            }

            await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("User not found in database"));
        }
Beispiel #5
0
        public static async Task EditBlacklist(InteractionContext ctx, string option, DiscordChannel channel)
        {
            await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);

            var usr = await ctx.Guild.GetMemberAsync(ctx.User.Id);

            var perms = (usr.PermissionsIn(ctx.Channel) & Permissions.BanMembers) != 0;

            if (!perms)
            {
                await ctx.DeleteResponseAsync();

                return;
            }

            using var db = new LiteDatabase(@$ "global.db");
            var col = db.GetCollection <ServerSettings>("servers");

            var server = col.FindOne(x => x.Id == ctx.Guild.Id);

            if (server == null)
            {
                server = new ServerSettings()
                {
                    Id = ctx.Guild.Id
                };
                col.Insert(server);
            }

            switch (option)
            {
            case "add":
                server.ExperienceBlacklistedChannels ??= new List <ulong>();
                server.ExperienceBlacklistedChannels.Add(channel.Id);
                await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"{channel.Mention} added"));

                break;

            case "remove":
                if (server.ExperienceBlacklistedChannels.Contains(channel.Id))
                {
                    server.ExperienceBlacklistedChannels.Remove(channel.Id);
                    await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"{channel.Mention} removed"));
                }
                else
                {
                    await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent($"{channel.Mention} not blacklisted"));
                }
                break;
            }
            col.Update(server);
        }
Beispiel #6
0
            public async Task ListWarnings(InteractionContext ctx,
                                           [Option("user", "The user to warn")] DiscordUser user = null !)
            {
                await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);


                if (user == null)
                {
                    user = ctx.User;
                }
                else
                {
                    var usr = await ctx.Guild.GetMemberAsync(ctx.User.Id);

                    var perms = (usr.PermissionsIn(ctx.Channel) & Permissions.KickMembers) != 0;

                    if (!perms)
                    {
                        await ctx.Client.SendMessageAsync(ctx.Guild.GetChannel(607392574235344928),
                                                          $"{ctx.User.Mention} tried to list warnings for {user.Mention} but was denied\n(►˛◄’!)");

                        await ctx.DeleteResponseAsync();

                        return;
                    }
                }


                using var db = new LiteDatabase(@$ "{ctx.Guild.Id}.db");
                var col = db.GetCollection <Warning>("warnings");

                var warnings = col.Find(x => x.UserId == user.Id);

                if (warnings.Any())
                {
                    var warningsDesc = string.Join("\n", warnings.Select(x => $"{x.Id}: {x.Reason} - {x.Date:g}"));

                    var username = user.Username ?? user.Id.ToString();

                    var embed = new DiscordEmbedBuilder
                    {
                        Title       = $"Warnings for {username}",
                        Description = warningsDesc,
                        Url         = null,
                        Color       = default,
Beispiel #7
0
        public async Task Faq(InteractionContext ctx,
                              [Choice("discordinstall", "discordinstall")]
                              [Option("option", "option")]
                              string option,
                              [Option("atuser", "user to mention")] DiscordUser user = null !)
        {
            await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);

            switch (option)
            {
            case "discordinstall":
                var embed = new DiscordEmbedBuilder()
                {
                    Title       = Formatter.Underline(Formatter.Bold("Please do not run these commands as root")),
                    Description = "How to install discord using xbps-src \n" + Formatter.BlockCode(@"git clone https://github.com/void-linux/void-packages
cd void-packages
./xbps-src binary-bootstrap
echo XBPS_ALLOW_RESTRICTED=yes > etc/conf
./xbps-src pkg discord
sudo xbps-install --repository=hostdir/binpkgs/nonfree discord", "bash")
                };

                var build = new DiscordWebhookBuilder();

                if (user != null)
                {
                    embed.Description += $"\n{user.Mention}";
                }
                build.AddEmbed(embed);

                await ctx.EditResponseAsync(build);

                return;

                break;

            case "":
                break;
            }
            await ctx.DeleteResponseAsync();
        }
Beispiel #8
0
        public async Task MassBan(InteractionContext ctx,
                                  [Option("users", "space separated list of ids to ban")]
                                  string users, [Option("reason", "reason for ban")] string reason)
        {
            await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);

            var usr = await ctx.Guild.GetMemberAsync(ctx.User.Id);

            var perms = (usr.PermissionsIn(ctx.Channel) & Permissions.BanMembers) != 0;


            if (!perms || users.Contains(ctx.User.Id.ToString()))
            {
                await ctx.Client.SendMessageAsync(ctx.Guild.GetChannel(607392574235344928),
                                                  $"{ctx.User.Mention} tried to use the ban command on {users} for reason {reason} but was denied\n(►˛◄’!)");

                await ctx.DeleteResponseAsync();

                return;
            }

            var userList = users.Split(' ').Select(ulong.Parse);

            var failCount = 0;

            foreach (var user in userList)
            {
                try
                {
                    await ctx.Guild.BanMemberAsync(user, 7, reason);
                }
                catch (Exception e)
                {
                    failCount++;
                }
            }

            await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(
                                            $"{userList.Count() - failCount} users have been banned. {(failCount > 0 ? $"Failed to ban {failCount} users" : "")} "));
        }
Beispiel #9
0
        public static async Task ViewBlacklist(InteractionContext ctx)
        {
            await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);

            var usr = await ctx.Guild.GetMemberAsync(ctx.User.Id);

            var perms = (usr.PermissionsIn(ctx.Channel) & Permissions.BanMembers) != 0;

            if (!perms)
            {
                await ctx.DeleteResponseAsync();

                return;
            }

            using var db = new LiteDatabase(@$ "global.db");
            var col = db.GetCollection <ServerSettings>("servers");

            var server = col.FindOne(x => x.Id == ctx.Guild.Id);

            if (server == null)
            {
                await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("Server not found"));

                return;
            }

            if (server.ExperienceBlacklistedChannels.Any())
            {
                await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent(string.Join(", ", server.ExperienceBlacklistedChannels.Select(x => $"<#{x}>"))));
            }
            else
            {
                await ctx.EditResponseAsync(new DiscordWebhookBuilder().WithContent("No channels blacklisted"));
            }
        }
Beispiel #10
0
        public async Task Xbps(InteractionContext ctx,
                               [Option("searchTerm", "Search term to use to find package")]
                               string searchTerm,
                               [Choice("aarch64", "aarch64")]
                               [Choice("aarch64-musl", "aarch64-musl")]
                               [Choice("armv6l-musl", "armv6l-musl")]
                               [Choice("armv7l", "armv7l")]
                               [Choice("armv7l-musl", "armv7l-musl")]
                               [Choice("i686", "i686")]
                               [Choice("x86_64", "x86_64")]
                               [Choice("x86_64-musl", "x86_64-musl")]
                               [Option("arch", "arch filter")]
                               string arch = "x86_64")
        {
            var interactivity = ctx.Client.GetInteractivity();


            //response may take a while so we need to do this first
            await ctx.CreateResponseAsync(InteractionResponseType.DeferredChannelMessageWithSource);

            searchTerm = searchTerm.Replace(' ', '+');

            var xqApiUrl = Config.AppSetting.GetSection("DiscordSettings")["xqApiUrl"];

            PackageListResponse resp;

            try
            {
                resp = await $"{xqApiUrl}query/{arch}?q={searchTerm}".GetJsonAsync <PackageListResponse>();
            }
            catch (FlurlHttpException ex)
            {
                //todo: make helper function for embeds
                var embed = new DiscordEmbedBuilder()
                            .WithTitle($"Void Repo Search: {searchTerm}")
                            .WithDescription(ex.Message + " report this error to @Epictek#6136")
                            .WithUrl(
                    $"https://github.com/void-linux/void-packages/search?q%5B%5D=filename%3Atemplate+path%3A%2Fsrcpkgs&q%5B%5D={searchTerm}&s=indexed")
                            .WithColor(new DiscordColor(0x478061))
                            .WithFooter(
                    "Search results xq-api",
                    "https://voidlinux.org/assets/img/void_bg.png"
                    ).Build();
                await ctx.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(embed));

                return;
            }

            if (resp.Data.Length == 0)
            {
                var embed = new DiscordEmbedBuilder()
                            .WithTitle($"Void Repo Search: {searchTerm}")
                            .WithDescription("No packages found")
                            .WithUrl(
                    $"https://github.com/void-linux/void-packages/search?q%5B%5D=filename%3Atemplate+path%3A%2Fsrcpkgs&q%5B%5D={searchTerm}&s=indexed")
                            .WithColor(new DiscordColor(0x478061))
                            .WithFooter(
                    "Search results xq-api",
                    "https://voidlinux.org/assets/img/void_bg.png"
                    ).Build();
                await ctx.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(embed));

                return;
            }

            string       links = "";
            IList <Page> pages = new List <Page>();

            Package last = resp.Data.Last();

            foreach (Package package in resp.Data)
            {
                var packageString =
                    $"[{package.Name} {package.Version}](https://github.com/void-linux/void-packages/tree/master/srcpkgs/{package.Name}) - {package.ShortDesc}";

                links += packageString + "\n";

                if (packageString.Length + links.Length > 2000 || package.Equals(last))
                {
                    var embed = new DiscordEmbedBuilder()
                                .WithTitle("Void Repo Search: " + searchTerm)
                                .WithDescription(links)
                                .WithUrl(
                        "https://github.com/void-linux/void-packages/search?q%5B%5D=filename%3Atemplate+path%3A%2Fsrcpkgs&q%5B%5D=" +
                        searchTerm + "&s=indexed")
                                .WithColor(new DiscordColor(0x478061))
                                .WithFooter(
                        "Search results from xq-api",
                        "https://voidlinux.org/assets/img/void_bg.png"
                        );

                    pages.Add(new Page
                    {
                        Embed = embed
                    });

                    links = "";
                }
            }

            if (pages.Count > 1)
            {
                await ctx.DeleteResponseAsync();

                await interactivity.SendPaginatedMessageAsync(ctx.Channel, ctx.Interaction.User, pages);
            }
            else
            {
                await ctx.EditResponseAsync(new DiscordWebhookBuilder().AddEmbed(pages.First().Embed));
            }
        }