Upgraded dicord.net

This commit is contained in:
Master Kwoth 2017-07-05 17:38:38 +02:00
parent 8f844d38d3
commit 269a4e3157
19 changed files with 38 additions and 32 deletions

View File

@ -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<TypeReaderResult> Read(ICommandContext context, string input)
public override Task<TypeReaderResult> 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<TypeReaderResult> Read(ICommandContext context, string input)
public override async Task<TypeReaderResult> 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));

View File

@ -14,7 +14,7 @@ namespace NadekoBot.TypeReaders
_gts = gts;
}
public override Task<TypeReaderResult> Read(ICommandContext context, string input)
public override Task<TypeReaderResult> 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."));

View File

@ -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<TypeReaderResult> Read(ICommandContext context, string input)
public override Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider _)
{
input = input.Trim().ToLowerInvariant();
var guilds = _client.Guilds;

View File

@ -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<TypeReaderResult> Read(ICommandContext context, string input)
public override Task<TypeReaderResult> 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<TypeReaderResult> Read(ICommandContext context, string input)
public override Task<TypeReaderResult> 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;

View File

@ -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
/// </summary>
public class PermissionActionTypeReader : TypeReader
{
public override Task<TypeReaderResult> Read(ICommandContext context, string input)
public override Task<TypeReaderResult> Read(ICommandContext context, string input, IServiceProvider _)
{
input = input.ToUpperInvariant();
switch (input)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -55,7 +55,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="AngleSharp" Version="0.9.9" />
<PackageReference Include="Discord.Net" Version="1.0.0-rc3-00746" />
<PackageReference Include="Discord.Net" Version="1.0.1-build-00785" />
<PackageReference Include="libvideo" Version="1.0.1" />
<PackageReference Include="CoreCLR-NCalc" Version="2.1.2" />
<PackageReference Include="Google.Apis.Urlshortener.v1" Version="1.19.0.138" />

View File

@ -84,7 +84,7 @@ namespace NadekoBot.Services.Administration
{
if (hs.Remove(u.Id))
{
channels.Add(u.Id, new AsyncLazy<IDMChannel>(async () => await u.CreateDMChannelAsync()));
channels.Add(u.Id, new AsyncLazy<IDMChannel>(async () => await u.GetOrCreateDMChannelAsync()));
if (hs.Count == 0)
break;
}

View File

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

View File

@ -81,7 +81,7 @@ namespace NadekoBot.Services.CustomReactions
public static async Task<IUserMessage> 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);

View File

@ -139,7 +139,7 @@ namespace NadekoBot.Services
if (conf.SendDmGreetMessage)
{
var channel = await user.CreateDMChannelAsync();
var channel = await user.GetOrCreateDMChannelAsync();
if (channel != null)
{

View File

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

View File

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

View File

@ -22,6 +22,7 @@ namespace NadekoBot
private readonly Logger _log;
private readonly ShardComServer _comServer;
private readonly int _port;
private readonly int _curProcessId;
public ShardsCoordinator(int port)
{
@ -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);
}

View File

@ -186,7 +186,7 @@ namespace NadekoBot.Extensions
public static async Task<IMessage> 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<IUserMessage> SendMessageAsync(this IUser user, string message, bool isTTS = false) =>
await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync(message, isTTS).ConfigureAwait(false);
//public static async Task<IUserMessage> SendMessageAsync(this IUser user, string message, bool isTTS = false) =>
// await (await user.CreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync(message, isTTS).ConfigureAwait(false);
public static async Task<IUserMessage> 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<IUserMessage> 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<IUserMessage> 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<IUserMessage> 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<IUserMessage> 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<IUserMessage> 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<IUser> Members(this IRole role) =>
role.Guild.GetUsersAsync().GetAwaiter().GetResult().Where(u => u.RoleIds.Contains(role.Id)) ?? Enumerable.Empty<IUser>();