Example #1
0
 private static void IrcClientOnOnTwitchDataDebugOut(object sender, TwitchEvent twitchEvent)
 {
     if (ConfigFile.GetValue("adv", "debug", false))
     {
         Logger.Debug(twitchEvent.Payload, "Debug");
     }
 }
Example #2
0
        private void IrcClientOnOnTwitchEvent(object sender, TwitchEvent twitchEvent)
        {
            var data = twitchEvent.Payload;
            var message = "";

            var split1 = data.Split(':');
            if (split1.Length > 1)
            {
                //Splitting nick, type, chan and message
                var split2 = split1[1].Split(' ');

                //Nick consists of various things - we only want the nick itself
                var nick = split2[0];
                nick = nick.Split('!')[0];

                //Type = PRIVMSG for normal messages. Only thing we need
                var type = split2[1];

                //Channel posted to
                var channel = split2[2];

                if (split1.Length > 2)
                {
                    for (var i = 2; i < split1.Length; i++)
                    {
                        message += split1[i] + " ";
                    }
                }

                switch (type)
                {
                    case "PRIVMSG":
                        if (channel.StartsWith("#"))
                            if (OnChatHandler != null)
                                OnChatHandler(this, new OnChatEvent(channel, nick, message));
                        Logger.Info(string.Format("{0} -> {1}", nick, message), "Chat");
                        break;
                    case "JOIN":
                        if (channel.StartsWith("#"))
                            if (OnUserJoinHandler != null)
                                OnUserJoinHandler(this, new OnUserJoinEvent(nick, channel));
                        Logger.Info(string.Format("{0} has joined the chat", nick), "Joined Chat");
                        break;
                    case "PART":
                        if (channel.StartsWith("#"))
                            if (OnUserLeftHandler != null)
                                OnUserLeftHandler(this, new OnUserLeftEvent(nick, channel));
                        Logger.Info(string.Format("{0} has left the chat", nick), "Left Chat");
                        break;
                }

                if (message.StartsWith("!"))
                {
                    Command command;
                    Commands.TryGetValue(message.Split(' ')[0], out command);

                    if (command != null)
                    {
                        var args = message.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                        //try
                        //{
                            if (OnCommandHandler != null)
                                OnCommandHandler(this, new OnCommandEvent(command, args, message));

                            command.Run(args, message, channel.TrimStart('#'), nick);
                        /*}
                        catch (Exception ex)
                        {
                            RemoveCommand(command);
                            Logger.Error("Error in Running Command: " + ex, "Plugin Command Error");
                        }*/
                    }
                }
            }
        }