public static DiscordClient UsingCommands(this DiscordClient client, Action<CommandServiceConfig> configFunc = null) { var config = new CommandServiceConfig(); configFunc(config); client.Services.Add(new CommandService(config)); return client; }
public CommandService(CommandServiceConfig config) { _caseSensitive = config.CaseSensitiveCommands; _separatorChar = config.SeparatorChar; _defaultRunMode = config.DefaultRunMode; _moduleLock = new SemaphoreSlim(1, 1); _typedModuleDefs = new ConcurrentDictionary <Type, ModuleInfo>(); _moduleDefs = new HashSet <ModuleInfo>(); _map = new CommandMap(this); _typeReaders = new ConcurrentDictionary <Type, ConcurrentDictionary <Type, TypeReader> >(); _defaultTypeReaders = new ConcurrentDictionary <Type, TypeReader>(); foreach (var type in PrimitiveParsers.SupportedTypes) { _defaultTypeReaders[type] = PrimitiveTypeReader.Create(type); } var entityTypeReaders = ImmutableList.CreateBuilder <Tuple <Type, Type> >(); entityTypeReaders.Add(new Tuple <Type, Type>(typeof(IMessage), typeof(MessageTypeReader <>))); entityTypeReaders.Add(new Tuple <Type, Type>(typeof(IChannel), typeof(ChannelTypeReader <>))); entityTypeReaders.Add(new Tuple <Type, Type>(typeof(IRole), typeof(RoleTypeReader <>))); entityTypeReaders.Add(new Tuple <Type, Type>(typeof(IUser), typeof(UserTypeReader <>))); _entityTypeReaders = entityTypeReaders.ToImmutable(); }
public CommandService(CommandServiceConfig config) { Config = config; _allCommands = new List <Command>(); _map = new CommandMap(); _categories = new Dictionary <string, CommandMap>(); Root = new CommandGroupBuilder(this); }
public CommandService(CommandServiceConfig config) { Config = config; _allCommands = new List<Command>(); _map = new CommandMap(null, "", ""); _categories = new Dictionary<string, CommandMap>(); Root = new CommandGroupBuilder(this, "", null); }
/// <summary> /// Initializes a new <see cref="CommandService"/> class with the provided configuration. /// </summary> /// <param name="config">The configuration class.</param> /// <exception cref="InvalidOperationException"> /// The <see cref="RunMode"/> cannot be set to <see cref="RunMode.Default"/>. /// </exception> public CommandService(CommandServiceConfig config) { _caseSensitive = config.CaseSensitiveCommands; _throwOnError = config.ThrowOnError; _ignoreExtraArgs = config.IgnoreExtraArgs; _separatorChar = config.SeparatorChar; _defaultRunMode = config.DefaultRunMode; _quotationMarkAliasMap = (config.QuotationMarkAliasMap ?? new Dictionary <char, char>()).ToImmutableDictionary(); if (_defaultRunMode == RunMode.Default) { throw new InvalidOperationException("The default run mode cannot be set to Default."); } _logManager = new LogManager(config.LogLevel); _logManager.Message += async msg => await _logEvent.InvokeAsync(msg).ConfigureAwait(false); _cmdLogger = _logManager.CreateLogger("Command"); _moduleLock = new SemaphoreSlim(1, 1); _typedModuleDefs = new ConcurrentDictionary <Type, ModuleInfo>(); _moduleDefs = new HashSet <ModuleInfo>(); _map = new CommandMap(this); _typeReaders = new ConcurrentDictionary <Type, ConcurrentDictionary <Type, TypeReader> >(); _defaultTypeReaders = new ConcurrentDictionary <Type, TypeReader>(); foreach (var type in PrimitiveParsers.SupportedTypes) { _defaultTypeReaders[type] = PrimitiveTypeReader.Create(type); _defaultTypeReaders[typeof(Nullable <>).MakeGenericType(type)] = NullableTypeReader.Create(type, _defaultTypeReaders[type]); } var tsreader = new TimeSpanTypeReader(); _defaultTypeReaders[typeof(TimeSpan)] = tsreader; _defaultTypeReaders[typeof(TimeSpan?)] = NullableTypeReader.Create(typeof(TimeSpan), tsreader); _defaultTypeReaders[typeof(string)] = new PrimitiveTypeReader <string>((string x, out string y) => { y = x; return(true); }, 0); var entityTypeReaders = ImmutableList.CreateBuilder <Tuple <Type, Type> >(); entityTypeReaders.Add(new Tuple <Type, Type>(typeof(IMessage), typeof(MessageTypeReader <>))); entityTypeReaders.Add(new Tuple <Type, Type>(typeof(IChannel), typeof(ChannelTypeReader <>))); entityTypeReaders.Add(new Tuple <Type, Type>(typeof(IRole), typeof(RoleTypeReader <>))); entityTypeReaders.Add(new Tuple <Type, Type>(typeof(IUser), typeof(UserTypeReader <>))); _entityTypeReaders = entityTypeReaders.ToImmutable(); }
public CommandService(CommandServiceConfig config) { _caseSensitive = config.CaseSensitiveCommands; _throwOnError = config.ThrowOnError; _separatorChar = config.SeparatorChar; _defaultRunMode = config.DefaultRunMode; if (_defaultRunMode == RunMode.Default) { throw new InvalidOperationException("The default run mode cannot be set to Default."); } _logManager = new LogManager(config.LogLevel); _logManager.Message += async msg => await _logEvent.InvokeAsync(msg).ConfigureAwait(false); _cmdLogger = _logManager.CreateLogger("Command"); _moduleLock = new SemaphoreSlim(1, 1); _typedModuleDefs = new ConcurrentDictionary <Type, ModuleInfo>(); _moduleDefs = new HashSet <ModuleInfo>(); _map = new CommandMap(this); _typeReaders = new ConcurrentDictionary <Type, ConcurrentDictionary <Type, TypeReader> >(); _defaultTypeReaders = new ConcurrentDictionary <Type, TypeReader>(); foreach (var type in PrimitiveParsers.SupportedTypes) { _defaultTypeReaders[type] = PrimitiveTypeReader.Create(type); } var entityTypeReaders = ImmutableList.CreateBuilder <Tuple <Type, Type> >(); entityTypeReaders.Add(new Tuple <Type, Type>(typeof(IMessage), typeof(MessageTypeReader <>))); entityTypeReaders.Add(new Tuple <Type, Type>(typeof(IChannel), typeof(ChannelTypeReader <>))); entityTypeReaders.Add(new Tuple <Type, Type>(typeof(IRole), typeof(RoleTypeReader <>))); entityTypeReaders.Add(new Tuple <Type, Type>(typeof(IUser), typeof(UserTypeReader <>))); _entityTypeReaders = entityTypeReaders.ToImmutable(); }
public static DiscordClient UsingCommands(this DiscordClient client, CommandServiceConfig config = null) { client.AddService(new CommandService(config)); return client; }
public static DiscordClient UsingCommands(this DiscordClient client, CommandServiceConfig config = null) { client.Services.Add(new CommandService(config)); return(client); }