public IRCMessage(IRCCommand command, String parameters = "", String trailingParameters = "") { TimeStamp = DateTime.Now; msgtype = (int)IRCMessageType.SEND; Command = command.ToString(); Parameters = parameters != String.Empty ? parameters.Split(' ').ToList() : new List <String> (); TrailingParameters = trailingParameters; }
/// <summary> /// Add a command to the list /// </summary> /// <param name="commandName">The command information</param> /// <param name="target">The class containing the command</param> /// <param name="method">The command</param> public void AddCommand(IRCCommand commandName, object target, System.Reflection.MethodInfo method) { IRCCommandLink val = new IRCCommandLink() { Object = target, Method = method, Attributes = commandName }; if (!commandList.Contains(val)) { commandList.Add(val); } }
public static void RegisterCommands(object commandClass) { IRCCommandList returnValue = IRCCommands; Type commandClassType = commandClass.GetType(); int maxCom = 0; int place = 0; Console.WriteLine("Registering {0}...", commandClass.GetType().Name); foreach (MethodInfo methodInfo in commandClassType.GetMethods()) { foreach (Attribute attr in Attribute.GetCustomAttributes(methodInfo)) { if (attr.GetType() == typeof(IRCCommand) || attr.GetType() == typeof(IRCCommandPlaceholder)) { maxCom++; if (attr.GetType() == typeof(IRCCommandPlaceholder)) { place++; } IRCCommand command = (IRCCommand)attr; ParameterInfo[] parameters = methodInfo.GetParameters(); if (parameters.Length != 1 && parameters[0].ParameterType != typeof(IMessage)) { Console.WriteLine("\tCommand {0} ({1}) not registered, argument mismatch (requires one argument of type 'Message')", command.Name, methodInfo.Name); continue; } Console.WriteLine("\tCommand {0} {1} registered{2}", command.Name, (command.MinimumArguments != -1 ? "(" + command.MinimumArguments + (command.MaximumArguments != command.MinimumArguments ? "-" + command.MaximumArguments : "") + " argument" + (command.MinimumArguments == 1 && command.MaximumArguments == 1 ? "" : "s") + ")" : "(no arguments)"), (attr.GetType() == typeof(IRCCommandPlaceholder) ? " (Placeholder implementation)" : "")); returnValue.AddCommand(command, commandClass, methodInfo); } } } if (maxCom != 0) { Console.WriteLine("{0} Commands implemented on {1} with {2} ({3}%)", maxCom, commandClass.GetType().Name, place + " placeholder" + (place != 1 ? "s" : ""), Math.Round((place / (double)maxCom) * 100)); } else { Console.WriteLine("No commands implemented on {0}", commandClass.GetType().Name); } }
/// <summary> /// Registers an IRC Command /// </summary> /// <param name="name"></param> /// <param name="cmd"></param> public void RegisterCommand(string name, IRCCommand cmd) { this.commands.Add(name, cmd); }
private void OutputThreadMethod(TextWriter output) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); _messageDelay = 0; while (ThreadAlive) { try { Thread.Sleep(25); IRCCommand command; if (stopWatch.ElapsedMilliseconds <= _messageDelay && _state == IRCConnectionState.Connected) { continue; } lock (_sendQueue) { if (_sendQueue.Count == 0) { continue; } command = _sendQueue.Dequeue(); } if (command.CommandIsColor() && CurrentColor.Equals(command.GetColor(), StringComparison.InvariantCultureIgnoreCase)) { continue; } output.WriteLine(command.Command); output.Flush(); stopWatch.Reset(); stopWatch.Start(); _messageDelay = _isModerator ? MessageDelayMod : MessageDelayUser; _messageDelay += (command.CommandIsColor() && _isModerator) ? 700 : 0; } catch { AddTextToHoldable("[IRC:Disconnect] Connection failed."); _state = IRCConnectionState.Disconnected; } } MainThreadQueue.Enqueue(() => TwitchGame.EnableDisableInput()); try { if (_state == IRCConnectionState.Disconnecting) { IRCCommand setColor = new IRCCommand($"PRIVMSG #{_settings.channelName} :.color {ColorOnDisconnect}"); if (setColor.CommandIsColor()) { AddTextToHoldable("[IRC:Disconnect] Color {0} was requested, setting it now.", ColorOnDisconnect); while (stopWatch.ElapsedMilliseconds < _messageDelay) { Thread.Sleep(25); } output.WriteLine(setColor.Command); output.Flush(); stopWatch.Reset(); stopWatch.Start(); while (stopWatch.ElapsedMilliseconds < 1200) { Thread.Sleep(25); } } _state = IRCConnectionState.Disconnected; AddTextToHoldable("[IRC:Disconnect] Disconnected from chat IRC."); } lock (_sendQueue) _sendQueue.Clear(); } catch { _state = IRCConnectionState.Disconnected; } MainThreadQueue.Enqueue(() => { if (!gameObject.activeInHierarchy) { AddTextToHoldable("[IRC:Disconnect] Twitch Plays disabled."); } }); }