diff --git a/src/NadekoBot/DataStructures/TypeReaders/BotCommandTypeReader.cs b/src/NadekoBot/DataStructures/TypeReaders/BotCommandTypeReader.cs index 6a292833..8a415eae 100644 --- a/src/NadekoBot/DataStructures/TypeReaders/BotCommandTypeReader.cs +++ b/src/NadekoBot/DataStructures/TypeReaders/BotCommandTypeReader.cs @@ -1,6 +1,7 @@ using Discord.Commands; using NadekoBot.Services; using NadekoBot.Services.CustomReactions; +using System; using System.Linq; using System.Threading.Tasks; @@ -17,7 +18,7 @@ namespace NadekoBot.TypeReaders _cmdHandler = cmdHandler; } - public override Task Read(ICommandContext context, string input) + public override Task Read(ICommandContext context, string input, IServiceProvider _) { input = input.ToUpperInvariant(); var prefix = _cmdHandler.GetPrefix(context.Guild); @@ -44,7 +45,7 @@ namespace NadekoBot.TypeReaders _crs = crs; } - public override async Task Read(ICommandContext context, string input) + public override async Task Read(ICommandContext context, string input, IServiceProvider _) { input = input.ToUpperInvariant(); @@ -64,7 +65,7 @@ namespace NadekoBot.TypeReaders } } - var cmd = await base.Read(context, input); + var cmd = await base.Read(context, input, _); if (cmd.IsSuccess) { return TypeReaderResult.FromSuccess(new CommandOrCrInfo(((CommandInfo)cmd.Values.First().Value).Name)); diff --git a/src/NadekoBot/DataStructures/TypeReaders/GuildDateTimeTypeReader.cs b/src/NadekoBot/DataStructures/TypeReaders/GuildDateTimeTypeReader.cs index 798caf62..7e394a21 100644 --- a/src/NadekoBot/DataStructures/TypeReaders/GuildDateTimeTypeReader.cs +++ b/src/NadekoBot/DataStructures/TypeReaders/GuildDateTimeTypeReader.cs @@ -14,7 +14,7 @@ namespace NadekoBot.TypeReaders _gts = gts; } - public override Task Read(ICommandContext context, string input) + public override Task Read(ICommandContext context, string input, IServiceProvider _) { if (!DateTime.TryParse(input, out var dt)) return Task.FromResult(TypeReaderResult.FromError(CommandError.ParseFailed, "Input string is in an incorrect format.")); diff --git a/src/NadekoBot/DataStructures/TypeReaders/GuildTypeReader.cs b/src/NadekoBot/DataStructures/TypeReaders/GuildTypeReader.cs index 3bb72d4c..068514fb 100644 --- a/src/NadekoBot/DataStructures/TypeReaders/GuildTypeReader.cs +++ b/src/NadekoBot/DataStructures/TypeReaders/GuildTypeReader.cs @@ -1,5 +1,6 @@ using Discord.Commands; using Discord.WebSocket; +using System; using System.Linq; using System.Threading.Tasks; @@ -13,7 +14,7 @@ namespace NadekoBot.TypeReaders { _client = client; } - public override Task Read(ICommandContext context, string input) + public override Task Read(ICommandContext context, string input, IServiceProvider _) { input = input.Trim().ToLowerInvariant(); var guilds = _client.Guilds; diff --git a/src/NadekoBot/DataStructures/TypeReaders/ModuleTypeReader.cs b/src/NadekoBot/DataStructures/TypeReaders/ModuleTypeReader.cs index 88645835..60adfc26 100644 --- a/src/NadekoBot/DataStructures/TypeReaders/ModuleTypeReader.cs +++ b/src/NadekoBot/DataStructures/TypeReaders/ModuleTypeReader.cs @@ -1,5 +1,6 @@ using Discord.Commands; using NadekoBot.Extensions; +using System; using System.Linq; using System.Threading.Tasks; @@ -14,7 +15,7 @@ namespace NadekoBot.TypeReaders _cmds = cmds; } - public override Task Read(ICommandContext context, string input) + public override Task Read(ICommandContext context, string input, IServiceProvider _) { input = input.ToUpperInvariant(); var module = _cmds.Modules.GroupBy(m => m.GetTopLevelModule()).FirstOrDefault(m => m.Key.Name.ToUpperInvariant() == input)?.Key; @@ -34,7 +35,7 @@ namespace NadekoBot.TypeReaders _cmds = cmds; } - public override Task Read(ICommandContext context, string input) + public override Task Read(ICommandContext context, string input, IServiceProvider _) { input = input.ToLowerInvariant(); var module = _cmds.Modules.GroupBy(m => m.GetTopLevelModule()).FirstOrDefault(m => m.Key.Name.ToLowerInvariant() == input)?.Key; diff --git a/src/NadekoBot/DataStructures/TypeReaders/PermissionActionTypeReader.cs b/src/NadekoBot/DataStructures/TypeReaders/PermissionActionTypeReader.cs index aa3510a6..9ca20229 100644 --- a/src/NadekoBot/DataStructures/TypeReaders/PermissionActionTypeReader.cs +++ b/src/NadekoBot/DataStructures/TypeReaders/PermissionActionTypeReader.cs @@ -1,6 +1,7 @@ using Discord.Commands; using System.Threading.Tasks; using NadekoBot.Modules.Permissions; +using System; namespace NadekoBot.TypeReaders { @@ -9,7 +10,7 @@ namespace NadekoBot.TypeReaders /// public class PermissionActionTypeReader : TypeReader { - public override Task Read(ICommandContext context, string input) + public override Task Read(ICommandContext context, string input, IServiceProvider _) { input = input.ToUpperInvariant(); switch (input) diff --git a/src/NadekoBot/Modules/Administration/Commands/UserPunishCommands.cs b/src/NadekoBot/Modules/Administration/Commands/UserPunishCommands.cs index 7e2a453a..9e7df4ec 100644 --- a/src/NadekoBot/Modules/Administration/Commands/UserPunishCommands.cs +++ b/src/NadekoBot/Modules/Administration/Commands/UserPunishCommands.cs @@ -109,7 +109,7 @@ namespace NadekoBot.Modules.Administration { try { - await (await user.CreateDMChannelAsync()).EmbedAsync(new EmbedBuilder().WithErrorColor() + await (await user.GetOrCreateDMChannelAsync()).EmbedAsync(new EmbedBuilder().WithErrorColor() .WithDescription(GetText("warned_on", Context.Guild.ToString())) .AddField(efb => efb.WithName(GetText("moderator")).WithValue(Context.User.ToString())) .AddField(efb => efb.WithName(GetText("reason")).WithValue(reason ?? "-"))) diff --git a/src/NadekoBot/Modules/Gambling/Commands/FlowerShop.cs b/src/NadekoBot/Modules/Gambling/Commands/FlowerShop.cs index dd4fd309..942ead4c 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/FlowerShop.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/FlowerShop.cs @@ -154,7 +154,7 @@ namespace NadekoBot.Modules.Gambling } try { - await (await Context.User.CreateDMChannelAsync()) + await (await Context.User.GetOrCreateDMChannelAsync()) .EmbedAsync(new EmbedBuilder().WithOkColor() .WithTitle(GetText("shop_purchase", Context.Guild.Name)) .AddField(efb => efb.WithName(GetText("item")).WithValue(item.Text).WithIsInline(false)) diff --git a/src/NadekoBot/Modules/Help/Help.cs b/src/NadekoBot/Modules/Help/Help.cs index 18ddf039..4b15b72e 100644 --- a/src/NadekoBot/Modules/Help/Help.cs +++ b/src/NadekoBot/Modules/Help/Help.cs @@ -96,7 +96,7 @@ namespace NadekoBot.Modules.Help if (com == null) { - IMessageChannel ch = channel is ITextChannel ? await ((IGuildUser)Context.User).CreateDMChannelAsync() : channel; + IMessageChannel ch = channel is ITextChannel ? await ((IGuildUser)Context.User).GetOrCreateDMChannelAsync() : channel; await ch.SendMessageAsync(HelpString).ConfigureAwait(false); return; } diff --git a/src/NadekoBot/Modules/NadekoModule.cs b/src/NadekoBot/Modules/NadekoModule.cs index 45abaea9..db7086fa 100644 --- a/src/NadekoBot/Modules/NadekoModule.cs +++ b/src/NadekoBot/Modules/NadekoModule.cs @@ -32,7 +32,7 @@ namespace NadekoBot.Modules _log = LogManager.GetCurrentClassLogger(); } - protected override void BeforeExecute() + protected override void BeforeExecute(CommandInfo cmd) { _cultureInfo = _localization.GetCultureInfo(Context.Guild?.Id); } diff --git a/src/NadekoBot/Modules/Searches/Searches.cs b/src/NadekoBot/Modules/Searches/Searches.cs index 0a8eec54..ea2990f5 100644 --- a/src/NadekoBot/Modules/Searches/Searches.cs +++ b/src/NadekoBot/Modules/Searches/Searches.cs @@ -667,7 +667,7 @@ namespace NadekoBot.Modules.Searches str += new NadekoRandom().Next(); foreach (var usr in allUsrsArray) { - await (await usr.CreateDMChannelAsync()).SendConfirmAsync(str).ConfigureAwait(false); + await (await usr.GetOrCreateDMChannelAsync()).SendConfirmAsync(str).ConfigureAwait(false); } } diff --git a/src/NadekoBot/NadekoBot.csproj b/src/NadekoBot/NadekoBot.csproj index 18ad4911..d5d72b38 100644 --- a/src/NadekoBot/NadekoBot.csproj +++ b/src/NadekoBot/NadekoBot.csproj @@ -55,7 +55,7 @@ - + diff --git a/src/NadekoBot/Services/Administration/SelfService.cs b/src/NadekoBot/Services/Administration/SelfService.cs index 2a12ffca..4134393b 100644 --- a/src/NadekoBot/Services/Administration/SelfService.cs +++ b/src/NadekoBot/Services/Administration/SelfService.cs @@ -84,7 +84,7 @@ namespace NadekoBot.Services.Administration { if (hs.Remove(u.Id)) { - channels.Add(u.Id, new AsyncLazy(async () => await u.CreateDMChannelAsync())); + channels.Add(u.Id, new AsyncLazy(async () => await u.GetOrCreateDMChannelAsync())); if (hs.Count == 0) break; } diff --git a/src/NadekoBot/Services/CommandHandler.cs b/src/NadekoBot/Services/CommandHandler.cs index a1de8871..58acff4d 100644 --- a/src/NadekoBot/Services/CommandHandler.cs +++ b/src/NadekoBot/Services/CommandHandler.cs @@ -355,7 +355,7 @@ namespace NadekoBot.Services } } - var execResult = await commands[i].ExecuteAsync(context, parseResult, serviceProvider); + var execResult = (ExecuteResult)(await commands[i].ExecuteAsync(context, parseResult, serviceProvider)); if (execResult.Exception != null && (!(execResult.Exception is HttpException he) || he.DiscordCode != 50013)) { lock (errorLogLock) diff --git a/src/NadekoBot/Services/CustomReactions/Extensions.cs b/src/NadekoBot/Services/CustomReactions/Extensions.cs index af968192..351ac6d2 100644 --- a/src/NadekoBot/Services/CustomReactions/Extensions.cs +++ b/src/NadekoBot/Services/CustomReactions/Extensions.cs @@ -81,7 +81,7 @@ namespace NadekoBot.Services.CustomReactions public static async Task Send(this CustomReaction cr, IUserMessage ctx, DiscordSocketClient client, CustomReactionsService crs) { - var channel = cr.DmResponse ? await ctx.Author.CreateDMChannelAsync() : ctx.Channel; + var channel = cr.DmResponse ? await ctx.Author.GetOrCreateDMChannelAsync() : ctx.Channel; crs.ReactionStats.AddOrUpdate(cr.Trigger, 1, (k, old) => ++old); diff --git a/src/NadekoBot/Services/GreetSettingsService.cs b/src/NadekoBot/Services/GreetSettingsService.cs index b38ac5bd..7e4aaee6 100644 --- a/src/NadekoBot/Services/GreetSettingsService.cs +++ b/src/NadekoBot/Services/GreetSettingsService.cs @@ -139,7 +139,7 @@ namespace NadekoBot.Services if (conf.SendDmGreetMessage) { - var channel = await user.CreateDMChannelAsync(); + var channel = await user.GetOrCreateDMChannelAsync(); if (channel != null) { diff --git a/src/NadekoBot/Services/Impl/StatsService.cs b/src/NadekoBot/Services/Impl/StatsService.cs index ed7ec815..60d4a1e2 100644 --- a/src/NadekoBot/Services/Impl/StatsService.cs +++ b/src/NadekoBot/Services/Impl/StatsService.cs @@ -17,7 +17,7 @@ namespace NadekoBot.Services.Impl private readonly IBotCredentials _creds; private readonly DateTime _started; - public const string BotVersion = "1.53"; + public const string BotVersion = "1.54"; public string Author => "Kwoth#2560"; public string Library => "Discord.Net"; diff --git a/src/NadekoBot/Services/Utility/RemindService.cs b/src/NadekoBot/Services/Utility/RemindService.cs index 592564c3..48f3f869 100644 --- a/src/NadekoBot/Services/Utility/RemindService.cs +++ b/src/NadekoBot/Services/Utility/RemindService.cs @@ -67,7 +67,7 @@ namespace NadekoBot.Services.Utility var user = _client.GetGuild(r.ServerId).GetUser(r.ChannelId); if (user == null) return; - ch = await user.CreateDMChannelAsync().ConfigureAwait(false); + ch = await user.GetOrCreateDMChannelAsync().ConfigureAwait(false); } else { diff --git a/src/NadekoBot/ShardsCoordinator.cs b/src/NadekoBot/ShardsCoordinator.cs index 1516f868..ad112cbf 100644 --- a/src/NadekoBot/ShardsCoordinator.cs +++ b/src/NadekoBot/ShardsCoordinator.cs @@ -22,7 +22,8 @@ namespace NadekoBot private readonly Logger _log; private readonly ShardComServer _comServer; private readonly int _port; - + private readonly int _curProcessId; + public ShardsCoordinator(int port) { LogSetup.SetupLogger(); @@ -36,6 +37,8 @@ namespace NadekoBot _comServer.Start(); _comServer.OnDataReceived += _comServer_OnDataReceived; + + _curProcessId = Process.GetCurrentProcess().Id; } private Task _comServer_OnDataReceived(ShardComMessage msg) @@ -49,13 +52,12 @@ namespace NadekoBot public async Task RunAsync() { - var curProcessId = Process.GetCurrentProcess().Id; for (int i = 1; i < Credentials.TotalShards; i++) { var p = Process.Start(new ProcessStartInfo() { FileName = Credentials.ShardRunCommand, - Arguments = string.Format(Credentials.ShardRunArguments, i, curProcessId, _port) + Arguments = string.Format(Credentials.ShardRunArguments, i, _curProcessId, _port) }); await Task.Delay(5000); } diff --git a/src/NadekoBot/_Extensions/Extensions.cs b/src/NadekoBot/_Extensions/Extensions.cs index 8488071b..880e9fbe 100644 --- a/src/NadekoBot/_Extensions/Extensions.cs +++ b/src/NadekoBot/_Extensions/Extensions.cs @@ -186,7 +186,7 @@ namespace NadekoBot.Extensions public static async Task SendMessageToOwnerAsync(this IGuild guild, string message) { - var ownerPrivate = await (await guild.GetOwnerAsync().ConfigureAwait(false)).CreateDMChannelAsync() + var ownerPrivate = await (await guild.GetOwnerAsync().ConfigureAwait(false)).GetOrCreateDMChannelAsync() .ConfigureAwait(false); return await ownerPrivate.SendMessageAsync(message).ConfigureAwait(false); @@ -230,28 +230,28 @@ namespace NadekoBot.Extensions public static double UnixTimestamp(this DateTime dt) => dt.ToUniversalTime().Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds; - public static async Task SendMessageAsync(this IUser user, string message, bool isTTS = false) => - await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync(message, isTTS).ConfigureAwait(false); + //public static async Task SendMessageAsync(this IUser user, string message, bool isTTS = false) => + // await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync(message, isTTS).ConfigureAwait(false); public static async Task SendConfirmAsync(this IUser user, string text) - => await (await user.CreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithOkColor().WithDescription(text)); + => await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithOkColor().WithDescription(text)); public static async Task SendConfirmAsync(this IUser user, string title, string text, string url = null) - => await (await user.CreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithOkColor().WithDescription(text) + => await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithOkColor().WithDescription(text) .WithTitle(title).WithUrl(url)); public static async Task SendErrorAsync(this IUser user, string title, string error, string url = null) - => await (await user.CreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithErrorColor().WithDescription(error) + => await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithErrorColor().WithDescription(error) .WithTitle(title).WithUrl(url)); public static async Task SendErrorAsync(this IUser user, string error) - => await (await user.CreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithErrorColor().WithDescription(error)); + => await (await user.GetOrCreateDMChannelAsync()).SendMessageAsync("", embed: new EmbedBuilder().WithErrorColor().WithDescription(error)); public static async Task SendFileAsync(this IUser user, string filePath, string caption = null, string text = null, bool isTTS = false) => - await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(File.Open(filePath, FileMode.Open), caption ?? "x", text, isTTS).ConfigureAwait(false); + await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(File.Open(filePath, FileMode.Open), caption ?? "x", text, isTTS).ConfigureAwait(false); public static async Task SendFileAsync(this IUser user, Stream fileStream, string fileName, string caption = null, bool isTTS = false) => - await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(fileStream, fileName, caption, isTTS).ConfigureAwait(false); + await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(fileStream, fileName, caption, isTTS).ConfigureAwait(false); public static IEnumerable Members(this IRole role) => role.Guild.GetUsersAsync().GetAwaiter().GetResult().Where(u => u.RoleIds.Contains(role.Id)) ?? Enumerable.Empty();