public void OnReceivedEvent(IGatewayClient gatewayClient, Payload <JsonElement> payload, string json, JsonSerializerOptions serializerOptions) { _events.OnRaw(gatewayClient, json); switch (payload.Event) { case "MESSAGE_CREATE": _events.OnMessageCreate(gatewayClient, payload.Data.ToObject <Message>(serializerOptions)); break; case "MESSAGE_UPDATE": _events.OnMessageUpdate(gatewayClient, payload.Data.ToObject <Message>(serializerOptions)); break; case "MESSAGE_DELETE": _events.OnMessageDelete(gatewayClient, payload.Data.ToObject <Message>(serializerOptions)); break; case "GUILD_CREATE": _events.OnGuildCreate(gatewayClient, payload.Data.ToObject <Guild>(serializerOptions)); break; case "READY": _events.OnReady(gatewayClient, payload.Data.ToObject <Ready>(serializerOptions)); break; default: _logger.Log(LoggingLevel.Warning, $"Event not implemented {payload.Event}"); break; } }
protected CachedChannel(IGatewayClient client, ChannelJsonModel model) : base(client, model.Id) { Type = model.Type; Update(model); }
/// <summary> /// Instantiates a new shared user. /// </summary> /// <param name="client"></param> /// <param name="model"></param> public CachedSharedUser(IGatewayClient client, UserJsonModel model) : base(client, model) { _isBot = model.Bot.GetValueOrDefault(); Update(model); }
private async Task <Guid?> UpdateProduct(IGatewayClient client, Guid subscriptionId, Guid providerId, string folderPath, Product product, Guid productId) { using var logo = new FileStream(path: Path.Combine(folderPath, product.Logo), FileMode.Open); using var document = new FileStream(path: Path.Combine(folderPath, product.Documentation), FileMode.Open); var response = await client.UpdateProductAsync( subscriptionId : subscriptionId, productId : productId, name : product.Name, description : product.Description, providerId : providerId.ToString(), apiKeyRequired : product.ApiKeyRequired, providerApprovalRequired : product.ProviderApprovalRequired, productTerms : product.LegalTerms, visibility : product.Visibility, logo : logo, documentation : document, clientCredentialRequired : product.ClientCredentialRequired, openidConfigIssuer : product.OpenidConfigIssuer, openidConfigCustomUrl : product.OpenidConfigCustomUrl, applicationId : product.ApplicationId).ConfigureAwait(false); if (response != null) { this.publishResults.Add(new GatewayAutomationResult() { ResultCode = ResultCode.ProductUpdated, EntityId = response.Id }); return(response.Id); } return(null); }
public static CachedGuildChannel Create(IGatewayClient client, ChannelJsonModel model) { switch (model.Type) { case ChannelType.Text: case ChannelType.News: return(new CachedTextChannel(client, model)); case ChannelType.Voice: return(new CachedVoiceChannel(client, model)); case ChannelType.Category: return(new CachedCategoryChannel(client, model)); case ChannelType.Store: return(new CachedStoreChannel(client, model)); case ChannelType.NewsThread: case ChannelType.PublicThread: case ChannelType.PrivateThread: return(new CachedThreadChannel(client, model)); case ChannelType.Stage: return(new CachedStageChannel(client, model)); } return(new CachedUnknownGuildChannel(client, model)); }
public CachedVoiceState(IGatewayClient client, Snowflake guildId, VoiceStateJsonModel model) : base(client, model.UserId) { GuildId = guildId; Update(model); }
public SensorApplicationService(ISensorClient sensorClient, IGatewayClient gatewayClient, IMapper mapper, INetworkLocationClient networkLocationClient) { _sensorClient = sensorClient; _gatewayClient = gatewayClient; _mapper = mapper; _networkLocationClient = networkLocationClient; }
public CachedGuild(IGatewayClient client, GatewayGuildJsonModel model) : base(client, model.Id) { ApplicationId = model.ApplicationId; Update(model); }
public CachedRole(IGatewayClient client, Snowflake guildId, RoleJsonModel model) : base(client, model.Id) { GuildId = guildId; Update(model); }
public CachedUserMessage(IGatewayClient client, CachedMember author, MessageJsonModel model) : base(client, author, model) { WebhookId = model.WebhookId.GetValueOrNullable(); IsTextToSpeech = model.Tts; Nonce = model.Nonce; }
public virtual async void OnMessageUpdate(IGatewayClient gatewayClient, Message message) { Channel guildChannel = await Channels.Find(message.ChannelId); Message messageOld = null; if (guildChannel is TextChannel textChannel) { messageOld = await textChannel.Messages.Find(message.Id); textChannel.UpdateMessage(ref message); message.Channel = textChannel; } else { Logger.Log(LoggingLevel.Warning, $"Fail cache message {message.Id}"); } MessageUpdate?.Invoke(this, new ClientArgs <MessageUpdate> { GatewayClient = gatewayClient, Data = new MessageUpdate { Message = message, OldMessage = messageOld } }); }
public DiscordClientSharder( IOptions <DiscordClientSharderConfiguration> options, ILogger <DiscordClientSharder> logger, IRestClient restClient, IGatewayClient gatewayClient, IEnumerable <DiscordClientExtension> extensions, IShardFactory shardFactory, IServiceProvider services) : base(logger, restClient, gatewayClient, extensions) { if (GatewayClient.Shards is not ISynchronizedDictionary <ShardId, IGatewayApiClient> ) { throw new InvalidOperationException("The gateway client instance is expected to return a synchronized dictionary of shards."); } if (GatewayClient.Dispatcher is not DefaultGatewayDispatcher dispatcher || dispatcher["READY"] is not ReadyHandler) { throw new InvalidOperationException("The gateway dispatcher must be the default implementation."); } var configuration = options.Value; _configuredShardCount = configuration.ShardCount; _configuredShardIds = configuration.ShardIds?.ToArray(); _shardFactory = shardFactory; _services = services; _initialReadyTcs = new Tcs(); }
public CachedStage(IGatewayClient client, StageInstanceJsonModel model) : base(client, model.Id) { GuildId = model.GuildId; ChannelId = model.ChannelId; Update(model); }
public CachedGuildEvent(IGatewayClient client, GuildScheduledEventJsonModel model) : base(client, model.Id) { GuildId = model.GuildId; CreatorId = model.CreatorId; Update(model); }
public CachedPresence(IGatewayClient client, PresenceJsonModel model) : base(client, model.User.Id) { GuildId = model.GuildId; MemberId = model.User.Id; Update(model); }
/// <summary> /// Instantiates a new shared user. /// </summary> /// <param name="client"></param> /// <param name="model"></param> public CachedSharedUser(IGatewayClient client, UserJsonModel model) : base(client, model) { _isBot = model.Bot.GetValueOrDefault(); _references = new SynchronizedHashSet <CachedUser>(); Update(model); }
public static CachedGuild GetGuild(this IGatewayClient client, Snowflake guildId) { if (client.CacheProvider.TryGetGuilds(out var cache)) { return(cache.GetValueOrDefault(guildId)); } return(null); }
public CachedEntity(IGatewayClient client) { if (client == null) { throw new ArgumentNullException(nameof(client)); } Client = client; }
public static CachedGuildEvent GetGuildEvent(this IGatewayClient client, Snowflake guildId, Snowflake eventId) { if (client.CacheProvider.TryGetGuildEvents(guildId, out var cache, true)) { return(cache.GetValueOrDefault(eventId)); } return(null); }
public GatewayExtractor( ILogger <GatewayExtractor> logger, ITemplateBuilder templateBuilder, IGatewayClient gatewayClient) { this.logger = logger; this.templateBuilder = templateBuilder; this.gatewayClient = gatewayClient; }
public CareContextDiscoveryController(IPatientDiscovery patientDiscovery, IGatewayClient gatewayClient, IBackgroundJobClient backgroundJob, ILogger <CareContextDiscoveryController> logger) { this.patientDiscovery = patientDiscovery; this.gatewayClient = gatewayClient; this.backgroundJob = backgroundJob; this.logger = logger; }
public static IReadOnlyDictionary <Snowflake, CachedUserMessage> GetMessages(this IGatewayClient client, Snowflake channelId) { if (client.CacheProvider.TryGetMessages(channelId, out var cache, true)) { return(cache.ReadOnly()); } return(ReadOnlyDictionary <Snowflake, CachedUserMessage> .Empty); }
public static CachedUserMessage GetMessage(this IGatewayClient client, Snowflake channelId, Snowflake messageId) { if (client.CacheProvider.TryGetMessages(channelId, out var cache, true)) { return(cache.GetValueOrDefault(messageId)); } return(null); }
public static IReadOnlyDictionary <Snowflake, CachedRole> GetRoles(this IGatewayClient client, Snowflake guildId) { if (client.CacheProvider.TryGetRoles(guildId, out var cache, true)) { return(cache.ReadOnly()); } return(ReadOnlyDictionary <Snowflake, CachedRole> .Empty); }
public static CachedVoiceState GetVoiceState(this IGatewayClient client, Snowflake guildId, Snowflake memberId) { if (client.CacheProvider.TryGetVoiceStates(guildId, out var cache, true)) { return(cache.GetValueOrDefault(memberId)); } return(null); }
public static CachedRole GetRole(this IGatewayClient client, Snowflake guildId, Snowflake roleId) { if (client.CacheProvider.TryGetRoles(guildId, out var cache, true)) { return(cache.GetValueOrDefault(roleId)); } return(null); }
public static CachedUser GetUser(this IGatewayClient client, Snowflake userId) { if (client.CacheProvider.TryGetUsers(out var cache)) { return(cache.GetValueOrDefault(userId)); } return(null); }
public static CachedGuildChannel GetChannel(this IGatewayClient client, Snowflake guildId, Snowflake channelId) { if (client.CacheProvider.TryGetChannels(guildId, out var cache, true)) { return(cache.GetValueOrDefault(channelId)); } return(null); }
public static IReadOnlyDictionary <Snowflake, CachedGuild> GetGuilds(this IGatewayClient client) { if (client.CacheProvider.TryGetGuilds(out var cache)) { return(cache.ReadOnly()); } return(ReadOnlyDictionary <Snowflake, CachedGuild> .Empty); }
public DiscordClient( IOptions <DiscordClientConfiguration> options, ILogger <DiscordClient> logger, IRestClient restClient, IGatewayClient gatewayClient, IEnumerable <DiscordClientExtension> extensions) : base(logger, restClient, gatewayClient, extensions) { }