Example #1
0
        public BotsModule(IRC.Bot ircBot)
        {
            Get["/Bots"] = parameters =>
            {
                BotsModel model = new BotsModel();

                model.Bots.Add(new Web.Models.Bots.Bot()
                {
                    BotID = 1,
                    Errors = 0,
                    IsConnected = true,
                    IsConnecting = false,
                    SiteName = "BTN",
                });

                return View["Index", model];
            };

            Get["/Bots/Connect"] = parameters =>
            {
                string site = "irc.what-network.org";
                int port = 6697;
                bool useSSL = true;
                ircBot.Connect(site, port, useSSL);

                return true;
            };
        }
 void Start () {
     timeStart = 0f;
     resetVote();
     rgx = new Regex("[^a-zA-Z0-9 -]");
     if (twitch == null)
         twitch = gameObject.GetComponent<IRC>();
 }
Example #3
0
 private void btnConnect_Click(object sender, EventArgs e)
 {
     Connection co = new Connection(txtUsername.Text, txtPassword.Text);
     twitch = new IRC(co);
     txtPassword.Text = "";
     this.Name = "Twitch Bot - " + txtUsername;
     saveConnection.SerializeObject(co,co.username);
     saveConnection.SerializeObject(co, "lastConnection");
 }
Example #4
0
 /// <summary>
 /// Connect to network
 /// </summary>
 public static void Connect()
 {
     irc = new IRC(config.network, config.username, config.name, config.name);
     irc.Connect();
 }
Example #5
0
 public IRCPoller(IRC irc)
 {
     this.irc = irc;
 }
Example #6
0
 public void Send(IRC.Messages.Send.PrivateMessage msg)
 {
     Network.Client.Send(msg);
 }
Example #7
0
 public void AddSelf(IRC.Messages.Send.PrivateMessage privateMessage)
 {
     Lines.Add(new ChatLine(Network.Me, privateMessage.Message));
 }
Example #8
0
        private Bot()
        {
            // Load Plugins
            Logger.WriteLine("* Loading Plugins...", ConsoleColor.Green);

            plugins.FindPlugins(Environment.CurrentDirectory + "\\Plugins\\");

            // Load Plugins first
            foreach (AvailablePlugin p in plugins.AvailablePlugins)
            {
                Logger.WriteLine("* Loaded Plugin: " + p.Instance.PluginName + " - v" + p.Instance.Version, ConsoleColor.DarkGreen);
            }

            try
            {
            UserManager = (SBUserPlugin)plugins.AvailablePlugins.FindUserManager().Instance;
                TimeGiver = (SBTimePlugin)plugins.AvailablePlugins.FindTimeGiver().Instance;
            }
            catch (Exception) { }

            if (UserManager == null)
            {
                Logger.WriteLine("**** User Manager: NOT FOUND. Exiting.", ConsoleColor.DarkRed);
                Environment.Exit(1);
            }

            if (TimeGiver == null)
            {
                Logger.WriteLine("**** Timegiver: NOT FOUND.", ConsoleColor.DarkRed);
            }
            else
            {
                Logger.WriteLine("* Timegiver: " + TimeGiver.PluginName, ConsoleColor.Green);
            }

            Logger.WriteLine("* User Manager: " + UserManager.PluginName, ConsoleColor.Green);

            // Initialize plugins later
            foreach (AvailablePlugin p in plugins.AvailablePlugins)
            {
                p.Instance.PluginHost = this;
                Logger.WriteLine("* Started Plugin: " + p.Instance.PluginName + " - v" + p.Instance.Version, ConsoleColor.DarkGreen);
            }

            // Start Service

            Logger.WriteLine("* Starting Bot...", ConsoleColor.DarkYellow);

            IrcService = new IRC(Botname, ServerPassword, "SpawnBot", "Spawnbot", ServerAddress, ServerPort);

            IrcService.eventNameListReceived += new IrcNameListReceived(IrcService_eventNameListReceived);
            IrcService.eventTopicReceived += new IrcTopicReceived(IrcService_eventTopicReceived);
            IrcService.eventTopicOwnerReceived += new IrcTopicOwnerRecevied(IrcService_eventTopicOwnerReceived);

            IrcService.eventUserJoined += new IrcUserJoin(IrcService_eventUserJoined);
            IrcService.eventUserJoinedHostname += new IrcUserJoinHostname(IrcService_eventUserJoinedHostname);
            IrcService.eventUserKicked += new IrcUserKicked(IrcService_eventUserKicked);
            IrcService.eventUserChangedNick += new IrcUserChange(IrcService_eventUserChangedNick);
            IrcService.eventUserModeChanged += new IrcUserMode(IrcService_eventUserModeChanged);
            IrcService.eventUserPart += new IrcUserPart(IrcService_eventUserPart);
            IrcService.eventUserQuit += new IrcUserQuit(IrcService_eventUserQuit);

            IrcService.eventRawBotModeReceived += new IrcRawBotModeGet(IrcService_eventRawBotModeReceived);

            IrcService.eventMessageReceived += new IrcMessage(IrcService_eventMessageReceived);
            IrcService.eventActionReceived += new IrcAction(IrcService_eventActionReceived);
            IrcService.eventNoticeReceived += new IrcNotice(IrcService_eventNoticeReceived);

            IrcService.eventDisconnected += new IrcDisconnected(IrcService_eventDisconnected);
            IrcService.eventConnectingError += new IrcConnectingError(IrcService_eventConnectingError);
            IrcService.eventConnected += new IrcConnected(IrcService_eventConnected);

            IrcService.eventServerPingReceived += new IrcServerPingReceived(IrcService_eventServerPingReceived);
            IrcService.eventServerPongReceived += new IrcServerPongReceived(IrcService_eventServerPongReceived);

            IrcService.eventCommandReceived += new IrcCommandReceived(IrcService_eventCommandReceived);
            IrcService.eventUnhandled += new IrcCommandReceived(IrcService_eventUnhandled);

            Logger.WriteLine("* Connecting to " + IrcService.Server + " on port " + IrcService.Port.ToString(), ConsoleColor.White);
            IrcService.Connect();
        }
Example #9
0
 /*!
  * \brief	set some callback that will receive messages from the server
  * */
 public void setMessageReceiveHandler(IRC.Server.Receive receive)
 {
     m_server.receiveCallback = receive;
 }
Example #10
0
 private void Load_Click(object sender, EventArgs e)
 {
     Connection co = saveConnection.DeSerializeObject("lastConnection");
     twitch = new IRC(co);
     output.Text += "Connected to " + co.username + "\r\n";
 }
Example #11
0
        public void RetrieveStatus2(string nick, Channel channel, string source, bool by_host)
        {
            try
            {
                string response = "I have never seen " + nick;
                bool   found    = false;
                string action   = "quiting the network";
                lock (GlobalList)
                {
                    foreach (item xx in GlobalList)
                    {
                        if ((!by_host && (nick.ToUpper() == xx.nick.ToUpper())) || (by_host && (nick.ToUpper() == xx.hostname.ToUpper())))
                        {
                            found = true;
                            nick  = xx.nick;
                            Channel last;
                            switch (xx.LastAc)
                            {
                            case item.Action.Join:
                                action = "joining the channel";
                                last   = Core.GetChannel(xx.lastplace);
                                if (last != null)
                                {
                                    if (last.ContainsUser(nick))
                                    {
                                        action += ", they are still in the channel";
                                    }
                                    else
                                    {
                                        action += ", but they are not in the channel now and I don't know why, in";
                                    }
                                }
                                break;

                            case item.Action.Kick:
                                action = "kicked from the channel";
                                break;

                            case item.Action.Nick:
                                if (xx.newnick == null)
                                {
                                    action = "error NULL pointer at record";
                                    break;
                                }
                                action = "changing the nickname to " + xx.newnick;
                                last   = Core.GetChannel(xx.lastplace);
                                if (last.ContainsUser(xx.newnick))
                                {
                                    action += " and " + xx.newnick + " is still in the channel";
                                }
                                else
                                {
                                    action += ", but " + xx.newnick + " is no longer in channel";
                                }
                                item nick2 = getItem(xx.newnick);
                                if (nick2 != null)
                                {
                                    TimeSpan span3 = DateTime.Now - nick2.LastSeen;
                                    switch (nick2.LastAc)
                                    {
                                    case item.Action.Exit:
                                        action += " because he quit the network " + span3 + " ago. The nick change was done in";
                                        break;

                                    case item.Action.Kick:
                                        action += " because he was kicked from the channel " + span3 + " ago. The nick change was done in";
                                        break;

                                    case item.Action.Part:
                                        action += " because he left the channel " + span3 + " ago. The nick change was done in";
                                        break;
                                    }
                                }
                                break;

                            case item.Action.Part:
                                action = "leaving the channel";
                                break;

                            case item.Action.Talk:
                                action = "talking in the channel";
                                last   = Core.GetChannel(xx.lastplace);
                                if (last != null)
                                {
                                    if (last.ContainsUser(nick))
                                    {
                                        action += ", they are still in the channel";
                                    }
                                    else
                                    {
                                        action += ", but they are not in the channel now and I don't know why, in";
                                    }
                                }
                                break;

                            case item.Action.Exit:
                                string reason = xx.quit;
                                if (reason == "")
                                {
                                    reason = "no reason was given";
                                }
                                action = "quitting the network with reason: " + reason;
                                break;
                            }
                            TimeSpan span = DateTime.Now - xx.LastSeen;
                            response = "Last time I saw " + nick + " they were " + action + " " + xx.lastplace + " at " + xx.LastSeen + " (" + FormatTimeSpan(span) + " ago)";
                            break;
                        }
                    }
                }
                string target = source;
                if (channel != null)
                {
                    target = channel.Name;
                }
                if (!by_host && nick.ToUpper() == source.ToUpper())
                {
                    response = "are you really looking for yourself?";
                    IRC.DeliverMessage(source + ": " + response, target);
                    return;
                }
                if (!by_host && nick.ToUpper() == Configuration.IRC.NickName.ToUpper())
                {
                    response = "I am right here";
                    IRC.DeliverMessage(source + ": " + response, target);
                    return;
                }
                if (!by_host && channel != null)
                {
                    if (channel.ContainsUser(nick))
                    {
                        response = nick + " is in here, right now";
                        found    = true;
                    }
                }
                if (!by_host && !found)
                {
                    foreach (Channel Item in Configuration.ChannelList)
                    {
                        if (Item.ContainsUser(nick))
                        {
                            response = nick + " is in " + Item.Name + " right now";
                            break;
                        }
                    }
                }
                IRC.DeliverMessage(source + ": " + response, target);
            }
            catch (Exception fail)
            {
                HandleException(fail);
            }
        }
Example #12
0
        public void Search()
        {
            try
            {
                if (misc.IsValidRegex(temp_nick))
                {
                    Regex  ex       = new Regex(temp_nick);
                    string response = "I have never seen " + temp_nick;
                    bool   found    = false;
                    bool   multiple = false;
                    string results  = "";
                    int    cn       = 0;
                    string action   = "quitting the network with reason ";
                    lock (GlobalList)
                    {
                        foreach (item xx in GlobalList)
                        {
                            if (ex.IsMatch(xx.nick))
                            {
                                if (found)
                                {
                                    cn++;
                                    if (cn < 6)
                                    {
                                        results += xx.nick + ", ";
                                    }
                                    multiple = true;
                                    continue;
                                }
                                found = true;
                                Channel last;
                                switch (xx.LastAc)
                                {
                                case item.Action.Join:
                                    action = "joining the channel";
                                    last   = Core.GetChannel(xx.lastplace);
                                    if (last != null)
                                    {
                                        if (last.ContainsUser(xx.nick))
                                        {
                                            action += ", they are still in the channel";
                                        }
                                        else
                                        {
                                            action += ", but they are not in the channel now and I don't know why, in";
                                        }
                                    }
                                    break;

                                case item.Action.Kick:
                                    action = "kicked from the channel";
                                    break;

                                case item.Action.Nick:
                                    if (xx.newnick == null)
                                    {
                                        action = "error NULL pointer at record";
                                    }
                                    else
                                    {
                                        action = "changing the nickname to " + xx.newnick;
                                        last   = Core.GetChannel(xx.lastplace);
                                        if (last.ContainsUser(xx.newnick))
                                        {
                                            action += " and " + xx.newnick + " is still in the channel";
                                        }
                                        else
                                        {
                                            action += ", but " + xx.newnick + " is no longer in channel";
                                        }
                                        item nick = getItem(xx.newnick);
                                        if (nick != null)
                                        {
                                            TimeSpan span3 = DateTime.Now - nick.LastSeen;
                                            switch (nick.LastAc)
                                            {
                                            case item.Action.Exit:
                                                action += " because he quit the network " + span3 + " ago. The nick change was done in";
                                                break;

                                            case item.Action.Kick:
                                                action += " because he was kicked from the channel " + span3 + " ago. The nick change was done in";
                                                break;

                                            case item.Action.Part:
                                                action += " because he left the channel " + span3 + " ago. The nick change was done in";
                                                break;
                                            }
                                        }
                                    }
                                    break;

                                case item.Action.Part:
                                    action = "leaving the channel";
                                    break;

                                case item.Action.Talk:
                                    action = "talking in the channel";
                                    last   = Core.GetChannel(xx.lastplace);
                                    if (last != null)
                                    {
                                        if (last.ContainsUser(xx.nick))
                                        {
                                            action += ", they are still in the channel. It was in";
                                        }
                                        else
                                        {
                                            action += ", but they are not in the channel now and I don't know why. It was in";
                                        }
                                    }
                                    break;

                                case item.Action.Exit:
                                    string reason = xx.quit;
                                    if (String.IsNullOrEmpty(reason))
                                    {
                                        reason = "no reason was given";
                                    }
                                    action = "quitting the network with reason: " + reason;
                                    break;
                                }
                                TimeSpan span2 = DateTime.Now - xx.LastSeen;
                                if (xx.lastplace == null)
                                {
                                    xx.lastplace = "N/A";
                                }
                                if (xx.LastAc == item.Action.Exit)
                                {
                                    response = "Last time I saw " + xx.nick + " they were " + action + " at " + xx.LastSeen + " (" + FormatTimeSpan(span2) + " ago)";
                                }
                                else
                                {
                                    response = "Last time I saw " + xx.nick + " they were " + action + " " + xx.lastplace + " at " + xx.LastSeen + " (" + FormatTimeSpan(span2) + " ago)";
                                }
                            }
                        }
                    }
                    if (temp_nick.ToUpper() == temp_source.ToUpper())
                    {
                        response = "are you really looking for yourself?";
                        IRC.DeliverMessage(temp_source + ": " + response, chan.Name);
                        Working = false;
                        goto ex;
                    }
                    if (temp_nick.ToUpper() == Configuration.IRC.NickName.ToUpper())
                    {
                        response = "I am right here";
                        IRC.DeliverMessage(temp_source + ": " + response, chan.Name);
                        Working = false;
                        goto ex;
                    }
                    if (chan.ContainsUser(temp_nick))
                    {
                        response = temp_nick + " is in here, right now";
                    }
                    if (multiple)
                    {
                        if (results.Length > 2)
                        {
                            results = results.Substring(0, results.Length - 2);
                        }
                        if (cn > 5)
                        {
                            results = results + " and " + (cn - 5) + " more results";
                        }
                        response += " (multiple results were found: " + results + ")";
                    }
                    IRC.DeliverMessage(temp_source + ": " + response, chan.Name);
                    Working = false;
                    goto ex;
                }
                IRC.DeliverMessage(messages.Localize("Error1", chan.Language), chan.Name);
                Working = false;
            }
            catch (ThreadAbortException)
            {
                goto ex;
            }
            catch (Exception fail)
            {
                HandleException(fail);
                IsWorking = false;
            }
ex:
            Core.ThreadManager.UnregisterThread(SearchThread);
        }
Example #13
0
            void HandleMessage([NotNull] string message)
            {
                if (message == null)
                {
                    throw new ArgumentNullException("message");
                }

                IRCMessage msg      = IRC.MessageParser(message, ActualBotNick);
                var        SendList = Server.Players.Where(p => !p.IsDeaf && !p.GlobalChatIgnore);

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

                switch (msg.Type)
                {
                case IRCMessageType.Login:
                    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;
                    }
                    string processedMessage = msg.Message;
                    if (msg.Type == IRCMessageType.ChannelAction)
                    {
                        if (processedMessage.StartsWith("\u0001ACTION"))
                        {
                            processedMessage = processedMessage.Substring(8);
                        }
                        else
                        {
                            return;
                        }
                    }

                    processedMessage = IRC.NonPrintableChars.Replace(processedMessage, "");
                    if (processedMessage.Length > 0)
                    {
                        if (msg.Type == IRCMessageType.ChannelAction)
                        {
                            SendList.Message("&g[Global] * {1} {2}", 0, ActualBotNick, msg.Nick, processedMessage);
                            Logger.Log(LogType.GlobalChat, "[Global] * {1} {2}", ActualBotNick, msg.Nick, processedMessage);
                        }
                        else
                        {
                            SendList.Message("&g[Global] {1}: {2}", 0, ActualBotNick, msg.Nick, processedMessage);
                            Logger.Log(LogType.GlobalChat, "[Global] {1}: {2}", ActualBotNick, msg.Nick, processedMessage);
                        }
                    }

                    else if (msg.Message.StartsWith("#"))
                    {
                        SendList.Message("&g[Global] {1}: {2}", 0, ActualBotNick, msg.Nick, processedMessage.Substring(1));
                        Logger.Log(LogType.GlobalChat, "[Global] {1}: {2}", ActualBotNick, msg.Nick, processedMessage.Substring(1));
                    }
                    return;


                case IRCMessageType.Join:
                    if (!ResponsibleForInputParsing)
                    {
                        return;
                    }
                    if (msg.Nick.StartsWith("("))
                    {
                        SendList.Message("&g[Global] Server {0} joined the GemsCraft Global Chat", 0, msg.Nick);
                        Logger.Log(LogType.GlobalChat, "[Global] Server {0} joined the GemsCraft Global Chat", msg.Nick);
                    }
                    else
                    {
                        SendList.Message("&g[Global] {0} joined the GemsCraft Global Chat", 0, msg.Nick);
                        Logger.Log(LogType.GlobalChat, "[Global] {0} joined the GemsCraft Global Chat", msg.Nick);
                    }
                    return;


                case IRCMessageType.Kick:
                    string kicked = msg.RawMessageArray[3];
                    if (kicked == ActualBotNick)
                    {
                        Logger.Log(LogType.SystemActivity, "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;
                        }
                        SendList.Message("&g[Global] {0} kicked {1} ({2})", 0, msg.Nick, kicked, msg.Message);
                        Logger.Log(LogType.GlobalChat, "[Global] {0} kicked {1} ({2})", msg.Nick, kicked, msg.Message);
                    }
                    return;


                case IRCMessageType.Part:
                case IRCMessageType.Quit:
                    if (!ResponsibleForInputParsing)
                    {
                        return;
                    }
                    SendList.Message("&g[Global] Server {0} left the GemsCraft Global Chat", MessageType.Chat, msg.Nick);
                    Logger.Log(LogType.GlobalChat, "[Global] Server {0} left the GemsCraft Global Chat", msg.Nick);
                    return;


                case IRCMessageType.NickChange:
                    if (!ResponsibleForInputParsing)
                    {
                        return;
                    }
                    SendList.Message("&g[Global] {0} is now known as {1}", 0, msg.Nick, msg.Message);
                    Logger.Log(LogType.GlobalChat, "[Global] {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:
                        ActualBotNick = ActualBotNick.Remove(ActualBotNick.Length - 4) + "_";
                        Logger.Log(LogType.SystemActivity,
                                   "Error: Global Chat Nickname is already in use. Trying \"{0}\"",
                                   ActualBotNick);
                        Send(IRCCommands.Nick(ActualBotNick));
                        break;

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

                    //wont happen
                    case IRCReplyCode.ErrorBadChannelKey:
                        Logger.Log(LogType.SystemActivity,
                                   "Error: Channel password required for {0}. GemsCraft does not currently support passworded channels.",
                                   msg.Channel);
                        die     = true;
                        GCReady = false;
                        break;

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

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

                    return;


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


                case IRCMessageType.Kill:
                    Logger.Log(LogType.SystemActivity,
                               "Bot was killed from {0} by {1} ({2}), reconnecting.",
                               hostName, msg.Nick, msg.Message);
                    reconnect   = true;
                    isConnected = false;
                    return;
                }
            }
Example #14
0
 public Utilities(IRC _irc) : base(_irc)
 {
     moduleName = "Bot.Modules.HelloWorld.Utilities";
     base.addId("!uptime");
     base.addId("!viewers");
 }
Example #15
0
        private void time(CommandParams p)
        {
            DateTime time = DateTime.UtcNow;

            IRC.DeliverMessage(p.User.Nick + ": It is is " + time + " UTC", p.SourceChannel);
        }