Esempio n. 1
0
        public static IMessageActivity NowPlayingStation(ConversationInfo info, Station station)
        {
            var heroCard = NewHeroCard();

            var images = station.Album?.Images ?? station.Playlist?.Images;

            if (images != null && images.Any())
            {
                heroCard.Images.Add(
                    new CardImage
                {
                    Url = images[0].Url,
                    Alt = station.Name
                });
            }

            string messageText = info.IsGroup
                ? $"@{info.FromName} is now playing \"{station.Name}\" {station.HashtagHandle} 📢"
                : $"Now playing \"{station.Name}\". Friends can type `\"join @{RingoBotHelper.ToHashtag(info.FromName)}\"` to join in! 🎉";

            if (info.IsGroup)
            {
                heroCard.Buttons.Add(
                    new CardAction
                {
                    Title = $"Join {station.HashtagHandle}",
                    Value = $"join {station.HashtagHandle}",
                    Type  = ActionTypes.ImBack,
                });
            }

            return(MessageAttachment(heroCard, messageText));
        }
Esempio n. 2
0
        public async Task <Station> GetChannelStation(ConversationInfo info, string conversationName = null)
        {
            if (!info.IsGroup && string.IsNullOrEmpty(conversationName))
            {
                throw new ArgumentException("Must provide conversationName if not in group chat", nameof(conversationName));
            }

            return(await _stationData.GetStation(Station.EncodeIds(info, RingoBotHelper.ToHashtag(conversationName))));
        }
Esempio n. 3
0
        /// <summary>
        /// Changes the station owner to the current conversation From user
        /// </summary>
        public async Task ChangeStationOwner(Station station, ConversationInfo info)
        {
            var    oldOwner    = station.Owner;
            string ownerUserId = RingoBotHelper.ChannelUserId(info);

            // get user
            var ownerUser = await _userData.GetUser(ownerUserId);

            station.Owner = ownerUser;
            AddOwnerToListeners(station, ownerUser, ownerUserId);

            // TODO: if a user station, change the hashtag
            if (station.IsUserStation)
            {
                station.Hashtag = RingoBotHelper.ToHashtag(info.FromName);
            }

            await _stationData.ReplaceStation(station);

            _logger.LogInformation($"RingoBotNet.Services.RingoService.ChangeStationOwner: Station {station} has changed owner from {oldOwner} to {ownerUser}.");
        }
Esempio n. 4
0
        public async Task <Station> CreateUserStation(
            ConversationInfo info,
            Album album       = null,
            Playlist playlist = null)
        {
            string name        = album?.Name ?? playlist?.Name;
            string ownerUserId = RingoBotHelper.ChannelUserId(info);

            // get user
            var ownerUser = await _userData.GetUser(ownerUserId);

            string hashtag = RingoBotHelper.ToHashtag(ownerUser.Username);

            // get station
            var stationIds = Station.EncodeIds(info, hashtag, ownerUser.Username);
            var station    = await _stationData.GetStation(stationIds);

            // save station
            if (station == null)
            {
                // new station
                station = new Station(info, hashtag, album, playlist, ownerUser, ownerUser.Username);
                await _stationData.CreateStation(station);
            }
            else
            {
                // update station context and owner
                station.Name     = name;
                station.Owner    = ownerUser;
                station.Album    = album;
                station.Playlist = playlist;
                station.Hashtag  = hashtag;

                AddOwnerToListeners(station, ownerUser, ownerUserId);

                await _stationData.ReplaceStation(station);
            }

            return(station);
        }
Esempio n. 5
0
 public async Task <Station> GetUserStation(ConversationInfo info, string username)
 => await _stationData.GetStation(Station.EncodeIds(info, RingoBotHelper.ToHashtag(username), username));