コード例 #1
0
ファイル: script.cs プロジェクト: nebez/TwitchBot
        public void onChatMessage(Channel channel, User sender, string message)
        {
            if(message.IndexOf('!') == 0)
            {
                string[] split = message.Split(new char[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
                string command = split[0].Substring(1);
                string payload = "";

                if(split.Length > 1)
                {
                    payload = split[1];
                }

                handleCommand(command, payload, sender, channel);
            }
        }
コード例 #2
0
ファイル: Bot.cs プロジェクト: nebez/TwitchBot
        public Channel JoinChannel(string channel)
        {
            if (channel.IndexOf('#') != 0)
            {
                channel = "#" + channel;
            }

            if (ircConnection.Connected)
            {
                //Join the channel
                Logger.Log.Write("Joining " + channel + "...", ConsoleColor.DarkGray);
                ircConnection.Sender.Join(channel, true);


                if (GetChannelByName(channel) != null)
                {
                    //Whoa! We already exist?
                    Logger.Log.Write("Channel " + channel + " exists already?");
                    return GetChannelByName(channel);
                }

                Channel newchannel = new Channel(channel, this);

                //Now make a user object for ourself. We're still a user, are we not?
                User me = new User(ircArgs.Nick, newchannel);
                newchannel.botuser = me;

                //Add this channel to watch!
                channels.Add(newchannel);

                return newchannel;
            }
            else
            {
                Logger.Log.Write("Unable to join channel without a connection");
                return null;
            }
        }
コード例 #3
0
ファイル: Bot.cs プロジェクト: nebez/TwitchBot
        public void OnJTVCommand(Channel chan, string command)
        {
            User target;

            //What kind of command was this?
            string[] split = command.Split(' ');

            string cmd = split[0].ToLower();

            if (cmd == "specialuser")
            {
                //Does this user even exist?
                if (!chan.UserExists(split[1]))
                    //Nope, let's make a user object
                    target = new User(split[1], chan);
                else
                    target = chan.GetUser(split[1]);

                //What kind of specialuser are they?
                string perm = split[2].ToLower();

                if (perm == "subscriber")
                    target.AddPermission(User.PermissionLevel.Subscriber);
                else if (perm == "turbo")
                    target.AddPermission(User.PermissionLevel.Turbo);
                else if (perm == "admin")
                    target.AddPermission(User.PermissionLevel.Admin);
                else if (perm == "staff")
                    target.AddPermission(User.PermissionLevel.Staff);
                else
                    Logger.Log.Write("UNHANDLED SPECIALUSER: "******"usercolor")
            {
                //Set the chat color of a specific user

                //Does this user even exist?
                if (!chan.UserExists(split[1]))
                    //Nope, let's make a user object
                    target = new User(split[1], chan);
                else
                    target = chan.GetUser(split[1]);

                target.SetUserColor(split[2]);
            }

            else if (cmd == "clearchat")
            {
                //Was a target specified?
                if (split.Count() == 2)
                {
                    //We need to clear a certain users chat!
                    //TODO: DO SOMETHING HERE
                    Logger.Log.Write("USER CHAT CLEARED: " + split[1]);
                }
                else
                {
                    //Entire chat cleared!
                    //TODO: DO SOMETHING HERE
                    Logger.Log.Write("Chat history cleared");
                }
            }

            else if (cmd == "emoteset")
            {
                //Set the emotes for a specific user
                //TODO: figure out what this crap is for. We'll just ignore it for now, seems like a waste.
            }

                //Slowmode and sub mode are weird, they send entire sentences instead of commands.
                //We'll keep them unhandled for now... it'd be really ugly to program this.

                //TODO: Slow mode on/off
                //TODO: Sub mode on/off

            else
            {
                Logger.Log.Write("Unhandled JTV command: " + command, ConsoleColor.Yellow);
            }
        }
コード例 #4
0
ファイル: Bot.cs プロジェクト: nebez/TwitchBot
        public void OnChannelModeChange(UserInfo who, string channel, ChannelModeInfo[] modes)
        {
            Channel tempchan = GetChannelByName(channel);

            //What kind of modes are we applying
            foreach (ChannelModeInfo c in modes)
            {
                User.PermissionLevel permission;
                //What kind of permission?
                if (c.Mode == ChannelMode.ChannelOperator)
                    permission = User.PermissionLevel.Mod;
                else
                {
                    //WHOA!
                    Logger.Log.Write("UNHANDLED PERMISSION MODE CHANGE: " + c.ToString(), ConsoleColor.Yellow);
                    return;
                }

                //Who is the target?

                User target;
                if (!tempchan.UserExists(c.Parameter))
                    target = new User(c.Parameter, tempchan);
                else
                    target = tempchan.GetUser(c.Parameter);

                //Are we adding or removing?
                if (c.Action == ModeAction.Add)
                {
                    Logger.Log.Write(channel + " +o " + target.Nickname, ConsoleColor.DarkCyan);
                    target.AddPermission(permission);
                }
                else
                {
                    Logger.Log.Write(channel + " -o " + target.Nickname, ConsoleColor.DarkRed);
                    target.RemovePermission(permission);
                }
            }
        }
コード例 #5
0
ファイル: Bot.cs プロジェクト: nebez/TwitchBot
        public void OnTwitchNotification(Channel channel, string notification)
        {
            //This is a twitch chat notification for a specific channel!
            //What kind of notification is it? Let's parse!
            if (notification.ToLower().Contains("just subscribed"))
            {
                //It's a subscription!
                string subscriber = notification.Split(new string[] {" just"}, StringSplitOptions.None).First();

                //is this person a subscriber?
                User target;
                if (!channel.UserExists(subscriber))
                    //make a new user!
                    target = new User(subscriber, channel);
                else
                    target = channel.GetUser(subscriber);

                //Pass it off to the relevant handler in our script
                Scripting.Script.onNewSubscriber(channel, target);
                return;
            }
            else
            {
                Logger.Log.Write("UNHANDLED TWITCH NOTIFICATION: " + channel.name + ":" + notification, ConsoleColor.Yellow);
            }
        }
コード例 #6
0
ファイル: Bot.cs プロジェクト: nebez/TwitchBot
        public void OnPublic(UserInfo user, string channel, string message)
        {
            //Got a public message!
            Channel tempchan = GetChannelByName(channel);
            User sender;

            //Quickly! Is it a twitch notification? We handle those elsewhere!
            if (user.Nick.ToLower().Equals("twitchnotify"))
            {
                //Trigger the proper event and get outta here
                OnTwitchNotification(tempchan, message);
                return;
            }

            //or maybe it's the new TWITCHCLIENT 3 jtv commands
            if (user.Nick.ToLower().Equals("jtv"))
            {
                //yep, handle it elsewhere!
                OnJTVCommand(tempchan, message);
                return;
            }

            if (user.Nick.ToLower().Equals("nebezb") && message.Equals("!recompile"))
            {
                Logger.Log.Write("Recompiling bot script...", ConsoleColor.DarkGray);
                try
                {
                    var tmp = CSScript.Evaluator.LoadFile<Interfaces.IScript>("./script.cs");
                    Scripting.Script = tmp;
                    // ERROR RIGHT HERE.
                    Logger.Log.Write("Successfully recompiled bot script!", ConsoleColor.DarkGreen);
                }
                catch (Exception ex)
                {
                    Logger.Log.Write("Error recompiling script! " + ex.ToString(), ConsoleColor.Red);
                }
                return;
            }

            //Do we have this user object already?
            if (!tempchan.UserExists(user.Nick))
                //Nope, let's make a user object for this channel
                sender = new User(user.Nick, tempchan);
            else
                sender = tempchan.GetUser(user.Nick);

            //Increase their message count
            sender.MessagesSent++;

            //Increase the channels message count
            tempchan.messagesReceived++;

            //Log it!
            Logger.Log.Write(sender.Channel.name + ":" + sender.Nickname + "> " + message);

            //Send this off to our script
            Scripting.Script.onChatMessage(tempchan, sender, message);
        }
コード例 #7
0
ファイル: Bot.cs プロジェクト: nebez/TwitchBot
        private void OnAction(UserInfo user, string channel, string description)
        {
            //Got an action message. Log it and pass it off to the script
            Channel tempchan = GetChannelByName(channel);
            User sender;

            //Do we have this user object already?
            if (!tempchan.UserExists(user.Nick))
                //Nope, let's make a user object for this channel
                sender = new User(user.Nick, tempchan);
            else
                sender = tempchan.GetUser(user.Nick);

            //Increase their message count
            sender.MessagesSent++;

            //Increase the channels message count
            tempchan.messagesReceived++;

            //Log it!
            Logger.Log.Write(sender.Channel.name + ":" + sender.Nickname + " " + description, ConsoleColor.DarkYellow);

            //Send this off to our script
            Scripting.Script.onUserAction(tempchan, sender, description);
        }
コード例 #8
0
ファイル: script.cs プロジェクト: nebez/TwitchBot
 private void handleCommand(string command, string payload, User sender, Channel channel)
 {
     switch(command)
     {
         case "chat":
         case "subs":
         case "plebs":
             spammerino(command, channel);
             break;
         case "me":
             spammerino(sender.Nickname, channel);
             break;
         case "hi":
             if (payload.ToLower().Contains("nebez"))
             {
                 spammerino(sender.Nickname, channel, true);
             }
             else
             {
                 spammerino(payload, channel);
             }
             break;
         case "repeat":
             channel.SendMessage(payload);
             break;
         case "shutdown":
             if(sender.Nickname.ToLower().Equals("nebezb"))
             {
                 channel.SendMessage("goodbye Kappa");
                 bot.Stop();
             }
             break;
         case "join":
             if(sender.Nickname.ToLower().Equals("nebezb"))
             {
                 bot.JoinChannel(payload);
             }
             break;
         case "leave":
             if(sender.Nickname.ToLower().Equals("nebezb"))
             {
                 if (payload.Length > 0)
                     bot.LeaveChannel(payload);
                 else
                     bot.LeaveChannel(channel.name);
             }
             break;
         case "spammerino":
             if(sender.Nickname.ToLower().Equals("nebezb"))
             {
                 spammerinoMessage = payload;
                 channel.SendMessage("Kappa");
             }
             break;
         case "channels":
             if(sender.Nickname.ToLower().Equals("nebezb"))
             {
                 channel.SendMessage(String.Join(", ", bot.channels.Select(c => c.name)));
             }
             break;
     }
 }
コード例 #9
0
ファイル: script.cs プロジェクト: nebez/TwitchBot
 public void onUserAction(Channel channel, User sender, string action)
 {
     //triggered when people use the /me command.
 }
コード例 #10
0
ファイル: script.cs プロジェクト: nebez/TwitchBot
 public void onNewSubscriber(Channel channel, User subscriber)
 {
     Logger.Log.Write("new sub: " + subscriber.Nickname, ConsoleColor.Blue);
 }
コード例 #11
0
ファイル: Channel.cs プロジェクト: nebez/TwitchBot
 public void RemoveUser(User user)
 {
     if (users.Contains(user))
         users.Remove(user);
 }
コード例 #12
0
ファイル: Channel.cs プロジェクト: nebez/TwitchBot
 public void AddUser(User user)
 {
     if (!users.Contains(user))
         users.Add(user);
 }