Ejemplo n.º 1
0
        private void QueryHitboxForQueuedStream()
        {
            if (_streamsToCheck.Count == 0)
                    return;
                if (StreamStarted == null)
                {
                    return;
                }
                var stream = _streamsToCheck.Dequeue();

                var result = CheckStreamOnlineStatus(stream);

                if (result == null || result.livestream.Count != 1)
                    return;
                if (result.livestream[0].media_is_live == "1")
                {
                    if (!_streamData.ContainsKey(stream))
                    {

                        var hitboxStreamData = new HitboxStreamData
                        {
                            Started = DateTime.Now,
                            Stream = result.livestream[0]
                        };
                        bool globalancounce = false;
                        if (_streamData.Keys.Contains(stream))
                        {
                            globalancounce = true;
                        }
                        var bTryAddResult = _streamData.TryAdd(stream,
                                                               hitboxStreamData);

                        if (bTryAddResult)
                        {
                            var stream1 = new Stream
                            {
                                Channel = hitboxStreamData.Stream.media_user_name,
                                Game =
                                    hitboxStreamData.Stream.category_name ??
                                    "<no game>",
                                Message = hitboxStreamData.Stream.media_status,
                            };

                            var streamData = new StreamData
                            {
                                Started = DateTime.Now,
                                Stream = stream1,
                                StreamProvider = this
                            };
                            xmlprovider.AddStreamLivedata(hitboxStreamData.Stream.media_user_name, "http://www.hitbox.tv/" + hitboxStreamData.Stream.media_user_name.ToString(),hitboxStreamData.Stream.category_name);

                            var streamEventArgs = new StreamEventArgs(streamData);
                            StreamStarted(this, streamEventArgs);
                            StreamGlobalNotification(this, streamEventArgs);
                        }
                        if (!bTryAddResult && globalancounce)
                        {

                            var stream1 = new Stream
                            {
                                Channel = hitboxStreamData.Stream.media_user_name,
                                Game =
                                    hitboxStreamData.Stream.category_name ??
                                    "<no game>",
                                Message = hitboxStreamData.Stream.media_status,
                            };

                            var streamData = new StreamData
                            {
                                Started = DateTime.Now,
                                Stream = stream1,
                                StreamProvider = this
                            };

                            var streamEventArgs = new StreamEventArgs(streamData);
                            StreamGlobalNotification(this, streamEventArgs);
                        }
                    }
                    else
                    {
                        var hitboxStreamData = new HitboxStreamData
                        {
                            Started = DateTime.Now,
                            Stream = result.livestream[0]
                        };
                        bool globalancounce = false;
                        if (_streamData.Keys.Contains(stream))
                        {
                            globalancounce = true;
                        }
                        var bTryAddResult = _streamData.TryAdd(stream,
                                                               hitboxStreamData);
                        if (!bTryAddResult && globalancounce)
                        {
                            var stream1 = new Stream
                            {
                                Channel = hitboxStreamData.Stream.media_user_name,
                                Game =
                                    hitboxStreamData.Stream.category_name ??
                                    "<no game>",
                                Message = hitboxStreamData.Stream.media_status,
                            };

                            var streamData = new StreamData
                            {
                                Started = DateTime.Now,
                                Stream = stream1,
                                StreamProvider = this
                            };

                            var streamEventArgs = new StreamEventArgs(streamData);
                            StreamGlobalNotification(this, streamEventArgs);
                        }
                    }
                    //WriteStreamDataToFile();
                }
                else
                {
                    if (_streamData.ContainsKey(stream))
                    {
                        HitboxStreamData hitboxStreamData;

                        var bTryRemoveResult = _streamData.TryRemove(stream,
                                                                     out
                                                                     hitboxStreamData);
                        if (bTryRemoveResult && StreamStopped != null)
                        {
                            var stream1 = new Stream
                            {
                                Channel = hitboxStreamData.Stream.media_user_name,
                                Game = hitboxStreamData.Stream.category_name,
                                Message = hitboxStreamData.Stream.media_status
                            };

                            var streamData = new StreamData
                            {
                                Started = DateTime.Now,
                                Stream = stream1,
                                StreamProvider = this
                            };

                            var streamEventArgs = new StreamEventArgs(streamData);

                            StreamStopped(this, streamEventArgs);
                        }
                    }
                }
        }
Ejemplo n.º 2
0
        private void OnStreamStopped(object sender, StreamEventArgs args)
        {
            if (Properties.Settings.Default.SilentMode.ToString() != "true")
            {
                if (xmlprovider == null) { xmlprovider = new XMLProvider(); }
                if (xmlprovider.StreamInfo(args.StreamData.Stream.Channel, "starttime") != "" && Convert.ToBoolean(xmlprovider.StreamInfo(args.StreamData.Stream.Channel, "running")))
                {
                    xmlprovider.StreamStartUpdate(args.StreamData.Stream.Channel, true);
                    string duration = DateTime.Now.Subtract(Convert.ToDateTime(xmlprovider.StreamInfo(args.StreamData.Stream.Channel, "starttime"))).ToString("h':'mm':'ss");
                    string output = "Stream stopped after " + duration + ": " + args.StreamData.Stream.Channel;
                    List<string> NoticeTargets = new List<string>();
                    List<string> MsgsTargets = new List<string>();
                    List<NormalisedUser> UsersinChannel = new List<NormalisedUser>();
                    foreach (var user in thisclient.Channels.First().Users)
                    {
                        if (user.User.NickName != "Q" && user.User.NickName != Settings.Default.Name.ToString())
                        {
                            var updateduser = thisclient.Channels.FirstOrDefault().GetChannelUser(user.User);
                            if (updateduser != null)
                            {
                                UsersinChannel.Add(new NormalisedUser(updateduser.User.NickName));
                            }
                            else
                            {
                                UsersinChannel.Add(new NormalisedUser(user.User.NickName));
                            }
                        }
                    }
                    foreach (NormalisedUser user in UsersinChannel)
                    {
                        User userUser = getUser(user.normalised_username().ToLower());
                        if (userUser != null)
                        {
                            if (userUser.isSubscribed(args.StreamData.Stream.Channel))
                            {

                                if (!userUser.bMessages)
                                {
                                    NoticeTargets.Add(user.orig_username);
                                }
                                else
                                {
                                    MsgsTargets.Add(user.orig_username);
                                }
                            }
                        }
                        else
                        {
                            if (user.orig_username != "Q")
                            {
                                MsgsTargets.Add(user.orig_username);
                            }
                        }

                    }
                    if (NoticeTargets.Count > 0)
                    {
                        thisclient.LocalUser.SendNotice(NoticeTargets, output);
                    }
                    if (MsgsTargets.Count > 0)
                    {
                        thisclient.LocalUser.SendMessage(MsgsTargets, output);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private void OnStreamStarted(object sender, StreamEventArgs args)
        {
            if (Properties.Settings.Default.SilentMode.ToString() != "true")
            {
                if (xmlprovider == null) { xmlprovider = new XMLProvider(); }
                if (xmlprovider.isinStreamList(args.StreamData.Stream.Channel))
                {
                    if (xmlprovider.StreamInfo(args.StreamData.Stream.Channel, "running") == "false")
                    {
                        string game = args.StreamData.Stream.Game;

                        if (args.StreamData.Stream.Message != null)
                        {
                            game = args.StreamData.Stream.Message;
                        }
                        xmlprovider.AddStreamLivedata(args.StreamData.Stream.Channel, args.StreamData.StreamProvider.GetLink() + "/" + args.StreamData.Stream.Channel, game);
                        string output = "Stream started: " + args.StreamData.Stream.Channel + "(" + args.StreamData.Stream.Game + ": " + args.StreamData.Stream.Message + ")" + " at " + args.StreamData.StreamProvider.GetLink() + "/" + args.StreamData.Stream.Channel;
                        List<string> NoticeTargets = new List<string>();
                        List<string> MsgsTargets = new List<string>();
                        List<NormalisedUser> UsersinChannel = new List<NormalisedUser>();
                        foreach (var user in thisclient.Channels.FirstOrDefault().Users)
                        {
                            Console.WriteLine("UsersinBob: " + user.User.NickName);
                            if (user.User.NickName != "Q" && user.User.NickName != Settings.Default.Name.ToString())
                            {
                                var updateduser = thisclient.Channels.FirstOrDefault().GetChannelUser(user.User);
                                if(updateduser != null)
                                {
                                    UsersinChannel.Add(new NormalisedUser(updateduser.User.NickName));
                                }
                                else
                                {
                                    UsersinChannel.Add(new NormalisedUser(user.User.NickName));
                                }
                            }
                        }
                        foreach (NormalisedUser user in UsersinChannel)
                        {
                            User userUser = getUser(user.normalised_username().ToLower());
                            if (userUser != null)
                            {
                                if (userUser.isSubscribed(args.StreamData.Stream.Channel))
                                {

                                    if (!userUser.bMessages)
                                    {
                                        NoticeTargets.Add(user.orig_username);
                                    }
                                    else
                                    {
                                        MsgsTargets.Add(user.orig_username);
                                    }
                                }
                            }
                            else
                            {
                                if(user.orig_username != "Q")
                                {
                                    MsgsTargets.Add(user.orig_username);
                                }
                            }
                        }
                        if (NoticeTargets.Count > 0)
                        {
                            thisclient.LocalUser.SendNotice(NoticeTargets, output);
                        }
                        if (MsgsTargets.Count > 0)
                        {
                            thisclient.LocalUser.SendMessage(MsgsTargets, output);
                        }
                        xmlprovider.GlobalAnnouncementDue(args.StreamData.Stream.Channel);
                    }
                    xmlprovider.StreamStartUpdate(args.StreamData.Stream.Channel);

                }
            }
        }
Ejemplo n.º 4
0
        private void OnStreamStarted(object sender, StreamEventArgs args)
        {
            if (Properties.Settings.Default.SilentMode.ToString() != "true")
            {
                if (xmlprovider == null) { xmlprovider = new XMLProvider(); }
                if (xmlprovider.isinStreamList(args.StreamData.Stream.Channel))
                {
                    if (xmlprovider.StreamInfo(args.StreamData.Stream.Channel, "running") == "false")
                    {
                        if(RelayBots.Where(x => x.sChannel.ToLower() == args.StreamData.Stream.Channel.ToLower()).Count() > 0 && RelayBots.Where(x => x.sChannel.ToLower() == args.StreamData.Stream.Channel.ToLower()).First().isExit == false)
                        {
                            RelayBots.Where(x => x.sChannel.ToLower() == args.StreamData.Stream.Channel.ToLower()).First().StopRelayEnd();
                        }
                        else
                        {
                            ConnectToTwitchChat(args.StreamData.Stream.Channel, true);
                        }

                        string game = args.StreamData.Stream.Game;

                        if (args.StreamData.Stream.Message != null)
                        {
                            game = args.StreamData.Stream.Message;
                        }
                        xmlprovider.AddStreamLivedata(args.StreamData.Stream.Channel, args.StreamData.StreamProvider.GetLink() + "/" + args.StreamData.Stream.Channel, game);
                        string output = "Stream started: " + args.StreamData.Stream.Channel + "(" + args.StreamData.Stream.Game + ": " + args.StreamData.Stream.Message + ")" + " at " + args.StreamData.StreamProvider.GetLink() + "/" + args.StreamData.Stream.Channel;
                        List<string> NoticeTargets = new List<string>();
                        List<string> MsgsTargets = new List<string>();
                        List<NormalisedUser> UsersinChannel = new List<NormalisedUser>();
                        foreach (var user in bot.Servers.First().Users)
                        {
                            if (user.Name != Settings.Default.Name.ToString())
                            {
                                UsersinChannel.Add(new NormalisedUser(user.Name));
                            }
                        }
                        foreach (NormalisedUser user in UsersinChannel)
                        {
                            DataFiles.User userUser = getUser(user.normalised_username().ToLower());
                            if (userUser != null)
                            {
                                if (userUser.isSubscribed(args.StreamData.Stream.Channel) || true)
                                {
                                    MsgsTargets.Add(user.orig_username);
                                }
                            }
                            else
                            {
                                if (user.orig_username != "Q")
                                {
                                    MsgsTargets.Add(user.orig_username);
                                }
                            }

                        }
                        if (MsgsTargets.Count > 0)
                        {
                            foreach (var username in MsgsTargets)
                            {
                                var client = bot.Servers.First().Users.Where(x => x.Name.ToLower() == username.ToLower()).First();
                                if (client != null)
                                {
                                    try
                                    {
                                        Console.WriteLine(client.Name);
                                        client.SendMessage(output);
                                    }catch(Exception ex)
                                    {
                                        Console.WriteLine(ex.ToString());
                                    }

                                }
                            }
                        }
                        xmlprovider.GlobalAnnouncementDue(args.StreamData.Stream.Channel);
                    }
                    xmlprovider.StreamStartUpdate(args.StreamData.Stream.Channel);

                }
            }
        }
Ejemplo n.º 5
0
        private void OnStreamGlobalNotification(object sender, StreamEventArgs args)
        {
            if (Properties.Settings.Default.SilentMode.ToString() != "true")
            {
                if (xmlprovider.StreamInfo(args.StreamData.Stream.Channel, "running") == "true")
                {
                    if (args.StreamData.StreamProvider.GetType().ToString() == "DeathmicChatbot.StreamInfo.Hitbox.HitboxProvider")
                    {

                    }
                    else
                    {
                        //Twitch
                        if(RelayBots.Where(x=>x.sChannel.ToLower() == args.StreamData.Stream.Channel).Count()==0 || RelayBots.Where(x => x.sChannel.ToLower() == args.StreamData.Stream.Channel).Count() >0 && RelayBots.Where(x => x.sChannel.ToLower() == args.StreamData.Stream.Channel).First().bDisconnected)
                        {
                            ConnectToTwitchChat(args.StreamData.Stream.Channel, true);
                        }
                        if(RelayBots.Where(x => x.sChannel.ToLower() == args.StreamData.Stream.Channel).Count() > 0)
                        {
                            foreach(TwitchRelay RelayBot in RelayBots)
                            {
                                RelayBot.StopRelayEnd();
                            }
                        }
                    }

                    if (xmlprovider.GlobalAnnouncementDue(args.StreamData.Stream.Channel))
                    {
                        string game = "";
                        if (args.StreamData.StreamProvider.GetType().ToString() == "DeathmicChatbot.StreamInfo.Hitbox.HitboxProvider")
                        {
                            game = args.StreamData.Stream.Message;
                        }
                        else
                        {
                            game = xmlprovider.StreamInfo(args.StreamData.Stream.Channel, "game");
                        }
                        xmlprovider.AddStreamLivedata(args.StreamData.Stream.Channel, args.StreamData.StreamProvider.GetLink() + "/" + args.StreamData.Stream.Channel, game);
                        string output = "Stream is running: " + args.StreamData.Stream.Channel + "(" + args.StreamData.Stream.Game + ": " + args.StreamData.Stream.Message + ")" + " at " + args.StreamData.StreamProvider.GetLink() + "/" + args.StreamData.Stream.Channel;
                        List<string> NoticeTargets = new List<string>();
                        List<string> MsgsTargets = new List<string>();
                        List<NormalisedUser> UsersinChannel = new List<NormalisedUser>();

                        foreach (var user in bot.Servers.First().Users)
                        {
                            if (user.Name != Settings.Default.Name.ToString())
                            {
                                UsersinChannel.Add(new NormalisedUser(user.Name));
                            }
                        }
                        foreach (NormalisedUser user in UsersinChannel)
                        {
                            DataFiles.User userUser = getUser(user.normalised_username().ToLower());
                            if (userUser != null)
                            {

                                if (userUser.isSubscribed(args.StreamData.Stream.Channel) && userUser.isGlobalAnnouncment(args.StreamData.Stream.Channel))
                                {
                                    MsgsTargets.Add(user.orig_username);
                                }
                            }
                            else
                            {
                                MsgsTargets.Add(user.orig_username);
                            }

                        }
                        if (MsgsTargets.Count > 0)
                        {
                            foreach (var username in MsgsTargets)
                            {
                                var client = bot.Servers.First().Users.Where(x => x.Name.ToLower() == username.ToLower()).First();
                                if (client != null)
                                {
                                    client.SendMessage(output);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private void OnStreamStopped(object sender, StreamEventArgs args)
        {
            if (Properties.Settings.Default.SilentMode.ToString() != "true")
            {
                if (xmlprovider == null) { xmlprovider = new XMLProvider(); }
                if (xmlprovider.StreamInfo(args.StreamData.Stream.Channel, "starttime") != "" && Convert.ToBoolean(xmlprovider.StreamInfo(args.StreamData.Stream.Channel, "running")))
                {
                    if (RelayBots.Where(x => x.sChannel.ToLower() == args.StreamData.Stream.Channel.ToLower()).Count() > 0)
                    {
                        RelayBots.Where(x => x.sChannel.ToLower() == args.StreamData.Stream.Channel.ToLower()).First().StartRelayEnd();
                    }
                    xmlprovider.StreamStartUpdate(args.StreamData.Stream.Channel, true);
                    string duration = DateTime.Now.Subtract(Convert.ToDateTime(xmlprovider.StreamInfo(args.StreamData.Stream.Channel, "starttime"))).ToString("h':'mm':'ss");
                    string output = "Stream stopped after " + duration + ": " + args.StreamData.Stream.Channel;
                    List<string> NoticeTargets = new List<string>();
                    List<string> MsgsTargets = new List<string>();
                    List<NormalisedUser> UsersinChannel = new List<NormalisedUser>();
                    foreach (var user in bot.Servers.First().Users)
                    {
                        if (user.Name != Settings.Default.Name.ToString())
                        {
                                UsersinChannel.Add(new NormalisedUser(user.Name));
                        }
                    }
                    foreach (NormalisedUser user in UsersinChannel)
                    {
                        DataFiles.User userUser = getUser(user.normalised_username().ToLower());
                        if (userUser != null)
                        {
                            if (userUser.isSubscribed(args.StreamData.Stream.Channel))
                            {
                                MsgsTargets.Add(user.orig_username);
                            }
                        }
                        else
                        {
                            if (user.orig_username != "Q")
                            {
                                MsgsTargets.Add(user.orig_username);
                            }
                        }

                    }
                    if (MsgsTargets.Count > 0)
                    {
                        foreach(var username in NoticeTargets)
                        {
                            var client = bot.Servers.First().Users.Where(x => x.Name.ToLower() == username.ToLower()).First();
                            if(client != null)
                            {
                                client.SendMessage(output);
                            }
                        }
                    }
                }
            }
        }