public async Task Install(IDependencyMap _map) { try { // Create Command Service, inject it into Dependency Map client = _map.Get <DiscordSocketClient>(); commands = new CommandService(new CommandServiceConfig { CaseSensitiveCommands = false }); _map.Add(commands); map = _map; await commands.AddModuleAsync <RolesModule>().ConfigureAwait(false); Console.WriteLine("Roles Module Installed!"); //await commands.AddModuleAsync<BanModule>().ConfigureAwait(false); client.MessageReceived += HandleCommand; } catch (Exception ex) { Console.WriteLine(ErrorHandling.ThrowGenException("CommandHandler.cs", "Install(IDependencyMap)", ex.Message)); return; } }
public BlacklistService(IDependencyMap dependencies) { Client = dependencies.Get <DiscordSocketClient>(); Database = dependencies.Get <BotDbContext>(); Client.GuildAvailable += CheckBlacklist(false); Client.JoinedGuild += CheckBlacklist(true); }
public void OnEnable() { parentDotImage = EditorGUIUtility.Load("redLight") as Texture2D; currentDotImage = EditorGUIUtility.Load("greenLight") as Texture2D; childrenDotImage = EditorGUIUtility.Load("orangeLight") as Texture2D; parentArrow = EditorGUIUtility.Load("vcs_change") as Texture2D; childrenArrow = EditorGUIUtility.Load("vcs_incoming") as Texture2D; titleContent = new GUIContent("ResourceMap", EditorGUIUtility.Load("BlendTree Icon") as Texture2D); s_HandleWireMaterial2D = (Material)EditorGUIUtility.LoadRequired("SceneView/2DHandleLines.mat"); //Debug.LogError(currentImage); mapNames = AllMaps.Select(map => map.Name).ToArray(); if (selectMap >= AllMaps.Count) { selectMap = 0; } Map = AllMaps[selectMap]; if (string.IsNullOrEmpty(currentPath)) { OnSelectionChange(); } else { Refresh(); } }
public TempService(IDependencyMap map) { Bot = map.Get <Bot>(); Database = map.Get <BotDbContext>(); Client = map.Get <DiscordSocketClient>(); Bot.RegularTasks += CheckTempActions; }
/// <summary> /// Adds a service implementation to the dependency map that uses the given <paramref name="factoryFunctor"/> /// to instantiate the service itself. /// </summary> /// <typeparam name="T">The service type.</typeparam> /// <param name="map">The dependency map.</param> /// <param name="serviceName">The service name.</param> /// <param name="factoryFunctor">The factory functor that will be used to instantiate the service type.</param> public static void AddService <T>(this IDependencyMap map, string serviceName, Func <IMicroContainer, T> factoryFunctor) { Func <IMicroContainer, object> adapter = container => factoryFunctor(container); map.AddService(serviceName, typeof(T), adapter); }
/// <summary> /// Adds a service implementation to the dependency map that uses the given <paramref name="factoryFunctor"/> /// to instantiate the service itself. /// </summary> /// <param name="map">The dependency map.</param> /// <param name="serviceName">The service name.</param> /// <param name="serviceType">The service type.</param> /// <param name="factoryFunctor">The factory functor that will be used to instantiate the service type.</param> public static void AddService(this IDependencyMap map, string serviceName, System.Type serviceType, Func <IMicroContainer, object> factoryFunctor) { var dependency = new Dependency(serviceType, serviceName); var implementation = new FunctorCall(serviceType, factoryFunctor); map.AddService(dependency, implementation); }
public BotCommandService(IDependencyMap dependencies) { Client = dependencies.Get <DiscordSocketClient>(); Client.MessageReceived += HandleMessage; Commands = dependencies.Get <CommandService>(); Database = dependencies.Get <BotDbContext>(); Counters = dependencies.Get <CounterSet>(); Map = dependencies.Get <DependencyMap>(); }
private void AddAssemblyActions(IDependencyMap map, bool autoEnable = true) { var allActions = Assembly.GetEntryAssembly().GetTypes().Where(d => d.GetInterfaces().Contains(typeof(IMessageAction))); foreach (var type in allActions) { AddAction(type, map, autoEnable); } }
// Install public async Task Install(DiscordSocketClient client, IDependencyMap map) { _map = map; _client = client; _service = new CommandService(); await _service.AddModulesAsync(Assembly.GetEntryAssembly()); _client.MessageReceived += HandleCommand; }
public static async Task Setup(IDependencyMap _RemDeps) { RemDeps = _RemDeps; RemClient = RemDeps.Get <DiscordSocketClient>(); RemService = RemDeps.Get <CommandService>(); await RemService.AddModulesAsync(Assembly.GetEntryAssembly()); RemClient.MessageReceived += HandleCommand; }
public async Task Install(IDependencyMap map) { _commands = new CommandService(); await _commands.AddModulesAsync(Assembly.GetEntryAssembly()); _map = map; _client = map.Get <DiscordSocketClient>(); _client.MessageReceived += HandleCommand; }
public RemHelpCommand(CommandService _RemService, IDependencyMap _RemDeps) { if (_RemService == null) { throw new ArgumentNullException(nameof(_RemService)); } RemService = _RemService; RemDeps = _RemDeps; }
public async Task Install(DiscordSocketClient c) { _client = c; _cmds = new CommandService(); _map = new DependencyMap(); _map.Add(new AudioService()); await _cmds.AddModulesAsync(Assembly.GetEntryAssembly()); _client.MessageReceived += HandleCommand; }
private void AddAction(Type handlerType, IDependencyMap map, bool autoEnable = true) { var handler = Activator.CreateInstance(handlerType) as IMessageAction; handler.Install(map); if (autoEnable) { handler.Enable(); } Global.MessageActions.Add(handler.GetType().Name, handler); }
public async Task Install(IDependencyMap map) { _map = map; _client = _map.Get <DiscordSocketClient>(); _config = _map.Get <BotConfiguration>(); _programContext = _map.Get <Program>(); _commands = new CommandService(); _map.Add(_commands); await _commands.AddModulesAsync(Assembly.GetEntryAssembly()); _client.MessageReceived += HandleCommand; }
public async Task Install(IDependencyMap _map) { // Create Command Service, inject it into Dependency Map client = _map.Get <DiscordSocketClient>(); commands = new CommandService(); //_map.Add(commands); map = _map; await commands.AddModulesAsync(Assembly.GetEntryAssembly()); client.MessageReceived += HandleCommand; }
public LogService(IDependencyMap map, string directory) { BaseDirectory = directory; Client = map.Get <DiscordSocketClient>(); Logs = map.Get <LogSet>(); SetupBotLog(); ClientLogs(); GuildLogs(); ChannelLogs(); RoleLogs(); UserLogs(); MessageLogs(); }
public AnnounceService(IDependencyMap map) { Database = map.Get <BotDbContext>(); Client = map.Get <DiscordSocketClient>(); //TODO(james7132): make these messages configurable const string JoinMsg = "$mention has joined the server."; const string LeaveMsg = "**$user** has left the server."; const string BanMsg = "**$user** has been banned."; Client.UserJoined += u => GuildMessage(c => c.JoinMessage, JoinMsg)(u, u.Guild); Client.UserLeft += u => GuildMessage(c => c.LeaveMessage, LeaveMsg)(u, u.Guild); Client.UserBanned += GuildMessage(c => c.BanMessage, BanMsg); Client.UserVoiceStateUpdated += VoiceStateChanged; }
public async Task Load(DiscordSocketClient c) { // Hook the MessageReceived Event into our Command Handler _client = c; _client.MessageReceived += HandleCommand; _cmds = new CommandService(new CommandServiceConfig { CaseSensitiveCommands = true }); map = new DependencyMap(); // Discover all of the commands in this assembly and load them. map.Add(_client); map.Add(_cmds); await _cmds.AddModulesAsync(Assembly.GetEntryAssembly()); }
internal static object CreateObject(TypeInfo typeInfo, CommandService service, IDependencyMap map = null) { var constructors = typeInfo.DeclaredConstructors.Where(x => !x.IsStatic).ToArray(); if (constructors.Length == 0) { throw new InvalidOperationException($"No constructor found for \"{typeInfo.FullName}\""); } else if (constructors.Length > 1) { throw new InvalidOperationException($"Multiple constructors found for \"{typeInfo.FullName}\""); } var constructor = constructors[0]; ParameterInfo[] parameters = constructor.GetParameters(); object[] args = new object[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { var parameter = parameters[i]; object arg; if (map == null || !map.TryGet(parameter.ParameterType, out arg)) { if (parameter.ParameterType == typeof(CommandService)) { arg = service; } else if (parameter.ParameterType == typeof(IDependencyMap)) { arg = map; } else { throw new InvalidOperationException($"Failed to create \"{typeInfo.FullName}\", dependency \"{parameter.ParameterType.Name}\" was not found."); } } args[i] = arg; } try { return(constructor.Invoke(args)); } catch (Exception ex) { throw new Exception($"Failed to create \"{typeInfo.FullName}\"", ex); } }
public void ConcurrentDictDIContainer_Indexer_Test() { //arrange IDependencyMap expectedDependencyMap = fakeDependencyMap; IDependencyMap actualDependencyMap; mockDIContainer.Object.Register(fakeDependencyId, fakeDependencyMap); //act actualDependencyMap = mockDIContainer.Object[fakeDependencyId]; //assert Assert.AreSame(expectedDependencyMap, actualDependencyMap); Assert.IsNull(mockDIContainer.Object.GetDependencyMap(fakeDependencyId2)); }
public override void Register(IEnumerable <Type> types) { foreach (Type t in types) { if (Attribute.IsDefined(t, typeof(InjectForAttribute))) { Attribute[] injectForTypeAttributes = Attribute.GetCustomAttributes(t, typeof(InjectForAttribute)); foreach (Attribute eachAttribute in injectForTypeAttributes) { InjectForAttribute injectForType = eachAttribute as InjectForAttribute; string sourceDependencyId = injectForType.Type.GetDependencyId(); string targetDependencyId = t.GetDependencyId(); if (sourceDependencyId == targetDependencyId) { continue; } if (!this.Container.ContainsDependency(sourceDependencyId)) { throw new NonInjectableTypeException(sourceDependencyId + " dependency is not attributed as Injectable"); } if (!this.Container.ContainsDependency(targetDependencyId)) { throw new NonInjectableTypeException(targetDependencyId + " dependency is not attributed as Injectable"); } IDependencyMap sourceDependencyMap = this.Container.GetDependencyMap(sourceDependencyId); if (sourceDependencyMap.PrimaryDependencyHolder == null) { sourceDependencyMap.PrimaryDependencyHolder = this.Container.GetDependencyMap(targetDependencyId).PrimaryDependencyHolder; } else { throw new InjectionAmbiguityException("More than one types(" + sourceDependencyMap.PrimaryDependencyHolder.DependencyId + ", " + this.Container[targetDependencyId].PrimaryDependencyHolder.DependencyId + ") can not be set as to be injected for " + sourceDependencyId); } sourceDependencyMap.SecondaryDependencyHolders.Add(this.Container.GetDependencyMap(targetDependencyId).PrimaryDependencyHolder); } } } this.RegisterNext(types); }
public void Init() { fakeType = typeof(foo); fakeDependencyId = fakeType.GetDependencyId(); fakeDependencyId2 = typeof(Ifoo).GetDependencyId(); fakeDependencyMap = new DependencyMap(It.IsAny <IDIContainer>(), fakeType); fakeDict = new ConcurrentDictionary <string, IDependencyMap>(); fakeDict.TryAdd(fakeType.GetDependencyId(), fakeDependencyMap); mockDIContainer = new Mock <ConcurrentDictDIContainer>() { CallBase = true }; mockDIContainer.SetupGet(dict => dict.Container).Returns(fakeDict); }
public DatabaseService(IDependencyMap map) { Client = map.Get <DiscordSocketClient>(); Database = map.Get <BotDbContext>(); Bot.RegularTasks += Database.Save; Client.MessageReceived += async m => { var author = m.Author; if (author.Username == null) { return; } var user = Database.GetUser(author); user.AddName(author.Username); await Database.Save(); }; }
public async Task InitializeAsync(DiscordSocketClient c, IDependencyMap map) { _client = c; _service = new CommandService(new CommandServiceConfig() { CaseSensitiveCommands = false, DefaultRunMode = RunMode.Sync }); await _service.AddModulesAsync(Assembly.GetEntryAssembly()); _map = map; _map.Add(new InteractiveService(_client)); _client.MessageReceived += HandleCommandAsync; }
public async Task Install(IDependencyMap _map) { //Create Command Service, Inject it into Dependency Map client = _map.Get <DiscordSocketClient>(); commands = new CommandService(); //_map.Add(commands); //map = _map; await commands.AddModulesAsync(Assembly.GetEntryAssembly()); //Send user message to get handled client.MessageReceived += HandleCommand; //Announce user joins server client.UserJoined += AnnounceJoinedUser; }
public async Task Install(IDependencyMap _map) { // Create Command Service, inject it into Dependency Map client = _map.Get <DiscordSocketClient>(); commands = new CommandService(); //_map.Add(commands); map = _map; commands.Log += (x => { Console.ForegroundColor = ConsoleColor.Gray; Console.Write($"[{DateTime.Now.GetDateTimeFormats()[110]}]"); switch ((int)x.Severity) { case 0: Console.ForegroundColor = ConsoleColor.Red; break; case 1: Console.ForegroundColor = ConsoleColor.Red; break; case 2: Console.ForegroundColor = ConsoleColor.DarkYellow; break; case 3: Console.ForegroundColor = ConsoleColor.Yellow; break; case 4: Console.ForegroundColor = ConsoleColor.Magenta; break; case 5: Console.ForegroundColor = ConsoleColor.DarkMagenta; break; default: Console.ForegroundColor = ConsoleColor.White; break; } //sets color according to severity Console.WriteLine(x.Message); return(Task.CompletedTask); }); await commands.AddModulesAsync(Assembly.GetEntryAssembly()); client.MessageReceived += HandleCommand; }
public override Task <PreconditionResult> CheckPermissions( CommandContext context, CommandInfo commandInfo, IDependencyMap dependencies) { if (QCheck.InGuild(context.Message) == null) { return(Task.FromResult(PreconditionResult.FromError("Not in server."))); } var user = context.Message.Author as IGuildUser; if (!user.IsServerOwner() && !user.IsBotOwner()) { return(Task.FromResult(PreconditionResult.FromError($"{user.Username} you are not the owner of this server, and thus cannot run {commandInfo.Name.Code()}"))); } return(Task.FromResult(PreconditionResult.FromSuccess())); }
public async Task Install(IDependencyMap _map) { // Define Client client = _map.Get <DiscordSocketClient>(); // Define cmds cmds = new CommandService(); // Add cmds To _map _map.Add(cmds); // Define map map = _map; await cmds.AddModulesAsync(Assembly.GetEntryAssembly()); client.MessageReceived += HandleCommand; }
public async Task Install(IDependencyMap _map) { // Create Command Service, inject it into Dependency Map Client = _map.Get <DiscordSocketClient>(); Commands = new CommandService(); Commands.Log += JukeBot.Log; Map = _map; Map.Add(new AudioService()); Map.Add(new ImageService()); await Commands.AddModulesAsync(Assembly.GetEntryAssembly()); Client.MessageReceived += PrefixCommandHandler; Client.MessageReceived += PostfixCommandHandler; }
/// <summary> /// Registers a type as a factory type if it implements the <see cref="IFactory{T}"/> interface. /// </summary> /// <param name="type">The target type</param> /// <param name="defaultImplementations">The list of default implementations per service type.</param> /// <param name="map">The dependency map.</param> private void RegisterNamedFactoryType(Type type, IDictionary<Type, IImplementation> defaultImplementations, IDependencyMap map) { var factoryTypeDefinition = typeof(IFactory<>); var interfaces = type.GetInterfaces(); foreach (var interfaceType in interfaces) { if (!interfaceType.IsGenericType) continue; var definitionType = interfaceType.GetGenericTypeDefinition(); if (definitionType != factoryTypeDefinition) continue; var genericArguments = interfaceType.GetGenericArguments(); var actualServiceType = genericArguments[0]; var serviceName = type.Name; var nameLength = serviceName.Length; var hasSpecialName = serviceName.EndsWith("Factory") && nameLength > 7; serviceName = hasSpecialName ? serviceName.Substring(0, nameLength - 7) : serviceName; var implementation = new FactoryCall(actualServiceType, type.Name); // Register the default implementation if necessary if (!defaultImplementations.ContainsKey(actualServiceType)) defaultImplementations[actualServiceType] = implementation; var dependency = new Dependency(actualServiceType, serviceName); map.AddService(dependency, implementation); } }
/// <summary> /// Fetches the assembly list. /// </summary> /// <returns>IDependencyMap.</returns> public IDependencyMap FetchAssemblyList() { if (_dependencyMap == null || _dependencyMap.Expired) _dependencyMap = DependencyMap.Create(); return _dependencyMap; }