<commit_before>using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.Net;
using Discord.WebSocket;
using NadekoBot.Common;
using NadekoBot.Common.Attributes;
using NadekoBot.Common.Replacements;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models;
using NadekoBot.Extensions;
using NadekoBot.Modules.Administration.Services;

namespace NadekoBot.Modules.Administration
{
    public partial class Administration
    {
        [Group]
        public class SelfCommands : NadekoSubmodule<SelfService>
        {
            private readonly DiscordSocketClient _client;
            private readonly NadekoBot _bot;
            private readonly IBotCredentials _creds;

            public SelfCommands(DbService db, NadekoBot bot, DiscordSocketClient client,
                IBotCredentials creds, IDataCache cache)
            {
                _client = client;
                _bot = bot;
                _creds = creds;
            }

            [NadekoCommand, Usage, Description, Aliases]
            [RequireContext(ContextType.Guild)]
            [OwnerOnly]
            public async Task StartupCommandAdd([Remainder] string cmdText)
            {
                if (cmdText.StartsWith(Prefix + "die"))
                    return;

                var guser = ((IGuildUser)Context.User);
                var cmd = new StartupCommand()
                {
                    CommandText = cmdText,
                    ChannelId = Context.Channel.Id,
                    ChannelName = Context.Channel.Name,
                    GuildId = Context.Guild?.Id,
                    GuildName = Context.Guild?.Name,
                    VoiceChannelId = guser.VoiceChannel?.Id,
                    VoiceChannelName = guser.VoiceChannel?.Name,
                    Interval = 0,
                };
                _service.AddNewAutoCommand(cmd);

                await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
                    .WithTitle(GetText("scadd"))
                    .AddField(efb => efb.WithName(GetText("server"))
                        .WithValue(cmd.GuildId == null ? $"-" : $"{cmd.GuildName}/{cmd.GuildId}").WithIsInline(true))
                    .AddField(efb => efb.WithName(GetText("channel"))
                        .WithValue($"{cmd.ChannelName}/{cmd.ChannelId}").WithIsInline(true))
                    .AddField(efb => efb.WithName(GetText("command_text"))
                        .WithValue(cmdText).WithIsInline(false)));
            }

            [NadekoCommand, Usage, Description, Aliases]
            [RequireContext(ContextType.Guild)]
            [OwnerOnly]
            public async Task AutoCommandAdd(int interval, [Remainder] string cmdText)
            {
                if (cmdText.StartsWith(Prefix + "die"))
                    return;

                if (interval < 5)
                    return;

                var guser = ((IGuildUser)Context.User);
                var cmd = new StartupCommand()
                {
                    CommandText = cmdText,
                    ChannelId = Context.Channel.Id,
                    ChannelName = Context.Channel.Name,
                    GuildId = Context.Guild?.Id,
                    GuildName = Context.Guild?.Name,
                    VoiceChannelId = guser.VoiceChannel?.Id,
                    VoiceChannelName = guser.VoiceChannel?.Name,
                    Interval = interval,
                };
                _service.AddNewAutoCommand(cmd);

                await ReplyConfirmLocalized("autocmd_add", Format.Code(Format.Sanitize(cmdText)), cmd.Interval).ConfigureAwait(false);
            }

            [NadekoCommand, Usage, Description, Aliases]
            [RequireContext(ContextType.Guild)]
            [OwnerOnly]
            public async Task StartupCommands(int page = 1)
            {
                if (page-- < 1)
                    return;

                var scmds = _service.GetStartupCommands()
                    .Where(x => x.Interval <= 0)
                    .Skip(page * 5)
                    .Take(5);
                if (!scmds.Any())
                {
                    await ReplyErrorLocalized("startcmdlist_none").ConfigureAwait(false);
                }
                else
                {
                    await Context.Channel.SendConfirmAsync(
                        text: string.Join("\n", scmds
                        .Select(x => $@"```css
#{x.Index}
[{GetText("server")}]: {(x.GuildId.HasValue ? $"{x.GuildName} #{x.GuildId}" : "-")}
[{GetText("channel")}]: {x.ChannelName} #{x.ChannelId}
[{GetText("command_text")}]: {x.CommandText}```")),
                        title: string.Empty,
                        footer: GetText("page", page + 1))
                    .ConfigureAwait(false);
                }
            }

            [NadekoCommand, Usage, Description, Aliases]
            [RequireContext(ContextType.Guild)]
            [OwnerOnly]<commit_msg>Allow Administrators to use AutoCommands<commit_after>using System;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.Net;
using Discord.WebSocket;
using NadekoBot.Common;
using NadekoBot.Common.Attributes;
using NadekoBot.Common.Replacements;
using NadekoBot.Core.Services;
using NadekoBot.Core.Services.Database.Models;
using NadekoBot.Extensions;
using NadekoBot.Modules.Administration.Services;

namespace NadekoBot.Modules.Administration
{
    public partial class Administration
    {
        [Group]
        public class SelfCommands : NadekoSubmodule<SelfService>
        {
            private readonly DiscordSocketClient _client;
            private readonly NadekoBot _bot;
            private readonly IBotCredentials _creds;

            public SelfCommands(DbService db, NadekoBot bot, DiscordSocketClient client,
                IBotCredentials creds, IDataCache cache)
            {
                _client = client;
                _bot = bot;
                _creds = creds;
            }

            [NadekoCommand, Usage, Description, Aliases]
            [RequireContext(ContextType.Guild)]
            [OwnerOnly]
            public async Task StartupCommandAdd([Remainder] string cmdText)
            {
                if (cmdText.StartsWith(Prefix + "die"))
                    return;

                var guser = ((IGuildUser)Context.User);
                var cmd = new StartupCommand()
                {
                    CommandText = cmdText,
                    ChannelId = Context.Channel.Id,
                    ChannelName = Context.Channel.Name,
                    GuildId = Context.Guild?.Id,
                    GuildName = Context.Guild?.Name,
                    VoiceChannelId = guser.VoiceChannel?.Id,
                    VoiceChannelName = guser.VoiceChannel?.Name,
                    Interval = 0,
                };
                _service.AddNewAutoCommand(cmd);

                await Context.Channel.EmbedAsync(new EmbedBuilder().WithOkColor()
                    .WithTitle(GetText("scadd"))
                    .AddField(efb => efb.WithName(GetText("server"))
                        .WithValue(cmd.GuildId == null ? $"-" : $"{cmd.GuildName}/{cmd.GuildId}").WithIsInline(true))
                    .AddField(efb => efb.WithName(GetText("channel"))
                        .WithValue($"{cmd.ChannelName}/{cmd.ChannelId}").WithIsInline(true))
                    .AddField(efb => efb.WithName(GetText("command_text"))
                        .WithValue(cmdText).WithIsInline(false)));
            }

            [NadekoCommand, Usage, Description, Aliases]
            [RequireContext(ContextType.Guild)]
            [RequireUserPermission(GuildPermission.Administrator)]
            // [OwnerOnly]
            public async Task AutoCommandAdd(int interval, [Remainder] string cmdText)
            {
                if (cmdText.StartsWith(Prefix + "die"))
                    return;

                if (interval < 5)
                    return;

                var guser = ((IGuildUser)Context.User);
                var cmd = new StartupCommand()
                {
                    CommandText = cmdText,
                    ChannelId = Context.Channel.Id,
                    ChannelName = Context.Channel.Name,
                    GuildId = Context.Guild?.Id,
                    GuildName = Context.Guild?.Name,
                    VoiceChannelId = guser.VoiceChannel?.Id,
                    VoiceChannelName = guser.VoiceChannel?.Name,
                    Interval = interval,
                };
                _service.AddNewAutoCommand(cmd);

                await ReplyConfirmLocalized("autocmd_add", Format.Code(Format.Sanitize(cmdText)), cmd.Interval).ConfigureAwait(false);
            }

            [NadekoCommand, Usage, Description, Aliases]
            [RequireContext(ContextType.Guild)]
            [OwnerOnly]
            public async Task StartupCommands(int page = 1)
            {
                if (page-- < 1)
                    return;

                var scmds = _service.GetStartupCommands()
                    .Where(x => x.Interval <= 0)
                    .Skip(page * 5)
                    .Take(5);
                if (!scmds.Any())
                {
                    await ReplyErrorLocalized("startcmdlist_none").ConfigureAwait(false);
                }
                else
                {
                    await Context.Channel.SendConfirmAsync(
                        text: string.Join("\n", scmds
                        .Select(x => $@"```css
#{x.Index}
[{GetText("server")}]: {(x.GuildId.HasValue ? $"{x.GuildName} #{x.GuildId}" : "-")}
[{GetText("channel")}]: {x.ChannelName} #{x.ChannelId}
[{GetText("command_text")}]: {x.CommandText}```")),
                        title: string.Empty,
                        footer: GetText("page", page + 1))
                    .ConfigureAwait(false);
                }
            }

            [NadekoCommand, Usage, Description, Aliases]
            [RequireContext(ContextType.Guild)]
            [RequireUserPermission(GuildPermission.Administrator)]
            // [OwnerOnly]
{'fraction_non_alphanumeric': 0.10257406508013599, 'fraction_numerical': 0.0015541525012141815, 'mean_word_length': 1.5733566608347913, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6099261', 'n_tokens_mistral': 2802, 'n_tokens_neox': 2636, 'n_words': 479}