Privmsg() public static méthode

public static Privmsg ( string destination, string message ) : string
destination string
message string
Résultat string
Exemple #1
0
 public static void SendChannelMessage([NotNull] string line)
 {
     if (line == null)
     {
         throw new ArgumentNullException("line");
     }
     line = Color.MinecraftToIrcColors(line);
     if (_channelName == null || !GcReady)
     {
         return; // in case IRC bot is disabled.
     }
     SendRawMessage(IRCCommands.Privmsg(_channelName, line));
 }
Exemple #2
0
 public static void SendChannelMessage([NotNull] string line)
 {
     if (line == null)
     {
         throw new ArgumentNullException("line");
     }
     line = Color.MinecraftToIrcColors(line);
     if (channelNames == null || !GCReady)
     {
         return; // in case IRC bot is disabled.
     }
     for (int i = 0; i < channelNames.Length; i++)
     {
         SendRawMessage(IRCCommands.Privmsg(channelNames[i], line));
     }
 }
Exemple #3
0
 public static void SendChannelMessage([NotNull] string line)
 {
     if (line == null)
     {
         throw new ArgumentNullException("line");
     }
     if (channelNames == null)
     {
         return;                        // in case IRC bot is disabled.
     }
     if (ConfigKey.IRCUseColor.Enabled())
     {
         line = Color.ToIRCColorCodes(line);
     }
     else
     {
         line = NonPrintableChars.Replace(line, "").Trim();
     }
     for (int i = 0; i < channelNames.Length; i++)
     {
         SendRawMessage(IRCCommands.Privmsg(channelNames[i], line));
     }
 }
Exemple #4
0
            void HandleMessage([NotNull] string message)
            {
                if (message == null)
                {
                    throw new ArgumentNullException("message");
                }

                IRCMessage msg = MessageParser(message, ActualBotNick);

#if DEBUG_IRC
                Logger.Log(LogType.IRC,
                           "[{0}]: {1}",
                           msg.Type, msg.RawMessage);
#endif

                switch (msg.Type)
                {
                case IRCMessageType.Login:
                    if (ConfigKey.IRCRegisteredNick.Enabled())
                    {
                        Send(IRCCommands.Privmsg(ConfigKey.IRCNickServ.GetString(),
                                                 ConfigKey.IRCNickServMessage.GetString()));
                    }
                    foreach (string channel in channelNames)
                    {
                        Send(IRCCommands.Join(channel));
                    }
                    IsReady = true;
                    AssignBotForInputParsing();     // bot should be ready to receive input after joining
                    return;


                case IRCMessageType.Ping:
                    // ping-pong
                    Send(IRCCommands.Pong(msg.RawMessageArray[1].Substring(1)));
                    return;


                case IRCMessageType.ChannelAction:
                case IRCMessageType.ChannelMessage:
                    // channel chat
                    if (!ResponsibleForInputParsing)
                    {
                        return;
                    }
                    if (!IsBotNick(msg.Nick))
                    {
                        string processedMessage = msg.Message;
                        if (msg.Type == IRCMessageType.ChannelAction)
                        {
                            if (processedMessage.StartsWith("\u0001ACTION"))
                            {
                                processedMessage = processedMessage.Substring(8);
                            }
                            else
                            {
                                return;
                            }
                        }
                        processedMessage = NonPrintableChars.Replace(processedMessage, "");
                        if (processedMessage.Length > 0)
                        {
                            if (ConfigKey.IRCBotForwardFromIRC.Enabled())
                            {
                                if (msg.Type == IRCMessageType.ChannelAction)
                                {
                                    Server.Message("&i(IRC) * {0} {1}",
                                                   msg.Nick, processedMessage);
                                }
                                else
                                {
                                    Server.Message("&i(IRC) {0}{1}: {2}",
                                                   msg.Nick, Color.White, processedMessage);
                                }
                            }
                            else if (msg.Message.StartsWith("#"))
                            {
                                Server.Message("&i(IRC) {0}{1}: {2}",
                                               msg.Nick, Color.White, processedMessage.Substring(1));
                            }
                        }
                    }
                    return;


                case IRCMessageType.Join:
                    if (!ResponsibleForInputParsing)
                    {
                        return;
                    }
                    if (ConfigKey.IRCBotAnnounceIRCJoins.Enabled())
                    {
                        Server.Message("&i(IRC) {0} joined {1}",
                                       msg.Nick, msg.Channel);
                    }
                    return;


                case IRCMessageType.Kick:
                    string kicked = msg.RawMessageArray[3];
                    if (kicked == ActualBotNick)
                    {
                        Logger.Log(LogType.IRC,
                                   "Bot was kicked from {0} by {1} ({2}), rejoining.",
                                   msg.Channel, msg.Nick, msg.Message);
                        Thread.Sleep(ReconnectDelay);
                        Send(IRCCommands.Join(msg.Channel));
                    }
                    else
                    {
                        if (!ResponsibleForInputParsing)
                        {
                            return;
                        }
                        Server.Message("&i(IRC) {0} kicked {1} from {2} ({3})",
                                       msg.Nick, kicked, msg.Channel, msg.Message);
                    }
                    return;


                case IRCMessageType.Part:
                case IRCMessageType.Quit:
                    if (!ResponsibleForInputParsing)
                    {
                        return;
                    }
                    if (ConfigKey.IRCBotAnnounceIRCJoins.Enabled())
                    {
                        Server.Message("&i(IRC) {0} left {1}",
                                       msg.Nick, msg.Channel);
                    }
                    return;


                case IRCMessageType.NickChange:
                    if (!ResponsibleForInputParsing)
                    {
                        return;
                    }
                    Server.Message("&i(IRC) {0} is now known as {1}",
                                   msg.Nick, msg.Message);
                    return;


                case IRCMessageType.ErrorMessage:
                case IRCMessageType.Error:
                    bool die = false;
                    switch (msg.ReplyCode)
                    {
                    case IRCReplyCode.ErrorNicknameInUse:
                    case IRCReplyCode.ErrorNicknameCollision:
                        Logger.Log(LogType.IRC,
                                   "Error: Nickname \"{0}\" is already in use. Trying \"{0}_\"",
                                   ActualBotNick);
                        ActualBotNick += "_";
                        Send(IRCCommands.Nick(ActualBotNick));
                        break;

                    case IRCReplyCode.ErrorBannedFromChannel:
                    case IRCReplyCode.ErrorNoSuchChannel:
                        Logger.Log(LogType.IRC,
                                   "Error: {0} ({1})",
                                   msg.ReplyCode, msg.Channel);
                        die = true;
                        break;

                    case IRCReplyCode.ErrorBadChannelKey:
                        Logger.Log(LogType.IRC,
                                   "Error: Channel password required for {0}. fCraft does not currently support passworded channels.",
                                   msg.Channel);
                        die = true;
                        break;

                    default:
                        Logger.Log(LogType.IRC,
                                   "Error ({0}): {1}",
                                   msg.ReplyCode, msg.RawMessage);
                        break;
                    }

                    if (die)
                    {
                        Logger.Log(LogType.IRC, "Error: Disconnecting.");
                        reconnect = false;
                        DisconnectThread();
                    }

                    return;


                case IRCMessageType.QueryAction:
                    // TODO: PMs
                    Logger.Log(LogType.IRC,
                               "Query: {0}", msg.RawMessage);
                    break;


                case IRCMessageType.Kill:
                    Logger.Log(LogType.IRC,
                               "Bot was killed from {0} by {1} ({2}), reconnecting.",
                               hostName, msg.Nick, msg.Message);
                    reconnect   = true;
                    isConnected = false;
                    return;
                }
            }
Exemple #5
0
            void HandleMessage([NotNull] string message)
            {
                if (message == null)
                {
                    throw new ArgumentNullException("message");
                }

                IRCMessage msg = MessageParser(message, ActualBotNick);

#if DEBUG_IRC
                Logger.Log(LogType.IRC,
                           "[{0}]: {1}",
                           msg.Type, msg.RawMessage);
#endif

                switch (msg.Type)
                {
                case IRCMessageType.Login:
                    if (ConfigKey.IRCRegisteredNick.Enabled())
                    {
                        Send(IRCCommands.Privmsg(ConfigKey.IRCNickServ.GetString(),
                                                 ConfigKey.IRCNickServMessage.GetString()));
                    }
                    foreach (string channel in channelNames)
                    {
                        if (ConfigKey.IRCChannelPassword.GetString() != "password")
                        {
                            Send(IRCCommands.Join(channel + " " + ConfigKey.IRCChannelPassword.GetString()));
                        }
                        else
                        {
                            Send(IRCCommands.Join(channel));
                        }
                    }
                    IsReady = true;
                    AssignBotForInputParsing();     // bot should be ready to receive input after joining
                    return;


                case IRCMessageType.Ping:
                    // ping-pong
                    Send(IRCCommands.Pong(msg.RawMessageArray[1].Substring(1)));
                    return;


                case IRCMessageType.ChannelAction:
                case IRCMessageType.ChannelMessage:
                    // channel chat
                    if (!ResponsibleForInputParsing)
                    {
                        return;
                    }
                    if (!IsBotNick(msg.Nick))
                    {
                        string processedMessage = msg.Message;
                        if (msg.Type == IRCMessageType.ChannelAction)
                        {
                            if (processedMessage.StartsWith("\u0001ACTION"))
                            {
                                processedMessage = processedMessage.Substring(8);
                            }
                            else
                            {
                                return;
                            }
                        }
                        processedMessage = NonPrintableChars.Replace(processedMessage, "");
                        if (processedMessage.Length > 0)
                        {
                            if (ConfigKey.IRCBotForwardFromIRC.Enabled())
                            {
                                if (msg.Type == IRCMessageType.ChannelAction)
                                {
                                    Server.Message("&i(IRC) * {0} {1}",
                                                   msg.Nick, processedMessage);
                                    Logger.Log(LogType.IRC, "(IRC) * {0} {1}",
                                               msg.Nick, processedMessage);
                                }
                                else
                                {
                                    Server.Message("&i(IRC) {0}{1}: {2}",
                                                   msg.Nick, Color.White, processedMessage);
                                    Logger.Log(LogType.IRC, "(IRC) {0}: {1}",
                                               msg.Nick, processedMessage);
                                }
                            }
                            else if (msg.Message.StartsWith("#"))
                            {
                                Server.Message("&i(IRC) {0}{1}: {2}",
                                               msg.Nick, Color.White, processedMessage.Substring(1));
                                Logger.Log(LogType.IRC, "(IRC) {0}: {1}",
                                           msg.Nick, processedMessage.Substring(1));
                            }
                        }
                    }
                    return;


                case IRCMessageType.Join:
                    if (!ResponsibleForInputParsing)
                    {
                        return;
                    }
                    if (ConfigKey.IRCBotAnnounceIRCJoins.Enabled())
                    {
                        Server.Message("&i(IRC) {0} joined {1}",
                                       msg.Nick, msg.Channel);
                    }
                    return;


                case IRCMessageType.Kick:
                    string kicked = msg.RawMessageArray[3];
                    if (kicked == ActualBotNick)
                    {
                        Logger.Log(LogType.IRC,
                                   "Bot was kicked from {0} by {1} ({2}), rejoining.",
                                   msg.Channel, msg.Nick, msg.Message);
                        Thread.Sleep(ReconnectDelay);
                        Send(IRCCommands.Join(msg.Channel));
                    }
                    else
                    {
                        if (!ResponsibleForInputParsing)
                        {
                            return;
                        }
                        Server.Message("&i(IRC) {0} kicked {1} from {2} ({3})",
                                       msg.Nick, kicked, msg.Channel, msg.Message);
                    }
                    return;


                case IRCMessageType.Part:
                case IRCMessageType.Quit:
                    if (!ResponsibleForInputParsing)
                    {
                        return;
                    }
                    if (ConfigKey.IRCBotAnnounceIRCJoins.Enabled())
                    {
                        Server.Message("&i(IRC) {0} left {1}",
                                       msg.Nick, msg.Channel);
                    }
                    return;


                case IRCMessageType.NickChange:
                    if (!ResponsibleForInputParsing)
                    {
                        return;
                    }
                    Server.Message("&i(IRC) {0} is now known as {1}",
                                   msg.Nick, msg.Message);
                    return;

                case IRCMessageType.ErrorMessage:
                case IRCMessageType.Error:
                    bool die = false;
                    switch (msg.ReplyCode)
                    {
                    case IRCReplyCode.ErrorNicknameInUse:
                    case IRCReplyCode.ErrorNicknameCollision:
                        Logger.Log(LogType.IRC,
                                   "Error: Nickname \"{0}\" is already in use. Trying \"{0}_\"",
                                   ActualBotNick);
                        ActualBotNick += "_";
                        Send(IRCCommands.Nick(ActualBotNick));
                        break;

                    case IRCReplyCode.ErrorPasswordMismatch:
                        if (triedPass)
                        {
                            Logger.Log(LogType.IRC, "Could not connect with irc server password. Please configure your correct irc server password in the ConfigGUI.");
                            die = true;
                            break;
                        }
                        if (ConfigKey.IRCBotNetworkPass.GetString() == "defaultPass")
                        {
                            Logger.Log(LogType.IRC, "Requested irc server is password-locked. Please set your irc server password in the ConfigGUI.");
                            break;
                        }
                        Logger.Log(LogType.IRC, "Requested irc server is password-locked, attempting to connect with " + ConfigKey.IRCBotNetworkPass.GetString());

                        //give the irc client a second to prompt for password before sending
                        Scheduler.NewTask(t => SendChannelMessage("/pass " + ConfigKey.IRCBotNetworkPass.GetString())).RunManual(TimeSpan.FromSeconds(2));
                        triedPass = true;

                        break;

                    case IRCReplyCode.ErrorBannedFromChannel:
                    case IRCReplyCode.ErrorNoSuchChannel:
                        Logger.Log(LogType.IRC,
                                   "Error: {0} ({1})",
                                   msg.ReplyCode, msg.Channel);
                        die = true;
                        break;

                    default:
                        Logger.Log(LogType.IRC,
                                   "Error ({0}): {1}",
                                   msg.ReplyCode, msg.RawMessage);
                        break;
                    }

                    if (die)
                    {
                        Logger.Log(LogType.IRC, "Error: Disconnecting.");
                        reconnect = false;
                        DisconnectThread();
                    }

                    return;


                case IRCMessageType.QueryAction:
                    // TODO: PMs
                    Logger.Log(LogType.IRC,
                               "Query: {0}", msg.RawMessage);
                    break;


                case IRCMessageType.Kill:
                    Logger.Log(LogType.IRC,
                               "Bot was killed from {0} by {1} ({2}), reconnecting.",
                               hostName, msg.Nick, msg.Message);
                    reconnect   = true;
                    isConnected = false;
                    return;
                }
            }