Пример #1
0
            async Task manageThing(string strId, ulong thingId, PermissionTarget thingType, bool?value)
            {
                await Interaction.AcknowledgeAsync(flags : InteractionResponseFlags.Ephemeral);

                try
                {
                    RestApplicationCommand command = await getCommand(strId);

                    if (command == null)
                    {
                        await Interaction.FollowupAsync(":x: Command does not exist");

                        return;
                    }

                    GuildApplicationCommandPermissions existingPerms = null;
                    if (command is RestGlobalCommand g)
                    {
                        existingPerms = await g.GetCommandPermissions(Interaction.Guild.Id);
                    }
                    else if (command is RestGuildCommand u)
                    {
                        existingPerms = await u.GetCommandPermissions();
                    }
                    var permBuilder   = SlashCommandPermsBuilder.From(existingPerms);
                    var existingValue = permBuilder.Get(thingId);
                    if (value.HasValue)
                    {
                        if (existingValue != value.Value)
                        {
                            permBuilder.With(thingId, thingType, value.Value);
                            await command.ModifyCommandPermissionsAsync(Interaction.Guild.Id, permBuilder.Build().ToArray());
                        }
                        await Interaction.FollowupAsync("Done!");
                    }
                    else
                    {
                        if (!existingValue.HasValue)
                        {
                            await Interaction.FollowupAsync($"{thingType} has no explicit permission set.");
                        }
                        else
                        {
                            await Interaction.FollowupAsync($"{thingType} permission for command: " + emote(existingValue.Value));
                        }
                    }
                }
                catch (Exception ex)
                {
                    Program.LogMsg(ex, "a");
                }
            }
Пример #2
0
        string getCmdRow(RestApplicationCommand cmd)
        {
            bool hasChildren = cmd.Options != null && cmd.Options.Any(x => x.Type == ApplicationCommandOptionType.SubCommand || x.Type == ApplicationCommandOptionType.SubCommandGroup);

            if (!hasChildren)
            {
                return($"`/{cmd.Name}` {cmd.Id} - {cmd.Description}" + (cmd.DefaultPermission ? "" : " [x]"));
            }
            var sb = new StringBuilder();

            sb.Append($"- {cmd.Id} {cmd.Description}\r\n");
            foreach (var option in cmd.Options)
            {
                sb.Append(getCmdRow(cmd.Name, option) + "\r\n");
            }
            return(sb.ToString());
        }