Restart command added. But it needs configuration in credentials.json
This commit is contained in:
parent
8354271989
commit
ddb1103d1e
@ -31,9 +31,11 @@ namespace NadekoBot.Modules.Administration
|
|||||||
private readonly MusicService _music;
|
private readonly MusicService _music;
|
||||||
private readonly IBotConfigProvider _bc;
|
private readonly IBotConfigProvider _bc;
|
||||||
private readonly NadekoBot _bot;
|
private readonly NadekoBot _bot;
|
||||||
|
private readonly IBotCredentials _creds;
|
||||||
|
|
||||||
public SelfCommands(DbService db, NadekoBot bot, DiscordSocketClient client,
|
public SelfCommands(DbService db, NadekoBot bot, DiscordSocketClient client,
|
||||||
MusicService music, IImagesService images, IBotConfigProvider bc)
|
MusicService music, IImagesService images, IBotConfigProvider bc,
|
||||||
|
IBotCredentials creds)
|
||||||
{
|
{
|
||||||
_db = db;
|
_db = db;
|
||||||
_client = client;
|
_client = client;
|
||||||
@ -41,6 +43,7 @@ namespace NadekoBot.Modules.Administration
|
|||||||
_music = music;
|
_music = music;
|
||||||
_bc = bc;
|
_bc = bc;
|
||||||
_bot = bot;
|
_bot = bot;
|
||||||
|
_creds = creds;
|
||||||
}
|
}
|
||||||
|
|
||||||
[NadekoCommand, Usage, Description, Aliases]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
@ -280,6 +283,22 @@ namespace NadekoBot.Modules.Administration
|
|||||||
Environment.Exit(0);
|
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]
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
[OwnerOnly]
|
[OwnerOnly]
|
||||||
public async Task SetName([Remainder] string newName)
|
public async Task SetName([Remainder] string newName)
|
||||||
|
@ -42,7 +42,12 @@ namespace NadekoBot.Modules.Searches
|
|||||||
{
|
{
|
||||||
await reader.Read();
|
await reader.Read();
|
||||||
}
|
}
|
||||||
catch { success = false; }
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (success)
|
if (success)
|
||||||
|
@ -24,14 +24,27 @@ namespace NadekoBot.Services
|
|||||||
string ShardRunArguments { get; }
|
string ShardRunArguments { get; }
|
||||||
string PatreonCampaignId { get; }
|
string PatreonCampaignId { get; }
|
||||||
string CleverbotApiKey { 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 class DBConfig
|
||||||
{
|
{
|
||||||
public DBConfig(string type, string connString)
|
public DBConfig(string type, string connectionString)
|
||||||
{
|
{
|
||||||
this.Type = type;
|
this.Type = type;
|
||||||
this.ConnectionString = connString;
|
this.ConnectionString = connectionString;
|
||||||
}
|
}
|
||||||
public string Type { get; }
|
public string Type { get; }
|
||||||
public string ConnectionString { get; }
|
public string ConnectionString { get; }
|
||||||
|
@ -27,7 +27,7 @@ namespace NadekoBot.Services.Impl
|
|||||||
public string LoLApiKey { get; }
|
public string LoLApiKey { get; }
|
||||||
public string OsuApiKey { get; }
|
public string OsuApiKey { get; }
|
||||||
public string CleverbotApiKey { get; }
|
public string CleverbotApiKey { get; }
|
||||||
|
public RestartConfig RestartCommand { get; }
|
||||||
public DBConfig Db { get; }
|
public DBConfig Db { get; }
|
||||||
public int TotalShards { get; }
|
public int TotalShards { get; }
|
||||||
public string CarbonKey { get; }
|
public string CarbonKey { get; }
|
||||||
@ -72,6 +72,13 @@ namespace NadekoBot.Services.Impl
|
|||||||
ShardRunCommand = data[nameof(ShardRunCommand)];
|
ShardRunCommand = data[nameof(ShardRunCommand)];
|
||||||
ShardRunArguments = data[nameof(ShardRunArguments)];
|
ShardRunArguments = data[nameof(ShardRunArguments)];
|
||||||
CleverbotApiKey = data[nameof(CleverbotApiKey)];
|
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))
|
if (string.IsNullOrWhiteSpace(ShardRunCommand))
|
||||||
ShardRunCommand = "dotnet";
|
ShardRunCommand = "dotnet";
|
||||||
if (string.IsNullOrWhiteSpace(ShardRunArguments))
|
if (string.IsNullOrWhiteSpace(ShardRunArguments))
|
||||||
@ -124,6 +131,7 @@ namespace NadekoBot.Services.Impl
|
|||||||
public int TotalShards { get; set; } = 1;
|
public int TotalShards { get; set; } = 1;
|
||||||
public string PatreonAccessToken { get; set; } = "";
|
public string PatreonAccessToken { get; set; } = "";
|
||||||
public string PatreonCampaignId { get; set; } = "334038";
|
public string PatreonCampaignId { get; set; } = "334038";
|
||||||
|
public string RestartCommand { get; set; } = null;
|
||||||
|
|
||||||
public string ShardRunCommand { get; set; } = "";
|
public string ShardRunCommand { get; set; } = "";
|
||||||
public string ShardRunArguments { get; set; } = "";
|
public string ShardRunArguments { get; set; } = "";
|
||||||
|
@ -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_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_out_of_range": "Index out of range.",
|
||||||
"searches_feed_removed": "Feed removed.",
|
"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."
|
||||||
}
|
}
|
@ -18,6 +18,7 @@
|
|||||||
"TotalShards": 1,
|
"TotalShards": 1,
|
||||||
"PatreonAccessToken": "",
|
"PatreonAccessToken": "",
|
||||||
"PatreonCampaignId": "334038",
|
"PatreonCampaignId": "334038",
|
||||||
|
"RestartCommand": null,
|
||||||
"ShardRunCommand": "",
|
"ShardRunCommand": "",
|
||||||
"ShardRunArguments": "",
|
"ShardRunArguments": "",
|
||||||
"ShardRunPort": null
|
"ShardRunPort": null
|
||||||
|
Loading…
Reference in New Issue
Block a user