diff --git a/src/NadekoBot/Modules/Games/Commands/PollCommands.cs b/src/NadekoBot/Modules/Games/Commands/PollCommands.cs index 1cf5b951..27dbb03c 100644 --- a/src/NadekoBot/Modules/Games/Commands/PollCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PollCommands.cs @@ -44,9 +44,14 @@ namespace NadekoBot.Modules.Games await Context.Channel.EmbedAsync(poll.GetStats(GetText("current_poll_results"))); } - + //todo enable private polls, or completely remove them private async Task InternalStartPoll(string arg, bool isPublic = false) { + if (isPublic == false) + { + await ReplyErrorLocalized($"Temporarily disabled. Use `{Prefix}ppoll`"); + return; + } if(await _polls.StartPoll((ITextChannel)Context.Channel, Context.Message, arg, isPublic) == false) await ReplyErrorLocalized("poll_already_running").ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Utility/Utility.cs b/src/NadekoBot/Modules/Utility/Utility.cs index caf0e6b0..1b0276e6 100644 --- a/src/NadekoBot/Modules/Utility/Utility.cs +++ b/src/NadekoBot/Modules/Utility/Utility.cs @@ -18,6 +18,7 @@ using Discord.WebSocket; using System.Diagnostics; using Color = Discord.Color; using NadekoBot.Services; +using NadekoBot.DataStructures; namespace NadekoBot.Modules.Utility { @@ -277,48 +278,41 @@ namespace NadekoBot.Modules.Utility await Context.Channel.SendConfirmAsync($"{Context.User.Mention} https://discord.gg/{invite.Code}"); } - //todo 2 shard commands - //[NadekoCommand, Usage, Description, Aliases] - //public async Task ShardStats(int page = 1) - //{ - // if (--page < 0) - // return; - // var status = string.Join(", ", _client.Shards.GroupBy(x => x.ConnectionState) - // .Select(x => $"{x.Count()} {x.Key}") - // .ToArray()); + [NadekoCommand, Usage, Description, Aliases] + [Shard0Precondition] + public async Task ShardStats(int page = 1) + { + if (--page < 0) + return; - // var allShardStrings = _client.Shards - // .Select(x => - // GetText("shard_stats_txt", x.ShardId.ToString(), - // Format.Bold(x.ConnectionState.ToString()), Format.Bold(x.Guilds.Count.ToString()))) - // .ToArray(); + var status = string.Join(", ", _bot.ShardCoord.Statuses.GroupBy(x => x.ConnectionState) + .Select(x => $"{x.Count()} {x.Key}") + .ToArray()); + + var allShardStrings = _bot.ShardCoord.Statuses + .Select(x => + GetText("shard_stats_txt", x.ShardId.ToString(), + Format.Bold(x.ConnectionState.ToString()), Format.Bold(x.Guilds.ToString()))) + .ToArray(); - // await Context.Channel.SendPaginatedConfirmAsync(_client, page, (curPage) => - // { + await Context.Channel.SendPaginatedConfirmAsync(_client, page, (curPage) => + { - // var str = string.Join("\n", allShardStrings.Skip(25 * curPage).Take(25)); + var str = string.Join("\n", allShardStrings.Skip(25 * curPage).Take(25)); - // if (string.IsNullOrWhiteSpace(str)) - // str = GetText("no_shards_on_page"); + if (string.IsNullOrWhiteSpace(str)) + str = GetText("no_shards_on_page"); - // return new EmbedBuilder() - // .WithAuthor(a => a.WithName(GetText("shard_stats"))) - // .WithTitle(status) - // .WithOkColor() - // .WithDescription(str); - // }, allShardStrings.Length / 25); - //} - - //[NadekoCommand, Usage, Description, Aliases] - //public async Task ShardId(IGuild guild) - //{ - // var shardId = _client.GetShardIdFor(guild); - - // await Context.Channel.SendConfirmAsync(shardId.ToString()).ConfigureAwait(false); - //} + return new EmbedBuilder() + .WithAuthor(a => a.WithName(GetText("shard_stats"))) + .WithTitle(status) + .WithOkColor() + .WithDescription(str); + }, allShardStrings.Length / 25); + } [NadekoCommand, Usage, Description, Aliases] public async Task Stats() diff --git a/src/NadekoBot/Services/IBotCredentials.cs b/src/NadekoBot/Services/IBotCredentials.cs index d7a7073c..e0c271b5 100644 --- a/src/NadekoBot/Services/IBotCredentials.cs +++ b/src/NadekoBot/Services/IBotCredentials.cs @@ -20,6 +20,8 @@ namespace NadekoBot.Services bool IsOwner(IUser u); int TotalShards { get; } + string ShardRunCommand { get; } + string ShardRunArguments { get; } } public class DBConfig diff --git a/src/NadekoBot/Services/Impl/BotCredentials.cs b/src/NadekoBot/Services/Impl/BotCredentials.cs index 92ae20c1..3517a298 100644 --- a/src/NadekoBot/Services/Impl/BotCredentials.cs +++ b/src/NadekoBot/Services/Impl/BotCredentials.cs @@ -30,20 +30,22 @@ namespace NadekoBot.Services.Impl public int TotalShards { get; } public string CarbonKey { get; } - public string credsFileName { get; } = Path.Combine(Directory.GetCurrentDirectory(), "credentials.json"); + private readonly string _credsFileName = Path.Combine(Directory.GetCurrentDirectory(), "credentials.json"); public string PatreonAccessToken { get; } + public string ShardRunCommand { get; } + public string ShardRunArguments { get; } public BotCredentials() { _log = LogManager.GetCurrentClassLogger(); try { File.WriteAllText("./credentials_example.json", JsonConvert.SerializeObject(new CredentialsModel(), Formatting.Indented)); } catch { } - if(!File.Exists(credsFileName)) + if(!File.Exists(_credsFileName)) _log.Warn($"credentials.json is missing. Attempting to load creds from environment variables prefixed with 'NadekoBot_'. Example is in {Path.GetFullPath("./credentials_example.json")}"); try { var configBuilder = new ConfigurationBuilder(); - configBuilder.AddJsonFile(credsFileName, true) + configBuilder.AddJsonFile(_credsFileName, true) .AddEnvironmentVariables("NadekoBot_"); var data = configBuilder.Build(); @@ -61,13 +63,19 @@ namespace NadekoBot.Services.Impl MashapeKey = data[nameof(MashapeKey)]; OsuApiKey = data[nameof(OsuApiKey)]; PatreonAccessToken = data[nameof(PatreonAccessToken)]; + ShardRunCommand = data[nameof(ShardRunCommand)]; + ShardRunArguments = data[nameof(ShardRunArguments)]; + + if (string.IsNullOrWhiteSpace(ShardRunCommand)) + ShardRunCommand = "dotnet"; + if (string.IsNullOrWhiteSpace(ShardRunArguments)) + ShardRunArguments = "run -c Release -- {0} {1}"; int ts = 1; int.TryParse(data[nameof(TotalShards)], out ts); TotalShards = ts < 1 ? 1 : ts; - ulong clId = 0; - ulong.TryParse(data[nameof(ClientId)], out clId); + ulong.TryParse(data[nameof(ClientId)], out ulong clId); ClientId = clId; //var scId = data[nameof(SoundCloudClientId)]; @@ -107,6 +115,7 @@ namespace NadekoBot.Services.Impl public DBConfig Db { get; set; } = new DBConfig("sqlite", "Filename=./data/NadekoBot.db"); public int TotalShards { get; set; } = 1; public string PatreonAccessToken { get; set; } = ""; + public string ShardRunCommand { get; set; } = ""; } private class DbModel diff --git a/src/NadekoBot/ShardsCoordinator.cs b/src/NadekoBot/ShardsCoordinator.cs index acdac540..395ad71d 100644 --- a/src/NadekoBot/ShardsCoordinator.cs +++ b/src/NadekoBot/ShardsCoordinator.cs @@ -13,7 +13,7 @@ namespace NadekoBot { private readonly BotCredentials Credentials; private Process[] ShardProcesses; - private ShardComMessage[] Statuses; + public ShardComMessage[] Statuses { get; } private readonly Logger _log; private readonly ShardComServer _comServer; @@ -35,7 +35,7 @@ namespace NadekoBot { Statuses[msg.ShardId] = msg; if (msg.ConnectionState == Discord.ConnectionState.Disconnected || msg.ConnectionState == Discord.ConnectionState.Disconnecting) - _log.Error("!!! SHARD {0} IS IN {1} STATE", msg.ShardId, msg.ConnectionState); + _log.Error("!!! SHARD {0} IS IN {1} STATE", msg.ShardId, msg.ConnectionState.ToString()); return Task.CompletedTask; } @@ -46,13 +46,10 @@ namespace NadekoBot { var p = Process.Start(new ProcessStartInfo() { - FileName = "dotnet", - Arguments = $"run -c Debug -- {i} {curProcessId}", + FileName = Credentials.ShardRunCommand, + Arguments = string.Format(Credentials.ShardRunArguments, i, curProcessId) }); await Task.Delay(5000); - - //Task.Run(() => { while (!p.HasExited) _log.Info($"S-{i}|" + p.StandardOutput.ReadLine()); }); - //Task.Run(() => { while (!p.HasExited) _log.Error($"S-{i}|" + p.StandardError.ReadLine()); }); } } diff --git a/src/NadekoBot/credentials_example.json b/src/NadekoBot/credentials_example.json index 912b452a..7c7e4095 100644 --- a/src/NadekoBot/credentials_example.json +++ b/src/NadekoBot/credentials_example.json @@ -15,5 +15,6 @@ "ConnectionString": "Filename=./data/NadekoBot.db" }, "TotalShards": 1, - "PatreonAccessToken": "" + "PatreonAccessToken": "", + "ShardRunCommand": "" } \ No newline at end of file