diff --git a/src/NadekoBot/Modules/Administration/SelfCommands.cs b/src/NadekoBot/Modules/Administration/SelfCommands.cs index 32d902df..344b8379 100644 --- a/src/NadekoBot/Modules/Administration/SelfCommands.cs +++ b/src/NadekoBot/Modules/Administration/SelfCommands.cs @@ -31,9 +31,11 @@ namespace NadekoBot.Modules.Administration private readonly MusicService _music; private readonly IBotConfigProvider _bc; private readonly NadekoBot _bot; + private readonly IBotCredentials _creds; public SelfCommands(DbService db, NadekoBot bot, DiscordSocketClient client, - MusicService music, IImagesService images, IBotConfigProvider bc) + MusicService music, IImagesService images, IBotConfigProvider bc, + IBotCredentials creds) { _db = db; _client = client; @@ -41,6 +43,7 @@ namespace NadekoBot.Modules.Administration _music = music; _bc = bc; _bot = bot; + _creds = creds; } [NadekoCommand, Usage, Description, Aliases] @@ -280,6 +283,22 @@ namespace NadekoBot.Modules.Administration Environment.Exit(0); } + [NadekoCommand, Usage, Description, Aliases] + [OwnerOnly] + public async Task Restart() + { + var cmd = _creds.RestartCommand; + if (cmd == null || string.IsNullOrWhiteSpace(cmd.Cmd)) + { + await ReplyErrorLocalized("restart_fail").ConfigureAwait(false); + return; + } + + await ReplyConfirmLocalized("restarting").ConfigureAwait(false); + Process.Start(cmd.Cmd, cmd.Args); + Environment.Exit(0); + } + [NadekoCommand, Usage, Description, Aliases] [OwnerOnly] public async Task SetName([Remainder] string newName) diff --git a/src/NadekoBot/Modules/Searches/FeedCommands.cs b/src/NadekoBot/Modules/Searches/FeedCommands.cs index 38fe6be6..b98dfb2d 100644 --- a/src/NadekoBot/Modules/Searches/FeedCommands.cs +++ b/src/NadekoBot/Modules/Searches/FeedCommands.cs @@ -42,7 +42,12 @@ namespace NadekoBot.Modules.Searches { await reader.Read(); } - catch { success = false; } + catch (Exception ex) + { + + Console.WriteLine(ex); + success = false; + } } if (success) diff --git a/src/NadekoBot/Services/IBotCredentials.cs b/src/NadekoBot/Services/IBotCredentials.cs index f5ed37cc..3ee15942 100644 --- a/src/NadekoBot/Services/IBotCredentials.cs +++ b/src/NadekoBot/Services/IBotCredentials.cs @@ -24,14 +24,27 @@ namespace NadekoBot.Services string ShardRunArguments { get; } string PatreonCampaignId { get; } string CleverbotApiKey { get; } + RestartConfig RestartCommand { get; } + } + + public class RestartConfig + { + public RestartConfig(string cmd, string args) + { + this.Cmd = cmd; + this.Args = args; + } + + public string Cmd { get; } + public string Args { get; } } public class DBConfig { - public DBConfig(string type, string connString) + public DBConfig(string type, string connectionString) { this.Type = type; - this.ConnectionString = connString; + this.ConnectionString = connectionString; } public string Type { get; } public string ConnectionString { get; } diff --git a/src/NadekoBot/Services/Impl/BotCredentials.cs b/src/NadekoBot/Services/Impl/BotCredentials.cs index 0ee0dea9..07624cde 100644 --- a/src/NadekoBot/Services/Impl/BotCredentials.cs +++ b/src/NadekoBot/Services/Impl/BotCredentials.cs @@ -27,7 +27,7 @@ namespace NadekoBot.Services.Impl public string LoLApiKey { get; } public string OsuApiKey { get; } public string CleverbotApiKey { get; } - + public RestartConfig RestartCommand { get; } public DBConfig Db { get; } public int TotalShards { get; } public string CarbonKey { get; } @@ -72,6 +72,13 @@ namespace NadekoBot.Services.Impl ShardRunCommand = data[nameof(ShardRunCommand)]; ShardRunArguments = data[nameof(ShardRunArguments)]; CleverbotApiKey = data[nameof(CleverbotApiKey)]; + + var restartSection = data.GetSection(nameof(RestartCommand)); + var cmd = restartSection["cmd"]; + var args = restartSection["args"]; + if (!string.IsNullOrWhiteSpace(cmd)) + RestartCommand = new RestartConfig(cmd, args); + if (string.IsNullOrWhiteSpace(ShardRunCommand)) ShardRunCommand = "dotnet"; if (string.IsNullOrWhiteSpace(ShardRunArguments)) @@ -124,6 +131,7 @@ namespace NadekoBot.Services.Impl public int TotalShards { get; set; } = 1; public string PatreonAccessToken { get; set; } = ""; public string PatreonCampaignId { get; set; } = "334038"; + public string RestartCommand { get; set; } = null; public string ShardRunCommand { get; set; } = ""; public string ShardRunArguments { get; set; } = ""; diff --git a/src/NadekoBot/_strings/ResponseStrings.en-US.json b/src/NadekoBot/_strings/ResponseStrings.en-US.json index 081dc5c9..5e394681 100644 --- a/src/NadekoBot/_strings/ResponseStrings.en-US.json +++ b/src/NadekoBot/_strings/ResponseStrings.en-US.json @@ -878,5 +878,7 @@ "searches_feed_not_valid": "Invalid link, or you're already following that feed on this server, or you've reached maximum number of feeds allowed.", "searches_feed_out_of_range": "Index out of range.", "searches_feed_removed": "Feed removed.", - "searches_feed_no_feed": "You haven't subscribed to any feeds on this server." + "searches_feed_no_feed": "You haven't subscribed to any feeds on this server.", + "administration_restart_fail": "You must setup RestartCommand in your credentials.json", + "administration_restarting": "Restarting." } \ No newline at end of file diff --git a/src/NadekoBot/credentials_example.json b/src/NadekoBot/credentials_example.json index 5074f8e0..d3969554 100644 --- a/src/NadekoBot/credentials_example.json +++ b/src/NadekoBot/credentials_example.json @@ -18,6 +18,7 @@ "TotalShards": 1, "PatreonAccessToken": "", "PatreonCampaignId": "334038", + "RestartCommand": null, "ShardRunCommand": "", "ShardRunArguments": "", "ShardRunPort": null