Example #1
0
        public async Task <ListenGroup> GetGroupAsync(ChatServices service, string id)
        {
            var result = await table.ExecuteAsync(
                TableOperation.Retrieve <ListenGroup>(
                    ListenGroup.GetPartitionKey(ListenGroup.GetId(service, id)),
                    ListenGroup.GetId(service, id)));

            return(result.Result as ListenGroup);
        }
        protected override async Task ProcessListenSessionCommandInternalAsync(MBUser user, Message message, ILogger logger, bool isAuthorizationCallback = false)
        {
            if (ListenGroup != null)
            {
                logger.LogInformation("Group {group} is already setup for listen session", ListenGroup);
                await TelegramClient.SendTextMessageAsync(
                    message.Chat.Id,
                    "This group is already setup for listening.");

                return;
            }

            var spotifyClient = await SpotifyService.GetClientAsync(user);

            var playlist = await spotifyClient.Playlists.Create(user.SpotifyId, new PlaylistCreateRequest($"{message.Chat.Title} Playlist")
            {
                Description   = $"Playlist managed by Music Bot. For Telegram group chat '{message.Chat.Title}'",
                Collaborative = true,
                Public        = false
            });

            var group = new ListenGroup()
            {
                Id                         = ListenGroup.GetId(ChatServices.Telegram, message.Chat.Id.ToString()),
                ServiceId                  = message.Chat.Id.ToString(),
                OwnerMBDisplayName         = user.DisplayName,
                OwnerMBUserId              = user.Id,
                OwnerSpotifyUserId         = user.SpotifyId,
                ActiveListenerIds          = new string[] { },
                LastListened               = DateTimeOffset.UtcNow,
                SpotifyPlaylistDisplayName = playlist.Name,
                SpotifyPlaylistId          = playlist.Id,
                Created                    = DateTimeOffset.UtcNow
            };

            await ListenSessionService.CreateGroupAsync(group);

            await TelegramClient.SendTextMessageAsync(
                message.Chat.Id,
                "Setup Complete. " + playlist.ExternalUrls.FirstOrDefault().Value);

            return;
        }
Example #3
0
        public async Task SetLastListened(ListenGroup group)
        {
            group.LastListened = DateTimeOffset.UtcNow;

            await table.ExecuteAsync(TableOperation.Merge(group));
        }
Example #4
0
 public async Task CreateGroupAsync(ListenGroup group)
 {
     await table.ExecuteAsync(TableOperation.Insert(group));
 }