コード例 #1
0
ファイル: GatewayContext.cs プロジェクト: FarDragi/DiscordCs
        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;
            }
        }
コード例 #2
0
        protected CachedChannel(IGatewayClient client, ChannelJsonModel model)
            : base(client, model.Id)
        {
            Type = model.Type;

            Update(model);
        }
コード例 #3
0
        /// <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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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));
        }
コード例 #6
0
        public CachedVoiceState(IGatewayClient client, Snowflake guildId, VoiceStateJsonModel model)
            : base(client, model.UserId)
        {
            GuildId = guildId;

            Update(model);
        }
コード例 #7
0
 public SensorApplicationService(ISensorClient sensorClient, IGatewayClient gatewayClient, IMapper mapper, INetworkLocationClient networkLocationClient)
 {
     _sensorClient          = sensorClient;
     _gatewayClient         = gatewayClient;
     _mapper                = mapper;
     _networkLocationClient = networkLocationClient;
 }
コード例 #8
0
ファイル: CachedGuild.cs プロジェクト: Pyhoma69/Disqord
        public CachedGuild(IGatewayClient client, GatewayGuildJsonModel model)
            : base(client, model.Id)
        {
            ApplicationId = model.ApplicationId;

            Update(model);
        }
コード例 #9
0
ファイル: CachedRole.cs プロジェクト: QuantumToasted/Disqord
        public CachedRole(IGatewayClient client, Snowflake guildId, RoleJsonModel model)
            : base(client, model.Id)
        {
            GuildId = guildId;

            Update(model);
        }
コード例 #10
0
 public CachedUserMessage(IGatewayClient client, CachedMember author, MessageJsonModel model)
     : base(client, author, model)
 {
     WebhookId      = model.WebhookId.GetValueOrNullable();
     IsTextToSpeech = model.Tts;
     Nonce          = model.Nonce;
 }
コード例 #11
0
ファイル: Client.cs プロジェクト: FarDragi/DiscordCs
        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
                }
            });
        }
コード例 #12
0
        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();
        }
コード例 #13
0
ファイル: CachedStage.cs プロジェクト: QuantumToasted/Disqord
        public CachedStage(IGatewayClient client, StageInstanceJsonModel model)
            : base(client, model.Id)
        {
            GuildId   = model.GuildId;
            ChannelId = model.ChannelId;

            Update(model);
        }
コード例 #14
0
        public CachedGuildEvent(IGatewayClient client, GuildScheduledEventJsonModel model)
            : base(client, model.Id)
        {
            GuildId   = model.GuildId;
            CreatorId = model.CreatorId;

            Update(model);
        }
コード例 #15
0
ファイル: CachedPresence.cs プロジェクト: Quahu/Disqord
        public CachedPresence(IGatewayClient client, PresenceJsonModel model)
            : base(client, model.User.Id)
        {
            GuildId  = model.GuildId;
            MemberId = model.User.Id;

            Update(model);
        }
コード例 #16
0
ファイル: CachedSharedUser.cs プロジェクト: Pyhoma69/Disqord
        /// <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);
        }
コード例 #17
0
        public static CachedGuild GetGuild(this IGatewayClient client, Snowflake guildId)
        {
            if (client.CacheProvider.TryGetGuilds(out var cache))
            {
                return(cache.GetValueOrDefault(guildId));
            }

            return(null);
        }
コード例 #18
0
ファイル: CachedEntity.cs プロジェクト: Pyhoma69/Disqord
        public CachedEntity(IGatewayClient client)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            Client = client;
        }
コード例 #19
0
        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);
        }
コード例 #20
0
 public GatewayExtractor(
     ILogger <GatewayExtractor> logger,
     ITemplateBuilder templateBuilder,
     IGatewayClient gatewayClient)
 {
     this.logger          = logger;
     this.templateBuilder = templateBuilder;
     this.gatewayClient   = gatewayClient;
 }
コード例 #21
0
 public CareContextDiscoveryController(IPatientDiscovery patientDiscovery,
                                       IGatewayClient gatewayClient,
                                       IBackgroundJobClient backgroundJob, ILogger <CareContextDiscoveryController> logger)
 {
     this.patientDiscovery = patientDiscovery;
     this.gatewayClient    = gatewayClient;
     this.backgroundJob    = backgroundJob;
     this.logger           = logger;
 }
コード例 #22
0
        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);
        }
コード例 #23
0
        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);
        }
コード例 #24
0
        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);
        }
コード例 #25
0
        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);
        }
コード例 #26
0
        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);
        }
コード例 #27
0
        public static CachedUser GetUser(this IGatewayClient client, Snowflake userId)
        {
            if (client.CacheProvider.TryGetUsers(out var cache))
            {
                return(cache.GetValueOrDefault(userId));
            }

            return(null);
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        public static IReadOnlyDictionary <Snowflake, CachedGuild> GetGuilds(this IGatewayClient client)
        {
            if (client.CacheProvider.TryGetGuilds(out var cache))
            {
                return(cache.ReadOnly());
            }

            return(ReadOnlyDictionary <Snowflake, CachedGuild> .Empty);
        }
コード例 #30
0
 public DiscordClient(
     IOptions <DiscordClientConfiguration> options,
     ILogger <DiscordClient> logger,
     IRestClient restClient,
     IGatewayClient gatewayClient,
     IEnumerable <DiscordClientExtension> extensions)
     : base(logger, restClient, gatewayClient, extensions)
 {
 }