public static ValueTask HandleGatewayEvent(this IDiscordCache cache, IGatewayEvent evt) { switch (evt) { case GuildCreateEvent gc: return(cache.SaveGuildCreate(gc)); case GuildUpdateEvent gu: return(cache.SaveGuild(gu)); case GuildDeleteEvent gd: return(cache.RemoveGuild(gd.Id)); case ChannelCreateEvent cc: return(cache.SaveChannel(cc)); case ChannelUpdateEvent cu: return(cache.SaveChannel(cu)); case ChannelDeleteEvent cd: return(cache.RemoveChannel(cd.Id)); case GuildRoleCreateEvent grc: return(cache.SaveRole(grc.GuildId, grc.Role)); case GuildRoleUpdateEvent gru: return(cache.SaveRole(gru.GuildId, gru.Role)); case GuildRoleDeleteEvent grd: return(cache.RemoveRole(grd.GuildId, grd.RoleId)); case MessageReactionAddEvent mra: return(cache.TrySaveDmChannelStub(mra.GuildId, mra.ChannelId)); case MessageCreateEvent mc: return(cache.SaveMessageCreate(mc)); case MessageUpdateEvent mu: return(cache.TrySaveDmChannelStub(mu.GuildId.Value, mu.ChannelId)); case MessageDeleteEvent md: return(cache.TrySaveDmChannelStub(md.GuildId, md.ChannelId)); case MessageDeleteBulkEvent md: return(cache.TrySaveDmChannelStub(md.GuildId, md.ChannelId)); case ThreadCreateEvent tc: return(cache.SaveChannel(tc)); case ThreadUpdateEvent tu: return(cache.SaveChannel(tu)); case ThreadDeleteEvent td: return(cache.RemoveChannel(td.Id)); case ThreadListSyncEvent tls: return(cache.SaveThreadListSync(tls)); } return(default);
public ServerConfig(LoggerCleanService cleanService, IDatabase db, ModelRepository repo, IDiscordCache cache) { _cleanService = cleanService; _db = db; _repo = repo; _cache = cache; }
public static async Task <PermissionSet> PermissionsFor(this IDiscordCache cache, ulong channelId, ulong userId, GuildMemberPartial?member, bool isWebhook = false) { if (!(await cache.TryGetChannel(channelId) is Channel channel)) { // todo: handle channel not found better return(PermissionSet.Dm); } if (channel.GuildId == null) { return(PermissionSet.Dm); } var rootChannel = await cache.GetRootChannel(channelId); var guild = await cache.GetGuild(channel.GuildId.Value); if (isWebhook) { return(EveryonePermissions(guild)); } return(PermissionsFor(guild, rootChannel, userId, member)); }
public EmbedService(IDatabase db, ModelRepository repo, IDiscordCache cache, DiscordApiClient rest) { _db = db; _repo = repo; _cache = cache; _rest = rest; }
public static Channel?GetChannelOrNull(this IDiscordCache cache, ulong channelId) { if (cache.TryGetChannel(channelId, out var channel)) { return(channel); } return(null); }
public static Channel GetChannel(this IDiscordCache cache, ulong channelId) { if (!cache.TryGetChannel(channelId, out var channel)) { throw new KeyNotFoundException($"Channel {channelId} not found in cache"); } return(channel); }
public static Guild GetGuild(this IDiscordCache cache, ulong guildId) { if (!cache.TryGetGuild(guildId, out var guild)) { throw new KeyNotFoundException($"Guild {guildId} not found in cache"); } return(guild); }
// todo: make sure everything uses the minimum amount of REST calls necessary public Checks(DiscordApiClient rest, IDiscordCache cache, BotConfig botConfig, ProxyService proxy, ProxyMatcher matcher) { _rest = rest; _cache = cache; _botConfig = botConfig; _proxy = proxy; _matcher = matcher; }
public static async Task <Guild> GetGuild(this IDiscordCache cache, ulong guildId) { if (!(await cache.TryGetGuild(guildId) is Guild guild)) { throw new KeyNotFoundException($"Guild {guildId} not found in cache"); } return(guild); }
public WebhookCacheService(ILogger logger, IMetrics metrics, DiscordApiClient rest, IDiscordCache cache) { _metrics = metrics; _rest = rest; _cache = cache; _logger = logger.ForContext <WebhookCacheService>(); _webhooks = new ConcurrentDictionary <ulong, Lazy <Task <Webhook> > >(); }
public static async Task <Role> GetRole(this IDiscordCache cache, ulong roleId) { if (!(await cache.TryGetRole(roleId) is Role role)) { throw new KeyNotFoundException($"Role {roleId} not found in cache"); } return(role); }
public static async Task <User> GetUser(this IDiscordCache cache, ulong userId) { if (!(await cache.TryGetUser(userId) is User user)) { throw new KeyNotFoundException($"User {userId} not found in cache"); } return(user); }
public static async Task <Channel> GetChannel(this IDiscordCache cache, ulong channelId) { if (!(await cache.TryGetChannel(channelId) is Channel channel)) { throw new KeyNotFoundException($"Channel {channelId} not found in cache"); } return(channel); }
public static Role GetRole(this IDiscordCache cache, ulong roleId) { if (!cache.TryGetRole(roleId, out var role)) { throw new KeyNotFoundException($"User {roleId} not found in cache"); } return(role); }
public static User GetUser(this IDiscordCache cache, ulong userId) { if (!cache.TryGetUser(userId, out var user)) { throw new KeyNotFoundException($"User {userId} not found in cache"); } return(user); }
public Misc(BotConfig botConfig, IMetrics metrics, CpuStatService cpu, ModelRepository repo, ShardInfoService shards, IDiscordCache cache) { _botConfig = botConfig; _metrics = metrics; _cpu = cpu; _repo = repo; _shards = shards; _cache = cache; }
public WebhookExecutorService(IMetrics metrics, WebhookCacheService webhookCache, ILogger logger, HttpClient client, IDiscordCache cache, DiscordApiClient rest) { _metrics = metrics; _webhookCache = webhookCache; _client = client; _cache = cache; _rest = rest; _logger = logger.ForContext <WebhookExecutorService>(); }
public PeriodicStatCollector(IMetrics metrics, ILogger logger, WebhookCacheService webhookCache, DbConnectionCountHolder countHolder, CpuStatService cpu, IDatabase db, IDiscordCache cache) { _metrics = metrics; _webhookCache = webhookCache; _countHolder = countHolder; _cpu = cpu; _db = db; _cache = cache; _logger = logger.ForContext <PeriodicStatCollector>(); }
public LogChannelService(EmbedService embed, ILogger logger, IDatabase db, ModelRepository repo, IDiscordCache cache, DiscordApiClient rest, Bot bot) { _embed = embed; _db = db; _repo = repo; _cache = cache; _rest = rest; _bot = bot; _logger = logger.ForContext <LogChannelService>(); }
public MessageEdited(LastMessageCacheService lastMessageCache, ProxyService proxy, IDatabase db, IMetrics metrics, ModelRepository repo, Cluster client, IDiscordCache cache, Bot bot) { _lastMessageCache = lastMessageCache; _proxy = proxy; _db = db; _metrics = metrics; _repo = repo; _client = client; _cache = cache; _bot = bot; }
public ReactionAdded(ILogger logger, IDatabase db, ModelRepository repo, CommandMessageService commandMessageService, IDiscordCache cache, Bot bot, DiscordApiClient rest, EmbedService embeds) { _db = db; _repo = repo; _commandMessageService = commandMessageService; _cache = cache; _bot = bot; _rest = rest; _embeds = embeds; _logger = logger.ForContext <ReactionAdded>(); }
public static async Task <Channel> GetRootChannel(this IDiscordCache cache, ulong channelOrThread) { var channel = await cache.GetChannel(channelOrThread); if (!channel.IsThread()) { return(channel); } var parent = await cache.GetChannel(channel.ParentId !.Value); return(parent); }
public MessageEdited(LastMessageCacheService lastMessageCache, ProxyService proxy, IDatabase db, IMetrics metrics, ModelRepository repo, Cluster client, IDiscordCache cache, Bot bot, DiscordApiClient rest, ILogger logger) { _lastMessageCache = lastMessageCache; _proxy = proxy; _db = db; _metrics = metrics; _repo = repo; _client = client; _cache = cache; _bot = bot; _rest = rest; _logger = logger.ForContext <MessageEdited>(); }
public static PermissionSet PermissionsFor(this IDiscordCache cache, ulong channelId, ulong userId, ICollection <ulong>?userRoles) { var channel = cache.GetChannel(channelId); if (channel.GuildId == null) { return(PermissionSet.Dm); } var guild = cache.GetGuild(channel.GuildId.Value); return(PermissionsFor(guild, channel, userId, userRoles)); }
public static async Task <Channel> GetOrCreateDmChannel(this IDiscordCache cache, DiscordApiClient rest, ulong recipientId) { if (cache.TryGetDmChannel(recipientId, out var cacheChannel)) { return(cacheChannel); } var restChannel = await rest.CreateDm(recipientId); await cache.SaveChannel(restChannel); return(restChannel); }
public ProxyService(LogChannelService logChannel, ILogger logger, WebhookExecutorService webhookExecutor, IDatabase db, ProxyMatcher matcher, IMetrics metrics, ModelRepository repo, IDiscordCache cache, DiscordApiClient rest) { _logChannel = logChannel; _webhookExecutor = webhookExecutor; _db = db; _matcher = matcher; _metrics = metrics; _repo = repo; _cache = cache; _rest = rest; _logger = logger.ForContext <ProxyService>(); }
public Misc(BotConfig botConfig, IMetrics metrics, CpuStatService cpu, ShardInfoService shards, EmbedService embeds, ModelRepository repo, IDatabase db, IDiscordCache cache, DiscordApiClient rest, Bot bot, Cluster cluster) { _botConfig = botConfig; _metrics = metrics; _cpu = cpu; _shards = shards; _embeds = embeds; _repo = repo; _db = db; _cache = cache; _rest = rest; _bot = bot; _cluster = cluster; }
public PeriodicStatCollector(IMetrics metrics, ILogger logger, WebhookCacheService webhookCache, DbConnectionCountHolder countHolder, CpuStatService cpu, ModelRepository repo, BotConfig botConfig, CoreConfig config, RedisService redis, IDiscordCache cache) { _metrics = metrics; _webhookCache = webhookCache; _countHolder = countHolder; _cpu = cpu; _repo = repo; _cache = cache; _botConfig = botConfig; _config = config; _redis = redis; _logger = logger.ForContext <PeriodicStatCollector>(); }
public static async ValueTask <Channel?> GetOrFetchChannel(this IDiscordCache cache, DiscordApiClient rest, ulong channelId) { if (cache.TryGetChannel(channelId, out var cacheChannel)) { return(cacheChannel); } var restChannel = await rest.GetChannel(channelId); if (restChannel != null) { await cache.SaveChannel(restChannel); } return(restChannel); }
public static async ValueTask <User?> GetOrFetchUser(this IDiscordCache cache, DiscordApiClient rest, ulong userId) { if (cache.TryGetUser(userId, out var cacheUser)) { return(cacheUser); } var restUser = await rest.GetUser(userId); if (restUser != null) { await cache.SaveUser(restUser); } return(restUser); }