/// <summary>
 ///     Instantiates a new <see cref="DiscordClientService"/> with the provided logger and client.
 /// </summary>
 /// <param name="logger"> The logger to use. </param>
 /// <param name="client"> The client to use. </param>
 protected DiscordClientService(
     ILogger logger,
     DiscordClientBase client)
 {
     Logger = logger;
     Client = client;
 }
 /// <summary>
 ///     Instantiates a new <see cref="DiscordClientRunnerService"/>.
 /// </summary>
 /// <param name="logger"> The logger. </param>
 /// <param name="client"> The client to host. </param>
 public DiscordClientRunnerService(
     ILogger <DiscordClientRunnerService> logger,
     DiscordClientBase client)
 {
     Logger = logger;
     Client = client;
 }
예제 #3
0
 public DiscordClientMasterService(
     ILogger <DiscordClientMasterService> logger,
     DiscordClientBase client,
     IEnumerable <DiscordClientService> services)
     : this(client, services)
 {
     Logger = logger;
 }
예제 #4
0
 public BotService(
     ILogger <BotService> logger,
     DiscordClientBase client,
     AvailabilityService availability)
     : base(logger, client)
 {
     _availability = availability;
 }
 internal UserNoteUpdatedEventArgs(DiscordClientBase client,
                                   Snowflake userId,
                                   string oldNote,
                                   string newNote) : base(client)
 {
     UserId  = userId;
     OldNote = oldNote;
     NewNote = newNote;
 }
예제 #6
0
 internal TypingStartedEventArgs(DiscordClientBase client,
                                 SnowflakeOptional <ICachedMessageChannel> channel,
                                 FetchableSnowflakeOptional <IUser> user,
                                 DateTimeOffset timestamp) : base(client)
 {
     Channel   = channel;
     User      = user;
     Timestamp = timestamp;
 }
예제 #7
0
 internal InviteDeletedEventArgs(
     DiscordClientBase client,
     Snowflake?guildId,
     Snowflake channelId,
     string code) : base(client)
 {
     GuildId   = guildId;
     ChannelId = channelId;
     Code      = code;
 }
        public static InteractivityExtension GetInteractivity(this DiscordClientBase client)
        {
            var extension = client.GetExtension <InteractivityExtension>();

            if (extension == null)
            {
                throw new InvalidOperationException("This client does not have the interactivity extension added.");
            }

            return(extension);
        }
예제 #9
0
        public LavalinkClient(DiscordClientBase client, LavalinkConfiguration configuration)
        {
            DiscordClient = client;

            Address       = configuration.Address;
            Port          = configuration.Port;
            Authorization = configuration.Authorization;
            Shards        = configuration.Shards;
            SelfDeaf      = configuration.SelfDeaf;

            _connectionEndpoint = string.Format("{0}:{1}", configuration.Address, configuration.Port);
            _searchEndpoint     = string.Format("http://{0}/loadtracks?identifier=", _connectionEndpoint);
        }
예제 #10
0
 internal InviteCreatedEventArgs(
     DiscordClientBase client,
     CachedGuild guild,
     SnowflakeOptional <CachedChannel> channel,
     CachedUser inviter,
     string code,
     bool isTemporary,
     int maxUses,
     int maxAge,
     DateTimeOffset createdAt) : base(client)
 {
     Guild       = guild;
     Channel     = channel;
     Inviter     = inviter;
     Code        = code;
     IsTemporary = isTemporary;
     MaxUses     = maxUses;
     MaxAge      = maxAge;
     CreatedAt   = createdAt;
 }
예제 #11
0
        internal DiscordBotBase(DiscordClientBase client, IPrefixProvider prefixProvider, IDiscordBotBaseConfiguration configuration)
            : base(client)
        {
            PrefixProvider  = prefixProvider;
            _commandService = new CommandService(configuration.CommandServiceConfiguration ?? CommandServiceConfiguration.Default);
            _provider       = configuration.ProviderFactory?.Invoke(this);
            AddTypeParser(CachedRoleTypeParser.Instance);
            AddTypeParser(CachedMemberTypeParser.Instance);
            AddTypeParser(CachedUserTypeParser.Instance);
            AddTypeParser(CachedGuildChannelTypeParser <CachedGuildChannel> .Instance);
            AddTypeParser(CachedGuildChannelTypeParser <CachedTextChannel> .Instance);
            AddTypeParser(CachedGuildChannelTypeParser <CachedVoiceChannel> .Instance);
            AddTypeParser(CachedGuildChannelTypeParser <CachedCategoryChannel> .Instance);
            AddTypeParser(LocalCustomEmojiTypeParser.Instance);
            AddTypeParser(SnowflakeTypeParser.Instance);
            AddTypeParser(ColorTypeParser.Instance);
            //AddTypeParser(SanitaryContentParser.Instance);

            MessageReceived += MessageReceivedAsync;
        }
예제 #12
0
        private DiscordClientMasterService(
            DiscordClientBase client,
            IEnumerable <DiscordClientService> services,
            IServiceProvider serviceProvider)
        {
            Client = client;

            var servicesArray = services.GetArray();

            foreach (var service in servicesArray)
            {
                service.Logger ??= serviceProvider.GetService(typeof(ILogger <>).MakeGenericType(service.GetType())) as ILogger;
                service.Client ??= client;
            }

            ReadyServices                   = GetServices <ReadyEventArgs>(servicesArray, nameof(DiscordClientService.OnReady));
            ChannelCreatedServices          = GetServices <ChannelCreatedEventArgs>(servicesArray, nameof(DiscordClientService.OnChannelCreated));
            ChannelUpdatedServices          = GetServices <ChannelUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnChannelUpdated));
            ChannelDeletedServices          = GetServices <ChannelDeletedEventArgs>(servicesArray, nameof(DiscordClientService.OnChannelDeleted));
            ThreadCreatedServices           = GetServices <ThreadCreatedEventArgs>(servicesArray, nameof(DiscordClientService.OnThreadCreated));
            ThreadUpdatedServices           = GetServices <ThreadUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnThreadUpdated));
            ThreadDeletedServices           = GetServices <ThreadDeletedEventArgs>(servicesArray, nameof(DiscordClientService.OnThreadDeleted));
            ThreadsSynchronizedServices     = GetServices <ThreadsSynchronizedEventArgs>(servicesArray, nameof(DiscordClientService.OnThreadsSynchronized));
            ThreadMembersUpdatedServices    = GetServices <ThreadMembersUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnThreadMembersUpdated));
            ChannelPinsUpdatedServices      = GetServices <ChannelPinsUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnChannelPinsUpdated));
            GuildAvailableServices          = GetServices <GuildAvailableEventArgs>(servicesArray, nameof(DiscordClientService.OnGuildAvailable));
            JoinedGuildServices             = GetServices <JoinedGuildEventArgs>(servicesArray, nameof(DiscordClientService.OnJoinedGuild));
            GuildUpdatedServices            = GetServices <GuildUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnGuildUpdated));
            GuildUnavailableServices        = GetServices <GuildUnavailableEventArgs>(servicesArray, nameof(DiscordClientService.OnGuildUnavailable));
            LeftGuildServices               = GetServices <LeftGuildEventArgs>(servicesArray, nameof(DiscordClientService.OnLeftGuild));
            BanCreatedServices              = GetServices <BanCreatedEventArgs>(servicesArray, nameof(DiscordClientService.OnBanCreated));
            BanDeletedServices              = GetServices <BanDeletedEventArgs>(servicesArray, nameof(DiscordClientService.OnBanDeleted));
            EmojisUpdatedServices           = GetServices <EmojisUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnEmojisUpdated));
            StickersUpdatedServices         = GetServices <StickersUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnStickersUpdated));
            IntegrationsUpdatedServices     = GetServices <IntegrationsUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnIntegrationsUpdated));
            MemberJoinedServices            = GetServices <MemberJoinedEventArgs>(servicesArray, nameof(DiscordClientService.OnMemberJoined));
            MemberUpdatedServices           = GetServices <MemberUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnMemberUpdated));
            MemberLeftServices              = GetServices <MemberLeftEventArgs>(servicesArray, nameof(DiscordClientService.OnMemberLeft));
            RoleCreatedServices             = GetServices <RoleCreatedEventArgs>(servicesArray, nameof(DiscordClientService.OnRoleCreated));
            RoleUpdatedServices             = GetServices <RoleUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnRoleUpdated));
            RoleDeletedServices             = GetServices <RoleDeletedEventArgs>(servicesArray, nameof(DiscordClientService.OnRoleDeleted));
            GuildEventCreatedServices       = GetServices <GuildEventCreatedEventArgs>(servicesArray, nameof(DiscordClientService.OnGuildEventCreated));
            GuildEventUpdatedServices       = GetServices <GuildEventUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnGuildEventUpdated));
            GuildEventDeletedServices       = GetServices <GuildEventDeletedEventArgs>(servicesArray, nameof(DiscordClientService.OnGuildEventDeleted));
            GuildEventMemberAddedServices   = GetServices <GuildEventMemberAddedEventArgs>(servicesArray, nameof(DiscordClientService.OnGuildEventMemberAdded));
            GuildEventMemberRemovedServices = GetServices <GuildEventMemberRemovedEventArgs>(servicesArray, nameof(DiscordClientService.OnGuildEventMemberRemoved));
            IntegrationCreatedServices      = GetServices <IntegrationCreatedEventArgs>(servicesArray, nameof(DiscordClientService.OnIntegrationCreated));
            IntegrationUpdatedServices      = GetServices <IntegrationUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnIntegrationUpdated));
            IntegrationDeletedServices      = GetServices <IntegrationDeletedEventArgs>(servicesArray, nameof(DiscordClientService.OnIntegrationDeleted));
            InteractionReceivedServices     = GetServices <InteractionReceivedEventArgs>(servicesArray, nameof(DiscordClientService.OnInteractionReceived));
            InviteCreatedServices           = GetServices <InviteCreatedEventArgs>(servicesArray, nameof(DiscordClientService.OnInviteCreated));
            InviteDeletedServices           = GetServices <InviteDeletedEventArgs>(servicesArray, nameof(DiscordClientService.OnInviteDeleted));
            MessageReceivedServices         = GetServices <MessageReceivedEventArgs>(servicesArray, nameof(DiscordClientService.OnMessageReceived));
            MessageUpdatedServices          = GetServices <MessageUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnMessageUpdated));
            MessageDeletedServices          = GetServices <MessageDeletedEventArgs>(servicesArray, nameof(DiscordClientService.OnMessageDeleted));
            MessagesDeletedServices         = GetServices <MessagesDeletedEventArgs>(servicesArray, nameof(DiscordClientService.OnMessagesDeleted));
            ReactionAddedServices           = GetServices <ReactionAddedEventArgs>(servicesArray, nameof(DiscordClientService.OnReactionAdded));
            ReactionRemovedServices         = GetServices <ReactionRemovedEventArgs>(servicesArray, nameof(DiscordClientService.OnReactionRemoved));
            ReactionsClearedServices        = GetServices <ReactionsClearedEventArgs>(servicesArray, nameof(DiscordClientService.OnReactionsCleared));
            StageCreatedServices            = GetServices <StageCreatedEventArgs>(servicesArray, nameof(DiscordClientService.OnStageCreated));
            StageUpdatedServices            = GetServices <StageUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnStageUpdated));
            StageDeletedServices            = GetServices <StageDeletedEventArgs>(servicesArray, nameof(DiscordClientService.OnStageDeleted));
            PresenceUpdatedServices         = GetServices <PresenceUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnPresenceUpdated));
            TypingStartedServices           = GetServices <TypingStartedEventArgs>(servicesArray, nameof(DiscordClientService.OnTypingStarted));
            CurrentUserUpdatedServices      = GetServices <CurrentUserUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnCurrentUserUpdated));
            VoiceStateUpdatedServices       = GetServices <VoiceStateUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnVoiceStateUpdated));
            VoiceServerUpdatedServices      = GetServices <VoiceServerUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnVoiceServerUpdated));
            WebhooksUpdatedServices         = GetServices <WebhooksUpdatedEventArgs>(servicesArray, nameof(DiscordClientService.OnWebhooksUpdated));

            Client.Ready                   += HandleReady;
            Client.ChannelCreated          += HandleChannelCreated;
            Client.ChannelUpdated          += HandleChannelUpdated;
            Client.ChannelDeleted          += HandleChannelDeleted;
            Client.ThreadCreated           += HandleThreadCreated;
            Client.ThreadUpdated           += HandleThreadUpdated;
            Client.ThreadDeleted           += HandleThreadDeleted;
            Client.ThreadsSynchronized     += HandleThreadsSynchronized;
            Client.ThreadMembersUpdated    += HandleThreadMembersUpdated;
            Client.ChannelPinsUpdated      += HandleChannelPinsUpdated;
            Client.GuildAvailable          += HandleGuildAvailable;
            Client.JoinedGuild             += HandleJoinedGuild;
            Client.GuildUpdated            += HandleGuildUpdated;
            Client.GuildUnavailable        += HandleGuildUnavailable;
            Client.LeftGuild               += HandleLeftGuild;
            Client.BanCreated              += HandleBanCreated;
            Client.BanDeleted              += HandleBanDeleted;
            Client.EmojisUpdated           += HandleEmojisUpdated;
            Client.StickersUpdated         += HandleStickersUpdated;
            Client.IntegrationsUpdated     += HandleIntegrationsUpdated;
            Client.MemberJoined            += HandleMemberJoined;
            Client.MemberUpdated           += HandleMemberUpdated;
            Client.MemberLeft              += HandleMemberLeft;
            Client.RoleCreated             += HandleRoleCreated;
            Client.RoleUpdated             += HandleRoleUpdated;
            Client.RoleDeleted             += HandleRoleDeleted;
            Client.GuildEventCreated       += HandleGuildEventCreated;
            Client.GuildEventUpdated       += HandleGuildEventUpdated;
            Client.GuildEventDeleted       += HandleGuildEventDeleted;
            Client.GuildEventMemberAdded   += HandleGuildEventMemberAdded;
            Client.GuildEventMemberRemoved += HandleGuildEventMemberRemoved;
            Client.IntegrationCreated      += HandleIntegrationCreated;
            Client.IntegrationUpdated      += HandleIntegrationUpdated;
            Client.IntegrationDeleted      += HandleIntegrationDeleted;
            Client.InteractionReceived     += HandleInteractionReceived;
            Client.InviteCreated           += HandleInviteCreated;
            Client.InviteDeleted           += HandleInviteDeleted;
            Client.MessageReceived         += HandleMessageReceived;
            Client.MessageUpdated          += HandleMessageUpdated;
            Client.MessageDeleted          += HandleMessageDeleted;
            Client.MessagesDeleted         += HandleMessagesDeleted;
            Client.ReactionAdded           += HandleReactionAdded;
            Client.ReactionRemoved         += HandleReactionRemoved;
            Client.ReactionsCleared        += HandleReactionsCleared;
            Client.PresenceUpdated         += HandlePresenceUpdated;
            Client.StageCreated            += HandleStageCreated;
            Client.StageUpdated            += HandleStageUpdated;
            Client.StageDeleted            += HandleStageDeleted;
            Client.TypingStarted           += HandleTypingStarted;
            Client.CurrentUserUpdated      += HandleCurrentUserUpdated;
            Client.VoiceStateUpdated       += HandleVoiceStateUpdated;
            Client.VoiceServerUpdated      += HandleVoiceServerUpdated;
            Client.WebhooksUpdated         += HandleWebhooksUpdated;
        }
예제 #13
0
 internal WebhooksUpdatedEventArgs(DiscordClientBase client, Snowflake guildId, Snowflake channelId) : base(client)
 {
     GuildId   = guildId;
     ChannelId = channelId;
 }
예제 #14
0
        public static Task <ReactionAddedEventArgs> WaitForReactionAsync(this DiscordClientBase client, Snowflake messageId, Predicate <ReactionAddedEventArgs> predicate = null, TimeSpan timeout = default, CancellationToken cancellationToken = default)
        {
            var extension = client.GetInteractivity();

            return(extension.WaitForReactionAsync(messageId, predicate, timeout, cancellationToken));
        }
        private DiscordClientMasterService(
            DiscordClientBase client,
            IEnumerable <DiscordClientService> services)
        {
            Client = client;

            _readyServices              = services.Where(x => IsOverridden(x, "OnReady")).ToArray();
            _channelCreatedServices     = services.Where(x => IsOverridden(x, "OnChannelCreated")).ToArray();
            _channelUpdatedServices     = services.Where(x => IsOverridden(x, "OnChannelUpdated")).ToArray();
            _channelDeletedServices     = services.Where(x => IsOverridden(x, "OnChannelDeleted")).ToArray();
            _channelPinsUpdatedServices = services.Where(x => IsOverridden(x, "OnChannelPinsUpdated")).ToArray();
            _guildAvailableServices     = services.Where(x => IsOverridden(x, "OnGuildAvailable")).ToArray();
            _joinedGuildServices        = services.Where(x => IsOverridden(x, "OnJoinedGuild")).ToArray();
            _guildUpdatedServices       = services.Where(x => IsOverridden(x, "OnGuildUpdated")).ToArray();
            _guildUnavailableServices   = services.Where(x => IsOverridden(x, "OnGuildUnavailable")).ToArray();
            _leftGuildServices          = services.Where(x => IsOverridden(x, "OnLeftGuild")).ToArray();
            _banCreatedServices         = services.Where(x => IsOverridden(x, "OnBanCreated")).ToArray();
            _banDeletedServices         = services.Where(x => IsOverridden(x, "OnBanDeleted")).ToArray();
            _guildEmojisUpdatedServices = services.Where(x => IsOverridden(x, "OnGuildEmojisUpdated")).ToArray();
            _memberJoinedServices       = services.Where(x => IsOverridden(x, "OnMemberJoined")).ToArray();
            _memberUpdatedServices      = services.Where(x => IsOverridden(x, "OnMemberUpdated")).ToArray();
            _memberLeftServices         = services.Where(x => IsOverridden(x, "OnMemberLeft")).ToArray();
            _roleCreatedServices        = services.Where(x => IsOverridden(x, "OnRoleCreated")).ToArray();
            _roleUpdatedServices        = services.Where(x => IsOverridden(x, "OnRoleUpdated")).ToArray();
            _roleDeletedServices        = services.Where(x => IsOverridden(x, "OnRoleDeleted")).ToArray();
            _inviteCreatedServices      = services.Where(x => IsOverridden(x, "OnInviteCreated")).ToArray();
            _inviteDeletedServices      = services.Where(x => IsOverridden(x, "OnInviteDeleted")).ToArray();
            _messageReceivedServices    = services.Where(x => IsOverridden(x, "OnMessageReceived")).ToArray();
            _messageUpdatedServices     = services.Where(x => IsOverridden(x, "OnMessageUpdated")).ToArray();
            _messageDeletedServices     = services.Where(x => IsOverridden(x, "OnMessageDeleted")).ToArray();
            _messagesDeletedServices    = services.Where(x => IsOverridden(x, "OnMessagesDeleted")).ToArray();
            _reactionAddedServices      = services.Where(x => IsOverridden(x, "OnReactionAdded")).ToArray();
            _reactionRemovedServices    = services.Where(x => IsOverridden(x, "OnReactionRemoved")).ToArray();
            _reactionsClearedServices   = services.Where(x => IsOverridden(x, "OnReactionsCleared")).ToArray();
            _typingStartedServices      = services.Where(x => IsOverridden(x, "OnTypingStarted")).ToArray();
            _currentUserUpdatedServices = services.Where(x => IsOverridden(x, "OnCurrentUserUpdated")).ToArray();
            _voiceStateUpdatedServices  = services.Where(x => IsOverridden(x, "OnVoiceStateUpdated")).ToArray();
            _voiceServerUpdatedServices = services.Where(x => IsOverridden(x, "OnVoiceServerUpdated")).ToArray();
            _webhooksUpdatedServices    = services.Where(x => IsOverridden(x, "OnWebhooksUpdated")).ToArray();

            Client.Ready              += HandleReady;
            Client.ChannelCreated     += HandleChannelCreated;
            Client.ChannelUpdated     += HandleChannelUpdated;
            Client.ChannelDeleted     += HandleChannelDeleted;
            Client.ChannelPinsUpdated += HandleChannelPinsUpdated;
            Client.GuildAvailable     += HandleGuildAvailable;
            Client.JoinedGuild        += HandleJoinedGuild;
            Client.GuildUpdated       += HandleGuildUpdated;
            Client.GuildUnavailable   += HandleGuildUnavailable;
            Client.LeftGuild          += HandleLeftGuild;
            Client.BanCreated         += HandleBanCreated;
            Client.BanDeleted         += HandleBanDeleted;
            Client.GuildEmojisUpdated += HandleGuildEmojisUpdated;
            Client.MemberJoined       += HandleMemberJoined;
            Client.MemberUpdated      += HandleMemberUpdated;
            Client.MemberLeft         += HandleMemberLeft;
            Client.RoleCreated        += HandleRoleCreated;
            Client.RoleUpdated        += HandleRoleUpdated;
            Client.RoleDeleted        += HandleRoleDeleted;
            Client.InviteCreated      += HandleInviteCreated;
            Client.InviteDeleted      += HandleInviteDeleted;
            Client.MessageReceived    += HandleMessageReceived;
            Client.MessageUpdated     += HandleMessageUpdated;
            Client.MessageDeleted     += HandleMessageDeleted;
            Client.MessagesDeleted    += HandleMessagesDeleted;
            Client.ReactionAdded      += HandleReactionAdded;
            Client.ReactionRemoved    += HandleReactionRemoved;
            Client.ReactionsCleared   += HandleReactionsCleared;
            Client.TypingStarted      += HandleTypingStarted;
            Client.CurrentUserUpdated += HandleCurrentUserUpdated;
            Client.VoiceStateUpdated  += HandleVoiceStateUpdated;
            Client.VoiceServerUpdated += HandleVoiceServerUpdated;
            Client.WebhooksUpdated    += HandleWebhooksUpdated;
        }
예제 #16
0
 public static InteractivityExtension GetInteractivity(this DiscordClientBase client)
 => client.GetRequiredExtension <InteractivityExtension>();
예제 #17
0
 internal ShardReadyEventArgs(DiscordClientBase client, string sessionId, string[] trace, Shard shard)
     : base(client, sessionId, trace)
 {
     Shard = shard;
 }
        public static Task RunMenuAsync(this DiscordClientBase client, Snowflake channelId, MenuBase menu, TimeSpan timeout = default, CancellationToken cancellationToken = default)
        {
            var extension = client.GetInteractivity();

            return(extension.RunMenuAsync(channelId, menu, timeout, cancellationToken));
        }
예제 #19
0
 internal ReadyEventArgs(DiscordClientBase client, string sessionId, string[] trace) : base(client)
 {
     SessionId = sessionId;
     Trace     = trace.ReadOnly();
 }
예제 #20
0
 internal DiscordEventArgs(DiscordClientBase client)
 {
     Client = client;
 }
예제 #21
0
 public TestService(
     ILogger <TestService> logger,
     DiscordClientBase client)
     : base(logger, client)
 {
 }