/// <summary> /// /// </summary> /// <param name="e"></param> /// <returns></returns> public bool HandleUserCommand(IRC.ChannelMessageEventArgs e) { if (!e.Message.StartsWith("!")) { return(false); } var sections = e.Message.Split(' '); if (sections[0] == "!help") { foreach (var inst in BotModule.GetAll <IBotModule>()) { foreach (var command in inst.AvailableCommands(this.IRC)) { this.IRC.WriteToChannel( e.Channel, string.Format( " {0} - {1}", command.Key, command.Value)); } } return(true); } foreach (var inst in BotModule.GetAll <IBotModule>()) { var found = false; foreach (var command in inst.AvailableCommands(this.IRC)) { if (sections[0] != "!" + command.Key) { continue; } found = true; break; } if (!found) { continue; } if (inst.HandleUserCommand(this.IRC, e)) { return(true); } } return(false); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void IrcOnChannelMessage(object sender, IRC.ChannelMessageEventArgs e) { // Check for dot-command. if (this.HandleDotCommand(e)) { // Do nothing.. } // Check for user-command. else if (this.HandleUserCommand(e)) { // Do nothing.. } }
/// <summary> /// /// </summary> /// <param name="e"></param> /// <returns></returns> public bool HandleDotCommand(IRC.ChannelMessageEventArgs e) { if (!string.Equals(e.Nickname, Program.Config.Channel) || !e.Message.StartsWith("@" + Program.Config.Nickname)) { return(false); } var message = e.Message .Substring(Program.Config.Nickname.Length + 2) .Trim(); if (!message.StartsWith(".")) { return(false); } var sections = message .Substring(1) .Split(' '); switch (sections[0]) { // Tell the bot to disconnect from IRC and close the app. case "quit": this.IRC.WriteToChannel( e.Channel, string.Format( "@{0} kk thnx bye", e.Nickname)); this.Disconnect(); break; // Unknown dot-command given, give feedback. default: this.IRC.WriteToChannel( e.Channel, string.Format( "@{0} I have no idea what you're talking about..", e.Nickname)); break; } return(true); }