mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-12 02:08:27 -04:00
Switch to discord.net 3.0.0
This commit is contained in:
@@ -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)
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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))
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user