Exemplo n.º 1
0
        public static async Task ReportException(Exception e, string source, string context = null)
        {
            await BotCore.Log(new LogMessage(LogSeverity.Error, source, context, e));

            if (TryGetChannel(out SocketTextChannel exceptionChannel))
            {
                EmbedBuilder exceptionEmbed = new EmbedBuilder()
                {
                    Description = Markdown.MultiLineCodeBlock(e.StackTrace.MaxLength(EmbedHelper.EMBEDDESCRIPTION_MAX - 6)),
                    Color       = BotCore.ErrorColor
                };
                if (TryGetRole(out SocketRole exceptionRole))
                {
                    exceptionEmbed.Title = $"{exceptionRole.Mention} Exception reported from `{source}`{(string.IsNullOrEmpty(context) ? "" : $" with context `{context}`")}".MaxLength(EmbedHelper.EMBEDTITLE_MAX);
                }
                else
                {
                    exceptionEmbed.Title = $"Exception reported from `{source}`{(string.IsNullOrEmpty(context) ? "" : $" with context `{context}`")}".MaxLength(EmbedHelper.EMBEDTITLE_MAX);
                }
Exemplo n.º 2
0
        public static async Task <JSONContainer> LoadJSONFile(string path)
        {
            if (File.Exists(path))
            {
                try
                {
                    string filecontent = await File.ReadAllTextAsync(path);

                    if (JSONContainer.TryParse(filecontent, out JSONContainer result, out string jsonerror))
                    {
                        return(result);
                    }
                    else
                    {
                        await BotCore.Log(new LogMessage(LogSeverity.Error, "RESOURCES", $"Couldn't load \"{path}\"! JSON parsing error: {jsonerror}"));

                        return(null);
                    }
                }