public static async Task <LoadFileOperation> LoadToJSONObject(string path)
        {
            LoadFileOperation operation = new LoadFileOperation()
            {
                Success = false,
                Result  = null
            };

            if (File.Exists(path))
            {
                string fileContent = "";
                try
                {
                    fileContent = await File.ReadAllTextAsync(path, Encoding.UTF8);

                    operation.Result  = new JSONObject(fileContent);
                    operation.Success = true;
                    return(operation);
                }
                catch (Exception e)
                {
                    await BotCore.Logger(new Discord.LogMessage(Discord.LogSeverity.Critical, "Save/Load", "Failed to load " + path, e));
                }
            }
            return(operation);
        }
Example #2
0
        /// <summary>
        /// Sends an exception message to the debugmessage channel pinging the botdevs about it
        /// </summary>
        /// <param name="e">Exception</param>
        /// <param name="context">The context the command failing executed in</param>
        /// <param name="cmd">The command matched to the context</param>
        public async static void SendCommandExecutionExceptionMessage(Exception e, CommandContext context, Command cmd)
        {
            await context.Channel.SendEmbedAsync("Something went horribly wrong trying to execute your command! I have contacted my creators to help fix this issue!", true);

            ISocketMessageChannel channel = Var.client.GetChannel(SettingsModel.DebugMessageChannelId) as ISocketMessageChannel;

            if (channel != null)
            {
                EmbedBuilder embed = new EmbedBuilder();
                embed.Color = Var.ERRORCOLOR;
                embed.Title = "**__Exception__**";
                embed.AddField("Command", cmd.Key.KeyList);
                embed.AddField("Location", context.Guild.GetTextChannel(context.Channel.Id).Mention);
                embed.AddField("Message", Macros.MultiLineCodeBlock(e.Message));
                string stacktrace;
                if (e.StackTrace.Length <= 500)
                {
                    stacktrace = e.StackTrace;
                }
                else
                {
                    stacktrace = e.StackTrace.Substring(0, 500);
                }
                embed.AddField("StackTrace", Macros.MultiLineCodeBlock(stacktrace));
                string     message    = string.Empty;
                SocketRole botDevRole = context.Guild.GetRole(SettingsModel.BotDevRole);
                if (botDevRole != null)
                {
                    message = botDevRole.Mention;
                }
                await channel.SendMessageAsync(message, embed : embed.Build());
            }
            await BotCore.Logger(new LogMessage(LogSeverity.Error, "CMDSERVICE", string.Format("An Exception occured while trying to execute command `/{0}`.Message: '{1}'\nStackTrace {2}", cmd.Key.KeyList, e.Message, e.StackTrace)));
        }
 public static async Task WriteJSONObjectToFile(string path, JSONObject json)
 {
     try
     {
         await File.WriteAllTextAsync(path, json.ToString(), Encoding.UTF8);
     }
     catch (Exception e)
     {
         await BotCore.Logger(new Discord.LogMessage(Discord.LogSeverity.Critical, "Save/Load", "Failed to save " + path, e));
     }
 }