Example #1
0
        //Display text for Twitter.
        protected virtual string GetTwitterUrl(SocialMediaUserData ud)
        {
            string message = Hyperlink.Replace("@name", ud.Name);

            message = message.Replace("@id", ud.Id);
            return(message + "\n\n");
        }
Example #2
0
        public override async Task <string> GetSocialMediaUser(ulong guildId, ulong channelId, string username)
        {
            int i = FindIndexByName(guildId, username, SocialMediaEnum.Twitch);

            if (i <= -1)
            {
                return(await Task.FromResult("Can't find streamer."));
            }

            SocialMediaUserData ud = Users[i];
            bool isLive            = await _api.IsLive(ud.Name);

            string message;

            if (isLive)
            {
                message = await UpdateSocialMedia(new List <SocialMediaUserData> {
                    ud
                }, await GetStreamInfo(ud.Name));
            }
            else
            {
                message = Hyperlink + ud.Name;
            }

            return(await Task.FromResult(message));
        }
Example #3
0
 private void Equal(SocialMediaEnum expectedSocialMedia, string expectedName, ulong expectedGuildId,
                    ulong expectedChannelId, string expectedId, SocialMediaUserData actualUserData)
 {
     Assert.Equal(expectedSocialMedia, actualUserData.SocialMedia);
     Assert.Equal(expectedName, actualUserData.Name);
     Assert.Equal(expectedGuildId, actualUserData.GuildId);
     Assert.Equal(expectedChannelId, actualUserData.ChannelId);
     Assert.Equal(expectedId, actualUserData.Id);
 }
Example #4
0
        public void Save_Test_Fail()
        {
            var tuple                = SetUpSaveFileTests();
            var fileSystem           = tuple.Item1;
            var file                 = tuple.Item2;
            SocialMediaUserData user = new SocialMediaUserData();

            bool ok = fileSystem.Save(user);

            Assert.False(ok);
            Assert.False(File.Exists(file));
        }
Example #5
0
        public virtual string DeleteSocialMediaUser(ulong guildId, string user, SocialMediaEnum socialMedia)
        {
            int i = FindIndexByName(guildId, user, socialMedia);

            if (i > -1)
            {
                SocialMediaUserData ud = Users[i];
                FileSystem.DeleteInFile(ud);
                Users.RemoveAt(i);
                return($"Successfully deleted {ud.Name}");
            }
            return($"Failed to delete {user}");
        }
Example #6
0
        public override async Task <string> GetUpdatedSocialMediaUsers(ulong guildId)
        {
            if (Users.Count == 0)
            {
                return(await Task.FromResult("No streamers registered."));
            }

            List <SocialMediaUserData> live         = new List <SocialMediaUserData>();
            Tuple <string, string>     streamerInfo = null;

            for (int i = 0; i < Users.Count; i++)
            {
                SocialMediaUserData user = Users[i];
                if (user.SocialMedia != SocialMediaEnum.Twitch || user.GuildId != guildId)
                {
                    continue;
                }

                bool isLive = await _api.IsLive(user.Name);

                string oldId = user.Id;
                if (isLive)
                {
                    user.Id      = "online";
                    streamerInfo = await GetStreamInfo(user.Name);
                }
                else
                {
                    user.Id = "offline";
                }

                if (user.Id == oldId)
                {
                    continue;
                }

                Users[i] = user;
                live.Add(Users[i]);
                FileSystem.UpdateFile(user);
            }

            if (live.Count > 0)
            {
                return(await UpdateSocialMedia(live, streamerInfo));
            }

            return(await Task.FromResult("No streamers are broadcasting."));
        }
Example #7
0
        private async Task <TwitterStatus> GetLatestTwitter(SocialMediaUserData ud, bool isNsfw)
        {
            ListTweetsOnUserTimelineOptions options = new ListTweetsOnUserTimelineOptions()
            {
                ScreenName = ud.Name,
                IncludeRts = false,
                Count      = 100,
                TweetMode  = "extended"
            };

            var tweets = await _service.ListTweetsOnUserTimelineAsync(options);

            TwitterStatus[] twitterStatuses;
            try
            {
                twitterStatuses = tweets.Value as TwitterStatus[] ?? tweets.Value.ToArray();
                if (!twitterStatuses.Any())
                {
                    return(null);
                }
            }
            catch
            {
                return(null);
            }

            TwitterStatus tweet = twitterStatuses.ElementAt(0);

            if (isNsfw)
            {
                if (tweet.ExtendedEntities == null || !tweet.ExtendedEntities.Any() || !tweet.ExtendedEntities.Media.Any() ||
                    tweet.ExtendedEntities.Media.ElementAt(0).ExtendedEntityType != TwitterMediaType.Photo)
                {
                    tweet.Id = -1;
                }
            }

            if (tweet.Id == 0 || tweet.IdStr == "" || tweet.IdStr == null)
            {
                return(null);
            }

            return(await Task.FromResult(tweet));
        }
Example #8
0
        public override async Task <string> GetUpdatedSocialMediaUsers(ulong guildId)
        {
            if (Users.Count == 0)
            {
                return(await Task.FromResult("No Twitter handles registered."));
            }

            List <SocialMediaUserData> newTweets = new List <SocialMediaUserData>();

            for (int i = 0; i < Users.Count; i++)
            {
                SocialMediaUserData user = Users[i];
                if (user.SocialMedia != SocialMediaEnum.Twitter || user.GuildId != guildId)
                {
                    continue;
                }

                var           channel = Client.GetGuild(user.GuildId)?.GetTextChannel(user.ChannelId);
                TwitterStatus tweet   = await GetLatestTwitter(user, channel is { IsNsfw : true });
Example #9
0
        public override async Task <string> GetUpdatedSocialMediaUsers(ulong guildId)
        {
            if (Users.Count == 0)
            {
                return(await Task.FromResult("No YouTuber registered."));
            }

            List <SocialMediaUserData> newVideos = new List <SocialMediaUserData>();

            for (int i = 0; i < Users.Count; i++)
            {
                SocialMediaUserData user = Users[i];
                if (user.SocialMedia != SocialMediaEnum.YouTube || user.GuildId != guildId)
                {
                    continue;
                }

                List <string> channelInfo = await SearchForYouTuber(user.Name);

                if (channelInfo.Count == 0)
                {
                    continue;
                }
                if (channelInfo[0] == user.Id)
                {
                    continue;
                }

                user.Id  = channelInfo[0];
                Users[i] = user;
                newVideos.Add(Users[i]);
                FileSystem.UpdateFile(user);
            }

            if (newVideos.Count > 0)
            {
                return(await UpdateSocialMedia(newVideos));
            }

            return(await Task.FromResult("No updates since last time."));
        }
Example #10
0
        public override async Task <string> GetSocialMediaUser(ulong guildId, bool isNsfw, string username)
        {
            int i = FindIndexByName(guildId, username, SocialMediaEnum.Twitter);

            if (i == -1)
            {
                return(await Task.FromResult("Could not find Twitter handle."));
            }

            TwitterStatus tweet = await GetLatestTwitter(Users[i], isNsfw);

            if (tweet != null)
            {
                SocialMediaUserData temp = Users[i];
                temp.Id  = tweet.IdStr;
                Users[i] = temp;
                return(await Task.FromResult(GetTwitterUrl(Users[i])));
            }

            return(await Task.FromResult("Could not retrieve Tweet."));
        }
Example #11
0
        private IEnumerable <SocialMediaUserData> CollectUserData(Dictionary <XDocument, ulong> xmls, SocialMediaEnum socialMedia)
        {
            List <SocialMediaUserData> ud = new List <SocialMediaUserData>();

            foreach (KeyValuePair <XDocument, ulong> xml in xmls)
            {
                foreach (XElement e in xml.Key.Descendants("Service").Descendants(socialMedia.ToString()).Descendants("User"))
                {
                    SocialMediaUserData user = new SocialMediaUserData();
                    if (xml.Key.Document != null)
                    {
                        user.GuildId = xml.Value;
                    }
                    user.Name        = e.Attribute("Name")?.Value;
                    user.ChannelId   = ulong.Parse(e.Attribute("ChannelID")?.Value ?? string.Empty);
                    user.Id          = e.Attribute("ID")?.Value;
                    user.SocialMedia = socialMedia;
                    ud.Add(user);
                }
            }
            return(ud);
        }
Example #12
0
        protected virtual bool CreateSocialMediaUser(string name, ulong guildId, ulong channelId, string id, SocialMediaEnum socialMedia)
        {
            SocialMediaUserData temp = new SocialMediaUserData()
            {
                Name        = name,
                GuildId     = guildId,
                ChannelId   = channelId,
                Id          = id,
                SocialMedia = socialMedia
            };

            Users.Add(temp);

            bool ok = FileSystem.Save(temp);

            if (!ok)
            {
                Users.Remove(temp);
            }

            return(ok);
        }
Example #13
0
        //Display text for YouTube.
        protected virtual string GetYouTuber(SocialMediaUserData ud)
        {
            string message = Hyperlink + ud.Id;

            return(message + "\n\n");
        }
Example #14
0
 //Display text for Twitch.
 protected virtual string GetStreamerUrlAndGame(SocialMediaUserData ud, Tuple <string, string> streamerInfo)
 {
     return($"{streamerInfo.Item1} is playing {streamerInfo.Item2}\n{Hyperlink}{ud.Name}\n\n");
 }