Disable Discord member caching entirely

This commit is contained in:
Ske 2020-02-01 15:00:36 +01:00
parent 82dfe43d5a
commit 6863da9462
5 changed files with 18 additions and 19 deletions

View File

@ -230,6 +230,8 @@ namespace PluralKit.Bot.CommandSystem
public GuildPermissions GetGuildPermissions(IUser user)
{
if (user is IGuildUser gu)
return gu.GuildPermissions;
if (Channel is SocketGuildChannel gc)
return gc.GetUser(user.Id).GuildPermissions;
return GuildPermissions.None;
@ -237,6 +239,8 @@ namespace PluralKit.Bot.CommandSystem
public ChannelPermissions GetChannelPermissions(IUser user)
{
if (user is IGuildUser gu && Channel is IGuildChannel igc)
return gu.GetPermissions(igc);
if (Channel is SocketGuildChannel gc)
return gc.GetUser(user.Id).GetPermissions(gc);
return ChannelPermissions.DM;

View File

@ -1,7 +1,7 @@
using System.Linq;
using System.Threading.Tasks;
using Discord;
using Discord.WebSocket;
using PluralKit.Bot.CommandSystem;
@ -73,9 +73,9 @@ namespace PluralKit.Bot.Commands
public static Command[] LogCommands = {LogChannel, LogEnable, LogDisable};
private IDiscordClient _client;
private DiscordShardedClient _client;
public CommandTree(IDiscordClient client)
public CommandTree(DiscordShardedClient client)
{
_client = client;
}
@ -335,7 +335,7 @@ namespace PluralKit.Bot.Commands
{
// Try to resolve the user ID to find the associated account,
// so we can print their username.
var user = await _client.GetUserAsync(id);
var user = await _client.Rest.GetUserAsync(id);
// Print descriptive errors based on whether we found the user or not.
if (user == null)

View File

@ -27,6 +27,7 @@ namespace PluralKit.Bot
ConnectionTimeout = 2 * 60 * 1000,
ExclusiveBulkDelete = true,
LargeThreshold = 50,
GuildSubscriptions = false,
DefaultRetryMode = RetryMode.RetryTimeouts | RetryMode.RetryRatelimit
// Commented this out since Debug actually sends, uh, quite a lot that's not necessary in production
// but leaving it here in case I (or someone else) get[s] confused about why logging isn't working again :p

View File

@ -12,9 +12,9 @@ namespace PluralKit.Bot {
public class EmbedService
{
private IDataStore _data;
private IDiscordClient _client;
private DiscordShardedClient _client;
public EmbedService(IDiscordClient client, IDataStore data)
public EmbedService(DiscordShardedClient client, IDataStore data)
{
_client = client;
_data = data;
@ -24,7 +24,7 @@ namespace PluralKit.Bot {
var accounts = await _data.GetSystemAccounts(system);
// Fetch/render info for all accounts simultaneously
var users = await Task.WhenAll(accounts.Select(async uid => (await _client.GetUserAsync(uid))?.NameAndMention() ?? $"(deleted account {uid})"));
var users = await Task.WhenAll(accounts.Select(async uid => (await _client.Rest.GetUserAsync(uid))?.NameAndMention() ?? $"(deleted account {uid})"));
var memberCount = await _data.GetSystemMemberCount(system, false);
var eb = new EmbedBuilder()
@ -126,7 +126,7 @@ namespace PluralKit.Bot {
public async Task<Embed> CreateMessageInfoEmbed(FullMessage msg)
{
var channel = await _client.GetChannelAsync(msg.Message.Channel) as ITextChannel;
var channel = _client.GetChannel(msg.Message.Channel) as ITextChannel;
var serverMsg = channel != null ? await channel.GetMessageAsync(msg.Message.Mid) : null;
var memberStr = $"{msg.Member.Name} (`{msg.Member.Hid}`)";
@ -139,7 +139,7 @@ namespace PluralKit.Bot {
// Look up the user with the REST client
// this ensures we'll still get the information even if the user's not cached,
// even if this means an extra API request (meh, it'll be fine)
var shard = ((DiscordShardedClient) _client).GetShardFor(channel.Guild);
var shard = _client.GetShardFor(channel.Guild);
var guildUser = await shard.Rest.GetGuildUserAsync(channel.Guild.Id, msg.Message.Sender);
if (guildUser != null)
{

View File

@ -3,8 +3,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Dapper;
using Discord;
using Discord.Net;
using Discord.WebSocket;
@ -26,24 +24,20 @@ namespace PluralKit.Bot
}
class ProxyService {
private IDiscordClient _client;
private DiscordShardedClient _client;
private LogChannelService _logChannel;
private IDataStore _data;
private DbConnectionFactory _conn;
private EmbedService _embeds;
private ILogger _logger;
private WebhookExecutorService _webhookExecutor;
private ProxyCache _cache;
public ProxyService(IDiscordClient client, LogChannelService logChannel, IDataStore data, EmbedService embeds, ILogger logger, WebhookExecutorService webhookExecutor, DbConnectionFactory conn, ProxyCache cache)
public ProxyService(DiscordShardedClient client, LogChannelService logChannel, IDataStore data, EmbedService embeds, ILogger logger, WebhookExecutorService webhookExecutor)
{
_client = client;
_logChannel = logChannel;
_data = data;
_embeds = embeds;
_webhookExecutor = webhookExecutor;
_conn = conn;
_cache = cache;
_logger = logger.ForContext<ProxyService>();
}
@ -284,7 +278,7 @@ namespace PluralKit.Bot
await channel.SendMessageAsync($"Psst, **{msg.Member.DisplayName ?? msg.Member.Name}** (<@{msg.Message.Sender}>), you have been pinged by <@{userWhoReacted}>.", embed: embed.Build());
// Finally remove the original reaction (if we can)
var user = await _client.GetUserAsync(userWhoReacted);
var user = await _client.Rest.GetUserAsync(userWhoReacted);
if (user != null && await realMessage.Channel.HasPermission(ChannelPermission.ManageMessages))
await realMessage.RemoveReactionAsync(reactedEmote, user);
}
@ -292,7 +286,7 @@ namespace PluralKit.Bot
private async Task HandleMessageQueryByReaction(Cacheable<IUserMessage, ulong> message, ulong userWhoReacted, IEmote reactedEmote)
{
// Find the user who sent the reaction, so we can DM them
var user = await _client.GetUserAsync(userWhoReacted);
var user = await _client.Rest.GetUserAsync(userWhoReacted);
if (user == null) return;
// Find the message in the DB