Switch to discord.net 3.0.0

This commit is contained in:
Kwoth
2021-12-23 08:02:23 +07:00
parent f78e4d457c
commit 93b8bca018
34 changed files with 159 additions and 384 deletions

View File

@@ -34,8 +34,8 @@ public partial class Administration : NadekoModule<AdministrationService>
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
[UserPerm(ChannelPerm.ManageChannel)]
[BotPerm(ChannelPerm.ManageChannel)]
[UserPerm(ChannelPerm.ManageChannels)]
[BotPerm(ChannelPerm.ManageChannels)]
public async Task Slowmode(StoopidTime time = null)
{
var seconds = (int?)time?.Time.TotalSeconds ?? 0;

View File

@@ -466,7 +466,7 @@ public partial class Administration
if (user is null)
return;
var ch = await user.GetOrCreateDMChannelAsync();
var ch = await user.CreateDMChannelAsync();
text = rep.Replace(text);
await ch.SendAsync(text);
}

View File

@@ -253,7 +253,7 @@ public partial class Administration
{
user = user ?? (IGuildUser) ctx.User;
var channel = await user.GetOrCreateDMChannelAsync();
var channel = await user.CreateDMChannelAsync();
var success = await _service.GreetDmTest(channel, user);
if (success)
await ctx.OkAsync();

View File

@@ -4,6 +4,7 @@ using NadekoBot.Db;
namespace NadekoBot.Modules.Administration.Services;
// todo if any activity...
public class GameVoiceChannelService : INService
{
public ConcurrentHashSet<ulong> GameVoiceChannels { get; } = new ConcurrentHashSet<ulong>();
@@ -24,7 +25,7 @@ public class GameVoiceChannelService : INService
_client.GuildMemberUpdated += _client_GuildMemberUpdated;
}
private Task _client_GuildMemberUpdated(SocketGuildUser before, SocketGuildUser after)
private Task _client_GuildMemberUpdated(Cacheable<SocketGuildUser, ulong> before, SocketGuildUser after)
{
var _ = Task.Run(async () =>
{
@@ -32,15 +33,16 @@ public class GameVoiceChannelService : INService
{
//if the user is in the voice channel and that voice channel is gvc
var vc = after.VoiceChannel;
if (vc is null || !GameVoiceChannels.Contains(vc.Id))
if (vc is null || !GameVoiceChannels.Contains(vc.Id) || !before.HasValue)
return;
//if the activity has changed, and is a playing activity
if (before.Activity != after.Activity
&& after.Activity is { Type: Discord.ActivityType.Playing })
var oldActivity = before.Value.Activities.FirstOrDefault();
var newActivity = after.Activities.FirstOrDefault();
if (oldActivity != newActivity && newActivity is { Type: ActivityType.Playing })
{
//trigger gvc
await TriggerGvc(after, after.Activity.Name);
await TriggerGvc(after, newActivity.Name);
}
}
@@ -86,7 +88,7 @@ public class GameVoiceChannelService : INService
if (!(usr is SocketGuildUser gUser))
return;
var game = gUser.Activity?.Name;
var game = gUser.Activities.FirstOrDefault()?.Name;
if (oldState.VoiceChannel == newState.VoiceChannel ||
newState.VoiceChannel is null)

View File

@@ -567,12 +567,17 @@ public sealed class LogCommandService : ILogCommandService
return isDeleted;
}
private Task _client_GuildUserUpdated(SocketGuildUser before, SocketGuildUser after)
private Task _client_GuildUserUpdated(Cacheable<SocketGuildUser, ulong> optBefore, SocketGuildUser after)
{
var _ = Task.Run(async () =>
{
try
{
var before = await optBefore.GetOrDownloadAsync();
if (before is null)
return;
if (!GuildLogSettings.TryGetValue(before.Guild.Id, out var logSetting)
|| logSetting.LogIgnores.Any(ilc => ilc.LogItemId == after.Id && ilc.ItemType == IgnoredItemType.User))
return;
@@ -642,10 +647,10 @@ public sealed class LogCommandService : ILogCommandService
return list;
});
}
else if (before.Activity?.Name != after.Activity?.Name)
else if (before.Activities.FirstOrDefault()?.Name != after.Activities.FirstOrDefault()?.Name)
{
var str =
$"👾`{PrettyCurrentTime(after.Guild)}`👤__**{after.Username}**__ is now playing **{after.Activity?.Name ?? "-"}**.";
$"👾`{PrettyCurrentTime(after.Guild)}`👤__**{after.Username}**__ is now playing **{after.Activities.FirstOrDefault()?.Name ?? "-"}**.";
PresenceUpdates.AddOrUpdate(logChannel,
new List<string>() {str}, (id, list) =>
{
@@ -857,19 +862,19 @@ public sealed class LogCommandService : ILogCommandService
return Task.CompletedTask;
}
private Task _client_UserLeft(IGuildUser usr)
private Task _client_UserLeft(SocketGuild guild, SocketUser usr)
{
var _ = Task.Run(async () =>
{
try
{
if (!GuildLogSettings.TryGetValue(usr.Guild.Id, out var logSetting)
if (!GuildLogSettings.TryGetValue(guild.Id, out var logSetting)
|| logSetting.UserLeftId is null
|| logSetting.LogIgnores.Any(ilc => ilc.LogItemId == usr.Id && ilc.ItemType == IgnoredItemType.User))
return;
ITextChannel logChannel;
if ((logChannel = await TryGetLogChannel(usr.Guild, logSetting, LogType.UserLeft)
if ((logChannel = await TryGetLogChannel(guild, logSetting, LogType.UserLeft)
.ConfigureAwait(false)) is null)
return;
var embed = _eb.Create()
@@ -877,7 +882,7 @@ public sealed class LogCommandService : ILogCommandService
.WithTitle("❌ " + GetText(logChannel.Guild, strs.user_left))
.WithDescription(usr.ToString())
.AddField("Id", usr.Id.ToString())
.WithFooter(CurrentTime(usr.Guild));
.WithFooter(CurrentTime(guild));
if (Uri.IsWellFormedUriString(usr.GetAvatarUrl(), UriKind.Absolute))
embed.WithThumbnailUrl(usr.GetAvatarUrl());
@@ -1006,19 +1011,20 @@ public sealed class LogCommandService : ILogCommandService
return Task.CompletedTask;
}
private Task _client_MessageDeleted(Cacheable<IMessage, ulong> optMsg, ISocketMessageChannel ch)
private Task _client_MessageDeleted(Cacheable<IMessage, ulong> optMsg, Cacheable<IMessageChannel, ulong> optCh)
{
var _ = Task.Run(async () =>
{
try
{
var msg = (optMsg.HasValue ? optMsg.Value : null) as IUserMessage;
var msg = optMsg.Value as IUserMessage;
if (msg is null || msg.IsAuthor(_client))
return;
if (_ignoreMessageIds.Contains(msg.Id))
return;
var ch = optCh.Value;
if (!(ch is ITextChannel channel))
return;

View File

@@ -34,14 +34,16 @@ public class RoleCommandsService : INService
#endif
}
private Task _client_ReactionAdded(Cacheable<IUserMessage, ulong> msg, ISocketMessageChannel chan, SocketReaction reaction)
private Task _client_ReactionAdded(Cacheable<IUserMessage, ulong> msg,
Cacheable<IMessageChannel, ulong> chan,
SocketReaction reaction)
{
_ = Task.Run(async () =>
{
if (!reaction.User.IsSpecified ||
reaction.User.Value.IsBot ||
reaction.User.Value is not SocketGuildUser gusr ||
chan is not SocketGuildChannel gch ||
chan.Value is not SocketGuildChannel gch ||
!_models.TryGetValue(gch.Guild.Id, out var confs))
return;
@@ -93,7 +95,9 @@ public class RoleCommandsService : INService
return Task.CompletedTask;
}
private Task _client_ReactionRemoved(Cacheable<IUserMessage, ulong> msg, ISocketMessageChannel chan, SocketReaction reaction)
private Task _client_ReactionRemoved(Cacheable<IUserMessage, ulong> msg,
Cacheable<IMessageChannel, ulong> chan,
SocketReaction reaction)
{
_ = Task.Run(async () =>
{
@@ -104,7 +108,7 @@ public class RoleCommandsService : INService
reaction.User.Value is not SocketGuildUser gusr)
return;
if (chan is not SocketGuildChannel gch)
if (chan.Value is not SocketGuildChannel gch)
return;
if (!_models.TryGetValue(gch.Guild.Id, out var confs))

View File

@@ -203,7 +203,7 @@ public sealed class SelfService : ILateExecutor, IReadyExecutor, INService
if (user is null)
return Task.FromResult<IDMChannel>(null);
return user.GetOrCreateDMChannelAsync();
return user.CreateDMChannelAsync();
})).ConfigureAwait(false);
ownerChannels = channels.Where(x => x != null)

View File

@@ -61,7 +61,7 @@ public partial class Administration
var dmFailed = false;
try
{
await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).EmbedAsync(_eb.Create().WithErrorColor()
await user.EmbedAsync(_eb.Create().WithErrorColor()
.WithDescription(GetText(strs.warned_on(ctx.Guild.ToString())))
.AddField(GetText(strs.moderator), ctx.User.ToString())
.AddField(GetText(strs.reason), reason ?? "-"))
@@ -449,8 +449,7 @@ public partial class Administration
var embed = _service.GetBanUserDmEmbed(Context, guildUser, defaultMessage, msg, time.Time);
if (embed is not null)
{
var userChannel = await guildUser.GetOrCreateDMChannelAsync();
await userChannel.SendAsync(embed);
await guildUser.SendAsync(embed);
}
}
catch
@@ -520,8 +519,7 @@ public partial class Administration
var embed = _service.GetBanUserDmEmbed(Context, user, defaultMessage, msg, null);
if (embed is not null)
{
var userChannel = await user.GetOrCreateDMChannelAsync();
await userChannel.SendAsync(embed);
await ctx.User.SendAsync(embed);
}
}
catch
@@ -596,7 +594,6 @@ public partial class Administration
private async Task InternalBanMessageTest(string reason, TimeSpan? duration)
{
var dmChannel = await ctx.User.GetOrCreateDMChannelAsync();
var defaultMessage = GetText(strs.bandm(Format.Bold(ctx.Guild.Name), reason));
var embed = _service.GetBanUserDmEmbed(Context,
(IGuildUser)ctx.User,
@@ -612,7 +609,7 @@ public partial class Administration
{
try
{
await dmChannel.SendAsync(embed);
await ctx.User.SendAsync(embed);
}
catch (Exception)
{

View File

@@ -13,7 +13,7 @@ public static class CustomReactionExtensions
DiscordSocketClient client, bool sanitize)
{
var channel = cr.DmResponse
? await ctx.Author.GetOrCreateDMChannelAsync().ConfigureAwait(false)
? await ctx.Author.CreateDMChannelAsync().ConfigureAwait(false)
: ctx.Channel;
var trigger = cr.Trigger.ResolveTriggerString(client);

View File

@@ -120,7 +120,7 @@ public class GameStatusEvent : ICurrencyEvent
return _embedFunc(CurrencyEvent.Type.GameStatus, _opts, pot);
}
private async Task OnMessageDeleted(Cacheable<IMessage, ulong> msg, ISocketMessageChannel _)
private async Task OnMessageDeleted(Cacheable<IMessage, ulong> msg, Cacheable<IMessageChannel, ulong> cacheable)
{
if (msg.Id == _msg.Id)
{

View File

@@ -123,7 +123,7 @@ public class ReactionEvent : ICurrencyEvent
return _embedFunc(CurrencyEvent.Type.Reaction, _opts, pot);
}
private async Task OnMessageDeleted(Cacheable<IMessage, ulong> msg, ISocketMessageChannel _)
private async Task OnMessageDeleted(Cacheable<IMessage, ulong> msg, Cacheable<IMessageChannel, ulong> cacheable)
{
if (msg.Id == _msg.Id)
{
@@ -150,7 +150,7 @@ public class ReactionEvent : ICurrencyEvent
}
private Task HandleReaction(Cacheable<IUserMessage, ulong> msg,
ISocketMessageChannel ch, SocketReaction r)
Cacheable<IMessageChannel, ulong> cacheable, SocketReaction r)
{
var _ = Task.Run(() =>
{

View File

@@ -160,7 +160,7 @@ public partial class Gambling
}
try
{
await (await ctx.User.GetOrCreateDMChannelAsync().ConfigureAwait(false))
await ctx.User
.EmbedAsync(_eb.Create().WithOkColor()
.WithTitle(GetText(strs.shop_purchase(ctx.Guild.Name)))
.AddField(GetText(strs.item), item.Text, false)

View File

@@ -274,7 +274,7 @@ public class Help : NadekoModule<HelpService>
if (com is null)
{
var ch = channel is ITextChannel
? await ((IGuildUser)ctx.User).GetOrCreateDMChannelAsync().ConfigureAwait(false)
? await ctx.User.CreateDMChannelAsync().ConfigureAwait(false)
: channel;
try
{

View File

@@ -132,9 +132,9 @@ public class HelpService : ILateExecutor, INService
var userPermString = string.Empty;
if (userPerm is not null)
{
if (userPerm.UserPermissionAttribute.ChannelPermission is { } cPerm)
if (userPerm.ChannelPermission is { } cPerm)
userPermString = GetPreconditionString((ChannelPerm) cPerm);
if (userPerm.UserPermissionAttribute.GuildPermission is { } gPerm)
if (userPerm.GuildPermission is { } gPerm)
userPermString = GetPreconditionString((GuildPerm) gPerm);
}

View File

@@ -25,7 +25,9 @@ public sealed class AyuVoiceStateService : INService
.GetProperties(BindingFlags.NonPublic | BindingFlags.Instance)
.First(x => x.Name == "ApiClient" && x.PropertyType.Name == "DiscordSocketApiClient");
_dnetApiClient = prop.GetValue(_client, null);
_sendVoiceStateUpdateMethodInfo = _dnetApiClient.GetType().GetMethod("SendVoiceStateUpdateAsync");
_sendVoiceStateUpdateMethodInfo = _dnetApiClient.GetType()
.GetMethod("SendVoiceStateUpdateAsync",
types: new[] { typeof(ulong), typeof(ulong?), typeof(bool), typeof(bool), typeof(RequestOptions) });
_client.LeftGuild += ClientOnLeftGuild;
}

View File

@@ -27,8 +27,8 @@ public partial class Utility
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
[BotPerm(ChannelPerm.ManageChannel)]
[UserPerm(ChannelPerm.ManageChannel)]
[BotPerm(ChannelPerm.ManageChannels)]
[UserPerm(ChannelPerm.ManageChannels)]
public async Task InviteList(int page = 1, [Leftover]ITextChannel ch = null)
{
if (--page < 0)
@@ -76,8 +76,8 @@ public partial class Utility
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
[BotPerm(ChannelPerm.ManageChannel)]
[UserPerm(ChannelPerm.ManageChannel)]
[BotPerm(ChannelPerm.ManageChannels)]
[UserPerm(ChannelPerm.ManageChannels)]
public async Task InviteDelete(int index)
{
if (--index < 0)

View File

@@ -298,8 +298,7 @@ public class PatreonRewardsService : INService
if (user is null)
return;
var channel = await user.GetOrCreateDMChannelAsync();
await channel.SendConfirmAsync(_eb, message);
await user.SendConfirmAsync(_eb, message);
}
catch
{

View File

@@ -152,7 +152,7 @@ public class RemindService : INService
var user = _client.GetUser(r.ChannelId);
if (user is null)
return;
ch = await user.GetOrCreateDMChannelAsync().ConfigureAwait(false);
ch = await user.CreateDMChannelAsync();
}
else
{

View File

@@ -38,7 +38,7 @@ public class StreamRoleService : INService
});
}
private Task Client_GuildMemberUpdated(SocketGuildUser before, SocketGuildUser after)
private Task Client_GuildMemberUpdated(Cacheable<SocketGuildUser, ulong> cacheable, SocketGuildUser after)
{
var _ = Task.Run(async () =>
{

View File

@@ -66,7 +66,7 @@ public partial class Utility : NadekoModule
}
var rng = new NadekoRandom();
var arr = await Task.Run(() => socketGuild.Users
.Where(u => u.Activity?.Name?.ToUpperInvariant() == game)
.Where(u => u.Activities.FirstOrDefault()?.Name?.ToUpperInvariant() == game)
.Select(u => u.Username)
.OrderBy(x => rng.Next())
.Take(60)
@@ -277,24 +277,24 @@ public partial class Utility : NadekoModule
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
[BotPerm(GuildPerm.ManageEmojis)]
[UserPerm(GuildPerm.ManageEmojis)]
[BotPerm(GuildPerm.ManageEmojisAndStickers)]
[UserPerm(GuildPerm.ManageEmojisAndStickers)]
[Priority(2)]
public Task EmojiAdd(string name, Emote emote)
=> EmojiAdd(name, emote.Url);
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
[BotPerm(GuildPerm.ManageEmojis)]
[UserPerm(GuildPerm.ManageEmojis)]
[BotPerm(GuildPerm.ManageEmojisAndStickers)]
[UserPerm(GuildPerm.ManageEmojisAndStickers)]
[Priority(1)]
public Task EmojiAdd(Emote emote)
=> EmojiAdd(emote.Name, emote.Url);
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
[BotPerm(GuildPerm.ManageEmojis)]
[UserPerm(GuildPerm.ManageEmojis)]
[BotPerm(GuildPerm.ManageEmojisAndStickers)]
[UserPerm(GuildPerm.ManageEmojisAndStickers)]
[Priority(0)]
public async Task EmojiAdd(string name, string url = null)
{

View File

@@ -250,9 +250,7 @@ public class XpService : INService
{
if (x.NotifyType == XpNotificationLocation.Dm)
{
var chan = await x.User.GetOrCreateDMChannelAsync();
if (chan != null)
await chan.SendConfirmAsync(_eb,
await x.User.SendConfirmAsync(_eb,
_strings.GetText(strs.level_up_dm(
x.User.Mention, Format.Bold(x.Level.ToString()),
Format.Bold(x.Guild.ToString() ?? "-")),
@@ -272,7 +270,7 @@ public class XpService : INService
IMessageChannel chan;
if (x.NotifyType == XpNotificationLocation.Dm)
{
chan = await x.User.GetOrCreateDMChannelAsync();
chan = await x.User.CreateDMChannelAsync();
}
else // channel
{