Restart command added. But it needs configuration in credentials.json

This commit is contained in:
Master Kwoth 2017-09-27 08:32:33 +02:00
parent 8354271989
commit ddb1103d1e
6 changed files with 54 additions and 6 deletions

View File

@ -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)

View File

@ -42,7 +42,12 @@ namespace NadekoBot.Modules.Searches
{
await reader.Read();
}
catch { success = false; }
catch (Exception ex)
{
Console.WriteLine(ex);
success = false;
}
}
if (success)

View File

@ -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; }

View File

@ -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; } = "";

View File

@ -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."
}

View File

@ -18,6 +18,7 @@
"TotalShards": 1,
"PatreonAccessToken": "",
"PatreonCampaignId": "334038",
"RestartCommand": null,
"ShardRunCommand": "",
"ShardRunArguments": "",
"ShardRunPort": null