/// <summary> /// Handles the command. /// </summary> /// <param name="source">The source.</param> /// <param name="destination">The destination.</param> /// <param name="command">The command.</param> /// <param name="args">The args.</param> public void handleCommand(User source, string destination, string command, string[] args) { Logger.instance().addToLog("Handling recieved message...", Logger.LogTypes.General); // if on ignore list, ignore! if (source.accessLevel == User.UserRights.Ignored) return; // flip destination over if required if (destination == Helpmebot6.irc.ircNickname) destination = source.nickname; /* * check category codes */ if (WatcherController.instance().isValidKeyword(command)) { int argsLength = GlobalFunctions.realArrayLength(args); string[] newArgs = new string[argsLength + 1]; int newArrayPos = 1; for (int i = 0; i < args.Length; i++) { if (!String.IsNullOrEmpty(args[i])) newArgs[newArrayPos] = args[i]; newArrayPos++; } newArgs[0] = command; string directedTo = findRedirection(destination, ref newArgs); CommandResponseHandler crh = new CategoryWatcher().run(source, destination, newArgs); this.handleCommandResponseHandler(source, destination, directedTo, crh); return; } /* * Check for a valid command * search for a class that can handle this command. */ // Create a new object which holds the type of the command handler, if it exists. // if the command handler doesn't exist, then this won't be set to a value Type commandHandler = Type.GetType("helpmebot6.Commands." + command.Substring(0, 1).ToUpper() + command.Substring(1).ToLower()); // check the type exists if (commandHandler != null) { string directedTo = findRedirection(destination, ref args); // create a new instance of the commandhandler. // cast to genericcommand (which holds all the required methods to run the command) // run the command. CommandResponseHandler response = ((GenericCommand) Activator.CreateInstance(commandHandler)).run( source, destination, args); this.handleCommandResponseHandler(source, destination, directedTo, response); return; } /* * Check for a learned word */ { WordLearner.RemeberedWord rW = WordLearner.remember(command); CommandResponseHandler crh = new CommandResponseHandler(); string wordResponse = rW.phrase; string directedTo = ""; if (wordResponse != String.Empty) { if (source.accessLevel < User.UserRights.Normal) { crh.respond(new Message().get("accessDenied"), CommandResponseDestination.PrivateMessage); string[] aDArgs = {source.ToString(), MethodBase.GetCurrentMethod().Name}; crh.respond(new Message().get("accessDeniedDebug", aDArgs), CommandResponseDestination.ChannelDebug); } else { wordResponse = String.Format(wordResponse, args); if (rW.action) { crh.respond(IAL.wrapCTCP("ACTION", wordResponse)); } else { directedTo = findRedirection(destination, ref args); crh.respond(wordResponse); } this.handleCommandResponseHandler(source, destination, directedTo, crh); } return; } } }
/// <summary> /// Handles the command response handler. /// </summary> /// <param name="source">The source.</param> /// <param name="destination">The destination.</param> /// <param name="directedTo">The directed to.</param> /// <param name="response">The response.</param> private void handleCommandResponseHandler(User source, string destination, string directedTo, CommandResponseHandler response) { if (response != null) { foreach (CommandResponse item in response.getResponses()) { string message = item.message; if (directedTo != String.Empty) { message = directedTo + ": " + message; } switch (item.destination) { case CommandResponseDestination.Default: if (overrideBotSilence || Configuration.singleton()["silence",destination] != "true") { Helpmebot6.irc.ircPrivmsg(destination, message); } break; case CommandResponseDestination.ChannelDebug: Helpmebot6.irc.ircPrivmsg(Helpmebot6.debugChannel, message); break; case CommandResponseDestination.PrivateMessage: Helpmebot6.irc.ircPrivmsg(source.nickname, message); break; } } } }
/// <summary> /// New user from string. /// </summary> /// <param name="source">The source.</param> /// <param name="network">The network.</param> /// <returns></returns> public static User newFromString(string source, uint network) { string user, host; string nick = user = host = null; try { if ((source.Contains("@")) && (source.Contains("!"))) { char[] splitSeparators = {'!', '@'}; string[] sourceSegment = source.Split(splitSeparators, 3); nick = sourceSegment[0]; user = sourceSegment[1]; host = sourceSegment[2]; } else if (source.Contains("@")) { char[] splitSeparators = {'@'}; string[] sourceSegment = source.Split(splitSeparators, 2); nick = sourceSegment[0]; host = sourceSegment[1]; } else { nick = source; } } catch (IndexOutOfRangeException ex) { GlobalFunctions.errorLog(ex); } User ret = new User { hostname = host, nickname = nick, username = user, network = network }; return ret; }
private static void welcomeNewbieOnJoinEvent(User source, string channel) { NewbieWelcomer.instance().execute(source, channel); }
private static void receivedMessage(User source, string destination, string message) { CommandParser cmd = new CommandParser(); try { bool overrideSilence = cmd.overrideBotSilence; if (CommandParser.isRecognisedMessage(ref message, ref overrideSilence)) { cmd.overrideBotSilence = overrideSilence; string[] messageWords = message.Split(' '); string command = messageWords[0]; string[] commandArgs = string.Join(" ", messageWords, 1, messageWords.Length - 1).Split(' '); cmd.handleCommand(source, destination, command, commandArgs); } string aiResponse = Intelligence.singleton().respond(message); if (Configuration.singleton()["silence",destination] == "false" && aiResponse != string.Empty) { string[] aiParameters = {source.nickname}; irc.ircPrivmsg(destination, new Message().get(aiResponse, aiParameters)); } } catch (Exception ex) { GlobalFunctions.errorLog(ex); } }
private static void irc_InviteEvent(User source, string nickname, string channel) { new Join().run(source, nickname, new[] {channel}); }