Beispiel #1
0
        public void SendMessage(string text)
        {
            if (Name == null)
            {
                if (text.StartsWith("/w "))
                {
                    var channel = AllChannels.FirstOrDefault();

                    if (channel != null)
                    {
                        //IrcManager.Client.Say(text, "fivetf", true);
                        IrcManager.SendMessage(channel, text, IsModOrBroadcaster);
                    }
                }

                return;
            }

            IrcManager.SendMessage(this, text, IsModOrBroadcaster);

            if (AppSettings.Rainbow)
            {
                usernameHue += 0.1f;

                float r, g, b;
                (new HSLColor(usernameHue % 1, 0.5f, 0.5f)).ToRGB(out r, out g, out b);

                IrcManager.SendMessage(this, $".color #{(int)(r * 255):X}{(int)(g * 255):X}{(int)(b * 255):X}", IsModOrBroadcaster);
            }
        }
Beispiel #2
0
        // static ctor
        static Commands()
        {
            // Chat Commands
            ChatCommands.TryAdd("w", (s, channel, execute) =>
            {
                if (execute)
                {
                    var S = s.SplitWords();

                    if (S.Length > 1)
                    {
                        var name = S[0];

                        IrcMessage message;
                        IrcMessage.TryParse($":{name}!{name}@{name}.tmi.twitch.tv PRIVMSG #whispers :" + s.SubstringFromWordIndex(1), out message);

                        TwitchChannel.WhisperChannel.AddMessage(new Message(message, TwitchChannel.WhisperChannel, isSentWhisper: true));

                        if (AppSettings.ChatEnableInlineWhispers)
                        {
                            var inlineMessage = new Message(message, TwitchChannel.WhisperChannel, true, false, isSentWhisper: true)
                            {
                                HighlightTab = false
                            };

                            inlineMessage.HighlightType = HighlightType.Whisper;

                            foreach (var c in TwitchChannel.Channels)
                            {
                                c.AddMessage(inlineMessage);
                            }
                        }
                    }
                }

                return("/w " + s);
            });

            ChatCommands.TryAdd("ignore", (s, channel, execute) =>
            {
                if (execute)
                {
                    var S = s.SplitWords();
                    if (S.Length > 0)
                    {
                        IrcManager.AddIgnoredUser(S[0], null);
                    }
                }
                return(null);
            });
            ChatCommands.TryAdd("unignore", (s, channel, execute) =>
            {
                if (execute)
                {
                    var S = s.SplitWords();
                    if (S.Length > 0)
                    {
                        IrcManager.RemoveIgnoredUser(S[0], null);
                    }
                }
                return(null);
            });

            ChatCommands.TryAdd("uptime", (s, channel, execute) =>
            {
                if (execute && channel != null)
                {
                    try
                    {
                        var request = WebRequest.Create($"https://api.twitch.tv/kraken/streams/{channel.Name}?client_id={IrcManager.DefaultClientID}");
                        if (AppSettings.IgnoreSystemProxy)
                        {
                            request.Proxy = null;
                        }
                        using (var resp = request.GetResponse())
                            using (var stream = resp.GetResponseStream())
                            {
                                var parser = new JsonParser();

                                dynamic json = parser.Parse(stream);

                                dynamic root = json["stream"];

                                string createdAt = root["created_at"];

                                var streamStart = DateTime.Parse(createdAt);

                                var uptime = DateTime.Now - streamStart;

                                var text = "Stream uptime: ";

                                if (uptime.TotalDays > 1)
                                {
                                    text += (int)uptime.TotalDays + " days, " + uptime.ToString("hh\\h\\ mm\\m\\ ss\\s");
                                }
                                else
                                {
                                    text += uptime.ToString("hh\\h\\ mm\\m\\ ss\\s");
                                }

                                channel.AddMessage(new Message(text));
                            }
                    }
                    catch { }
                }

                return(null);
            });

            ChatCommands.TryAdd("testcheering", (s, channel, execute) =>
            {
                if (execute)
                {
                    foreach (var x in new[] { "1", "100", "1000", "5000", "10000" })
                    {
                        IrcMessage msg;
                        IrcMessage.TryParse($"@badges=subscriber/1;bits={x};color=;display-name=FOURTF;emotes=;mod=0;subscriber=1;turbo=0;user-type= :[email protected] PRIVMSG #fourtf :cheer{x} xD donation", out msg);

                        foreach (var c in TwitchChannel.Channels)
                        {
                            var message = new Message(msg, c);
                            c.AddMessage(message);
                        }
                    }
                }

                return(null);
            });

            ChatCommands.TryAdd("testchannels", (s, channel, execute) =>
            {
                TwitchChannel.WhisperChannel.AddMessage(new Message(string.Join(", ", TwitchChannel.Channels.Select(x => x.Name))));
                return(null);
            });
        }