示例#1
0
        /// <summary>
        /// Method for configuring <see cref="CommandsNextConfiguration"/>, accessing each configuration individually.
        /// </summary>
        /// <param name="prefixes">Sets the string prefixes used for commands.</param>
        /// <param name="prefixResolver">Sets the custom prefix resolver used for commands. Defaults to none (disabled).</param>
        /// <param name="enableMentionPrefix">Sets whether to allow mentioning the bot to be used as command prefix. Defaults to <see langword="true"/>.</param>
        /// <param name="caseSensitive">Sets whether strings should be matched in a case-sensitive manner. This switch affects the behaviour of default prefix resolver, command searching, and argument conversion. Defaults to <see langword="false"/>.</param>
        /// <param name="enableDefaultHelp">Sets whether to enable default help command. Disabling this will allow you to make your own help command. Modifying default help can be achieved via custom help formatters (see <see cref="BaseHelpFormatter"/> and <see cref="CommandsNextExtension.SetHelpFormatter{T}()"/> for more details). It is recommended to use help formatter instead of disabling help. Defaults to <see langword="true"/>.</param>
        /// <param name="directMessageHelp">Controls whether the default help will be sent via Direct Message or not. Enabling this will make the bot respond with help via direct messages. Defaults to <see langword="true"/>.</param>
        /// <param name="defaultHelpChecks">Sets the default pre-execution checks for the built-in help command. Only applicable if default help is enabled. Defaults to <see langword="null"/>.</param>
        /// <param name="directMessageCommands">Sets whether commands sent via direct messages should be processed. Defaults to <see langword="true"/>.</param>
        /// <param name="services">Sets the service provider for this <see cref="CommandsNextExtension"/> instance. Objects in this provider are used when instantiating command modules. This allows passing data around without resorting to static members. Defaults to <see langword="null"/>.</param>
        /// <param name="ignoreExtraArguments">Sets whether any extra arguments passed to commands should be ignored or not. If this is set to <see langword="false"/>, extra arguments will throw, otherwise they will be ignored. Defaults to <see langword="false"/>.</param>
        /// <param name="useDefaultCommandHandler">Sets whether to automatically enable handling commands. If this is set to <see langword="false"/>, you will need to manually handle each incoming message and pass it to <see cref="CommandsNextExtension"/>. Defaults to <see langword="true"/>.</param>
        public void CommandsSetup(IEnumerable <string> prefixes, PrefixResolverDelegate prefixResolver = null, bool enableMentionPrefix = true, bool caseSensitive = false,
                                  bool enableDefaultHelp        = true, bool directMessageHelp       = true, IEnumerable <CheckBaseAttribute> defaultHelpChecks = null,
                                  bool directMessageCommands    = false, IServiceCollection services = null, bool ignoreExtraArguments = false,
                                  bool useDefaultCommandHandler = true)
        {
            if (!(services is null))
            {
                foreach (ServiceDescriptor service in services)
                {
                    this._services.AddSingleton(service.ServiceType, service.ImplementationInstance);
                }
            }

            _discordClient.IsNotNull(this.MessageErrorDiscordClientIsNull);

            _commandsNext = _discordClient.UseCommandsNext(new CommandsNextConfiguration
            {
                StringPrefixes      = prefixes,
                PrefixResolver      = prefixResolver,
                EnableMentionPrefix = enableMentionPrefix,
                CaseSensitive       = caseSensitive,
                EnableDefaultHelp   = enableDefaultHelp,
                DmHelp                   = directMessageHelp,
                DefaultHelpChecks        = defaultHelpChecks,
                EnableDms                = directMessageCommands,
                Services                 = this._services.AddSingleton(this).BuildServiceProvider(true),
                IgnoreExtraArguments     = ignoreExtraArguments,
                UseDefaultCommandHandler = useDefaultCommandHandler
            });

            Type botObjectType = this._botObject.GetType();

            _commandsNext.RegisterCommands(botObjectType.IsClass && !string.Equals(botObjectType.Name, "runtimeassembly", StringComparison.CurrentCultureIgnoreCase) ?
                                           botObjectType.Assembly : (Assembly)this._botObject);
        }
示例#2
0
        public PrefixCacheService(ILogger <PrefixCacheService> logger, IDbContextFactory <BotDbContext> dbFactory)
        {
            _logger = logger;

            _cache     = new ConcurrentDictionary <ulong, string>();
            _dbFactory = dbFactory;

            PrefixDelegate = ResolvePrefix;
        }