예제 #1
0
        public async Task Bean(IGuildUser user, [Remainder] string reason = null)
        {
            using var Database = new SkuldDbContextFactory().CreateDbContext();

            var usr = Database.Users.Find(user.Id);

            if (usr.Flags.IsBitSet(DiscordUtilities.Banned))
            {
                usr.Flags    -= DiscordUtilities.Banned;
                usr.BanReason = null;
                await
                EmbedExtensions.FromSuccess(SkuldAppContext.GetCaller(), $"Un-beaned {user.Mention}", Context)
                .QueueMessageAsync(Context).ConfigureAwait(false);
            }
            else
            {
                if (reason == null)
                {
                    await
                    EmbedExtensions.FromError($"{nameof(reason)} needs a value", Context)
                    .QueueMessageAsync(Context).ConfigureAwait(false);

                    return;
                }
                usr.Flags    += DiscordUtilities.Banned;
                usr.BanReason = reason;
                await
                EmbedExtensions.FromSuccess(SkuldAppContext.GetCaller(), $"Beaned {user.Mention} for reason: `{reason}`", Context)
                .QueueMessageAsync(Context).ConfigureAwait(false);
            }

            await Database.SaveChangesAsync().ConfigureAwait(false);
        }
예제 #2
0
        public static void Warning(string source,
                                   string message,
                                   ICommandContext context,
                                   Exception exception = null)
        {
            var msg = Message(source, message, LogSeverity.Warning);

            if (SkuldAppContext.GetLogSeverity() >= LogSeverity.Warning)
            {
                Console.Out.WriteLine(msg);
            }

            if (exception is not null)
            {
                var m = msg + "EXTRA INFORMATION:\n" + exception.ToString();

                if (SkuldAppContext.GetLogSeverity() >= LogSeverity.Warning || exception is not null)
                {
                    if (sentryClient is not null)
                    {
                        SentryEvent @event;
                        if (context is not null)
                        {
                            @event = context.ToSentryEvent(exception);
                        }
                        else
                        {
                            @event = exception.ToSentryEvent();
                        }

                        @event.Level = SentryLevel.Warning;
                        @event.SetTag("Source", source);

                        if (@event is not null)
                        {
                            sentryClient.CaptureEvent(@event);
                        }
                    }
                }

                if (LogFile is not null)
                {
                    LogFile.WriteLine(m);
                }
            }
            else if (LogFile is not null)
            {
                LogFile.WriteLine(msg);
            }

            Console.ForegroundColor = ConsoleColor.White;

            if (LogFile is not null)
            {
                LogFile.Flush();
            }
        }
예제 #3
0
        public async Task Shrug()
        {
            var images = await Imghoard.GetImagesAsync(SkuldAppContext.GetCaller().LowercaseFirstLetter()).ConfigureAwait(false);

            var image = images.Images.RandomValue().Url;

            await
            new EmbedBuilder()
            .WithImageUrl(image)
            .WithTitle(SkuldAppContext.GetCaller())
            .WithDescription($"{Context.User.Mention} shrugs")
            .WithRandomColor()
            .AddAuthor(Context.Client)
            .AddFooter(Context)
            .QueueMessageAsync(Context).ConfigureAwait(false);
        }
예제 #4
0
        public async Task Stab([Remainder] string target = null)
        {
            var images = await Imghoard.GetImagesAsync(SkuldAppContext.GetCaller().LowercaseFirstLetter()).ConfigureAwait(false);

            var image = images.Images.RandomValue().Url;

            var action = DoAction(
                image,
                SkuldAppContext.GetCaller(),
                GetMessage(target,
                           $"{Context.Client.CurrentUser.Mention} stabs {target}",
                           $"{Context.User.Mention} stabs {target}"
                           )
                );

            await action.QueueMessageAsync(Context).ConfigureAwait(false);
        }
예제 #5
0
파일: Actions.cs 프로젝트: Multivax/Skuld
        public async Task Kiss([Remainder] string target = null)
        {
            var images = await Imghoard.GetImagesAsync(SkuldAppContext.GetCaller().LowercaseFirstLetter()).ConfigureAwait(false);

            var image = images.Images.Random().Url;

            var action = DoAction(
                image,
                SkuldAppContext.GetCaller(),
                GetMessage(target,
                           $"I-it's not like I like you or anything... {Context.Client.CurrentUser.Mention} kisses {Context.User.Mention}",
                           $"{Context.User.Mention} kisses {target}"
                           )
                );

            await action.QueueMessageAsync(Context).ConfigureAwait(false);
        }
예제 #6
0
        public static void Info(string source,
                                string message)
        {
            var msg = Message(source, message, LogSeverity.Info);

            if (SkuldAppContext.GetLogSeverity() >= LogSeverity.Info)
            {
                Console.Out.WriteLine(msg);
            }

            if (LogFile is not null)
            {
                LogFile.WriteLine(msg);
            }

            Console.ForegroundColor = ConsoleColor.White;

            if (LogFile is not null)
            {
                LogFile.Flush();
            }
        }
예제 #7
0
        public async Task Debug()
        {
            using MemoryStream stream = new();
            using TextWriter writer   = new StreamWriter(stream);

            await writer.WriteLineAsync($"SKULD VERSION {Assembly.GetExecutingAssembly().GetName().Version}");

            await writer.WriteLineAsync($"\tINFORMATION");

            await writer.WriteLineAsync($"\t\tRUNTIME");

            await writer.WriteLineAsync($"\t\t\tSTARTED {Process.GetCurrentProcess().StartTime.ToDMYString()}");

            await writer.WriteLineAsync($"\t\t\tUPTIME {DateTime.Now.Subtract(Process.GetCurrentProcess().StartTime).ToDifferenceString()}");

            await writer.WriteLineAsync($"\t\t\tCOMMANDS: {SkuldApp.CommandService.Commands.Count()}");

            await writer.WriteLineAsync($"\t\t\tMODULES: {SkuldApp.CommandService.Modules.Count()}");

            await writer.WriteLineAsync($"\t\t\tMEMORY USAGE: {SkuldAppContext.MemoryStats.GetMBUsage}MB");

            await writer.WriteLineAsync($"\t\t\tCPU Usage: {await SkuldAppContext.GetCurrentCPUUsage()}%");

            await writer.WriteLineAsync($"\t\tDEPENDENCIES");

            foreach (AssemblyName dependent in Assembly.GetExecutingAssembly().GetReferencedAssemblies())
            {
                await writer.WriteLineAsync($"\t\t\t{dependent.Name} VERSION {dependent.Version}");
            }

            await writer.FlushAsync();

            stream.Position = 0;

            await Context.User.SendFileAsync(stream, "debug.txt");
        }
예제 #8
0
        public async Task Pet([Remainder] string target = null)
        {
            var images = await Imghoard.GetImagesAsync(SkuldAppContext.GetCaller().LowercaseFirstLetter()).ConfigureAwait(false);

            var image = images.Images.RandomValue().Url;

            var action =
                new EmbedBuilder()
                .WithImageUrl(image)
                .WithTitle(SkuldAppContext.GetCaller().CapitaliseFirstLetter())
                .WithRandomColor()
                .AddAuthor(Context.Client)
                .AddFooter(Context);

            if (target != null)
            {
                if (Context.Message.MentionedUsers.Any())
                {
                    List <ulong> prune = new List <ulong>();

                    {
                        using SkuldDbContext Database = new SkuldDbContextFactory().CreateDbContext(null);

                        foreach (var mentionedUser in Context.Message.MentionedUsers)
                        {
                            var res = Database.BlockedActions.FirstOrDefault(x => x.Blockee == Context.User.Id && x.Blocker == mentionedUser.Id);

                            if (res != null)
                            {
                                prune.Add(mentionedUser.Id);
                            }
                        }
                    }

                    {
                        using SkuldDbContext Database = new SkuldDbContextFactory().CreateDbContext(null);
                        var initiator = await Database.InsertOrGetUserAsync(Context.User).ConfigureAwait(false);

                        StringBuilder message = new StringBuilder($"{Context.User.Mention} pets ");

                        var msg = target;

                        foreach (var usr in Context.Message.MentionedUsers)
                        {
                            if (usr.IsBot || usr.IsWebhook || usr.Discriminator == "0000" || usr.DiscriminatorValue == 0 || prune.Contains(usr.Id))
                            {
                                continue;
                            }

                            var uzr = await Database.InsertOrGetUserAsync(usr).ConfigureAwait(false);

                            if (!(uzr.RecurringBlock && uzr.Patted.IsRecurring(3)))
                            {
                                uzr.Patted     += 1;
                                initiator.Pats += 1;

                                message.Append(usr.Mention + " ");
                            }
                            else
                            {
                                msg.PruneMention(usr.Id);
                            }
                        }

                        await Database.SaveChangesAsync().ConfigureAwait(false);

                        if (message.ToString() != $"{Context.User.Mention} pets ")
                        {
                            action.WithDescription(message.ToString());
                        }
                        else
                        {
                            action.WithDescription($"{Context.Client.CurrentUser.Mention} pets {Context.User.Mention}");
                        }
                    }
                }
                else
                {
                    action.WithDescription($"{Context.User.Mention} pets {target}");
                }
            }
            else
            {
                action.WithDescription($"{Context.Client.CurrentUser.Mention} pets {Context.User.Mention}");
            }

            await action.QueueMessageAsync(Context).ConfigureAwait(false);
        }
예제 #9
0
        private static async Task Bot_ReactionAdded(
            Cacheable <IUserMessage, ulong> arg1,
            ISocketMessageChannel arg2,
            SocketReaction arg3)
        {
            DogStatsd.Increment("messages.reactions.added");
            IUser usr;

            var msg = await arg1.GetOrDownloadAsync().ConfigureAwait(false);

            if (msg == null)
            {
                return;
            }

            if (!arg3.User.IsSpecified)
            {
                return;
            }
            else
            {
                usr = arg3.User.Value;
            }

            if (usr.IsBot || usr.IsWebhook)
            {
                return;
            }

            if (arg2 is IGuildChannel)
            {
                await PinningService.ExecuteAdditionAsync(SkuldApp.DiscordClient, SkuldApp.Configuration, msg, arg2)
                .ConfigureAwait(false);

                await StarboardService.ExecuteAdditionAsync(msg, arg2, arg3)
                .ConfigureAwait(false);
            }

            if (arg2.Id == SkuldApp.Configuration.IssueChannel)
            {
                using var Database = new SkuldDbContextFactory()
                                     .CreateDbContext();

                var user = await Database.InsertOrGetUserAsync(usr)
                           .ConfigureAwait(false);

                if (user.Flags.IsBitSet(DiscordUtilities.BotCreator))
                {
                    try
                    {
                        if (arg1.HasValue)
                        {
                            var message = Database.Issues
                                          .FirstOrDefault(x =>
                                                          x.IssueChannelMessageId == arg1.Id
                                                          );
                            if (message != null)
                            {
                                var emote = arg3.Emote as Emote;

                                if (emote.Id == DiscordUtilities.Tick_Emote.Id)
                                {
                                    if (!message.HasSent)
                                    {
                                        try
                                        {
                                            var newissue =
                                                new NewIssue(message.Title)
                                            {
                                                Body = message.Body
                                            };

                                            newissue.
                                            Assignees.Add("exsersewo");
                                            newissue.
                                            Labels.Add("From Command");

                                            var issue = await SkuldApp
                                                        .Services
                                                        .GetRequiredService
                                                        <GitHubClient>()
                                                        .Issue
                                                        .Create(
                                                SkuldApp
                                                .Configuration
                                                .GithubRepository,
                                                newissue
                                                ).ConfigureAwait(false);

                                            try
                                            {
                                                await SkuldApp.DiscordClient
                                                .GetUser(
                                                    message.SubmitterId
                                                    )
                                                .SendMessageAsync(
                                                    "",
                                                    false,
                                                    new EmbedBuilder()
                                                    .WithTitle(
                                                        "Good News!"
                                                        )
                                                    .AddAuthor(
                                                        SkuldApp
                                                        .DiscordClient
                                                        )
                                                    .WithDescription(
                                                        "Your issue:\n" +
                                                        $"\"[{newissue.Title}]" +
                                                        $"({issue.HtmlUrl})\"" +
                                                        "\n\nhas been accepted"
                                                        )
                                                    .WithRandomColor()
                                                    .Build()
                                                    ).ConfigureAwait(false);
                                            }
                                            catch { }

                                            await msg.ModifyAsync(x =>
                                            {
                                                x.Embed = msg.Embeds
                                                          .ElementAt(0)
                                                          .ToEmbedBuilder()
                                                          .AddField(
                                                    "Sent",
                                                    DiscordUtilities
                                                    .Tick_Emote
                                                    .ToString()
                                                    )
                                                          .Build();
                                            }).ConfigureAwait(false);

                                            message.HasSent = true;

                                            await Database.SaveChangesAsync()
                                            .ConfigureAwait(false);
                                        }
                                        catch (Exception ex)
                                        {
                                            Log.Error(
                                                "Git-" +
                                                SkuldAppContext.GetCaller(),
                                                ex.Message,
                                                null,
                                                ex
                                                );
                                        }
                                    }
                                }
                                else if (
                                    emote.Id == DiscordUtilities.Cross_Emote.Id
                                    )
                                {
                                    Database.Issues.Remove(message);

                                    await Database.SaveChangesAsync()
                                    .ConfigureAwait(false);

                                    await msg.DeleteAsync()
                                    .ConfigureAwait(false);

                                    try
                                    {
                                        await SkuldApp
                                        .DiscordClient
                                        .GetUser(message.SubmitterId)
                                        .SendMessageAsync(
                                            "",
                                            false,
                                            new EmbedBuilder()
                                            .WithTitle("Bad News")
                                            .AddAuthor(
                                                SkuldApp.DiscordClient
                                                )
                                            .WithDescription(
                                                "Your issue:\n" +
                                                $"\"{message.Title}\"" +
                                                "\n\nhas been declined. " +
                                                "If you would like to know why, " +
                                                $"send: {usr.FullName()} a message"
                                                )
                                            .WithRandomColor()
                                            .Build()
                                            ).ConfigureAwait(false);
                                    }
                                    catch { }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Critical(Key,
                                     ex.Message,
                                     null,
                                     ex
                                     );
                    }
                }
            }
        }
예제 #10
0
        public static async Task Main(string[] args = null)
        {
            string defaultEnv = Path.Combine(SkuldAppContext.BaseDirectory, ".env");

            if (!File.Exists(defaultEnv))
            {
                Console.WriteLine("Copy .env.default into .env and enter details");
                return;
            }

            DotEnv.Load(new DotEnvOptions(envFilePaths: new[] { defaultEnv }));

            if (args.Contains("--pq"))
            {
                GeneratePixelQuery();
                return;
            }

            SkuldConfig Configuration = null;

            Log.Configure();

            if (!Directory.Exists(SkuldAppContext.StorageDirectory))
            {
                Directory.CreateDirectory(SkuldAppContext.StorageDirectory);
                Log.Verbose(Key, "Created Storage Directory", null);
            }
            if (!Directory.Exists(SkuldAppContext.FontDirectory))
            {
                Directory.CreateDirectory(SkuldAppContext.FontDirectory);
                Log.Verbose(Key, "Created Font Directory", null);
            }

            try
            {
                var database = new SkuldDbContextFactory().CreateDbContext();

                if (!database.Configurations.Any() ||
                    args.Contains("--newconf") ||
                    args.Contains("-nc"))
                {
                    var conf = new SkuldConfig();
                    database.Configurations.Add(conf);
                    await database.SaveChangesAsync().ConfigureAwait(false);

                    Log.Verbose(Key, $"Created new configuration with Id: {conf.Id}", null);

                    Log.Info(Key, $"Please fill out the configuration information in the database matching the Id \"{database.Configurations.LastOrDefault().Id}\"");
                    Console.ReadKey();
                    Environment.Exit(0);
                }

                var configId = SkuldAppContext.GetEnvVar(SkuldAppContext.ConfigEnvVar);

                var c = database.Configurations.Find(configId);

                Configuration = c ?? database.Configurations.FirstOrDefault();

                SkuldAppContext.SetConfigurationId(Configuration.Id);
            }
            catch (Exception ex)
            {
                Log.Critical(Key, ex.Message, null, ex);
            }

            if (Configuration.DiscordToken.IsNullOrWhiteSpace())
            {
                Log.Critical(Key, "You haven't provided a discord token, exiting", null);
                return;
            }

            await ConfigureBotAsync(
                Configuration,
                new DiscordSocketConfig
            {
                MessageCacheSize = 100,
                DefaultRetryMode = RetryMode.AlwaysRetry,
                LogLevel         = LogSeverity.Verbose,
                GatewayIntents   = GatewayIntents.Guilds |
                                   GatewayIntents.GuildMembers |
                                   GatewayIntents.GuildBans |
                                   GatewayIntents.GuildEmojis |
                                   GatewayIntents.GuildIntegrations |
                                   GatewayIntents.GuildWebhooks |
                                   GatewayIntents.GuildInvites |
                                   GatewayIntents.GuildVoiceStates |
                                   GatewayIntents.GuildMessages |
                                   GatewayIntents.GuildMessageReactions |
                                   GatewayIntents.DirectMessages |
                                   GatewayIntents.DirectMessageReactions
            },
                new CommandServiceConfig
            {
                CaseSensitiveCommands = false,
                DefaultRunMode        = RunMode.Async,
                LogLevel        = LogSeverity.Verbose,
                IgnoreExtraArgs = true
            },
                new MessageServiceConfig
            {
                Prefix    = Configuration.Prefix,
                AltPrefix = Configuration.AltPrefix
            }
                ).ConfigureAwait(false);

            Log.Info(Key, "Loaded Skuld v" + SkuldAppContext.Skuld.Key.Version);

            await StartBotAsync().ConfigureAwait(false);

            await Task.Delay(-1).ConfigureAwait(false);

            await StopBotAsync(Key);

            WebSocket.ShutdownServer();

            Environment.Exit(0);
        }