Beispiel #1
0
        public async Task <ActionResult> Create(IFormCollection collection)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var message = collection["Message"].ToString();

                    if (message.Length > 200)
                    {
                        message = message.Substring(0, 200);
                    }

                    var botTimers = new BotTimers()
                    {
                        PartitionKey = Guid.NewGuid().ToString(),
                        RowKey       = "1",
                        Name         = collection["Name"],
                        Message      = message,
                        Interval     = int.Parse(collection["Interval"]),
                        ChatLines    = int.Parse(collection["ChatLines"]),
                        Alias        = collection["Alias"],
                        Status       = bool.Parse(collection["Status"]),
                        IsVisible    = bool.Parse(collection["IsVisible"])
                    };

                    await TableStorageService.InsertEntity(botTimers, Constants.BotTimersTableName);

                    return(RedirectToAction("Index", "BotTimers", new { ac = "Timer successfully created!", type = "success" }));
                }
                else
                {
                    return(View());
                }
            }
            catch (Exception)
            {
                return(View());
            }
        }
Beispiel #2
0
        public async Task <ActionResult> Create(IFormCollection collection, CustomCommands cmd)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!string.IsNullOrWhiteSpace(collection["Command"]))
                    {
                        var customCommands = new CustomCommands()
                        {
                            PartitionKey = Guid.NewGuid().ToString(),
                            RowKey       = "1",
                            Alias        = collection["Alias"],
                            Command      = collection["Command"],
                            Cooldown     = int.Parse(collection["Cooldown"]),
                            Message      = collection["Message"],
                            Userlevel    = collection["Userlevel"],
                            Description  = collection["Description"],
                            IsEnabled    = bool.Parse(collection["IsEnabled"])
                        };

                        await TableStorageService.InsertEntity(customCommands, Constants.CustomCommandsTableName);

                        return(RedirectToAction("Index", "Commands", new { ac = "The command was successfully added!", type = "success" }));
                    }
                    else
                    {
                        return(View());
                    }
                }
                else
                {
                    return(View());
                }
            }
            catch (Exception)
            {
                return(View());
            }
        }
        public async Task <ActionResult> Create(IFormCollection collection, Tags tag)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!string.IsNullOrWhiteSpace(collection["Name"]))
                    {
                        var tags = new Tags()
                        {
                            PartitionKey = Guid.NewGuid().ToString(),
                            RowKey       = "1",
                            Name         = collection["Name"],
                            Emoji        = collection["Emoji"],
                            Description  = collection["Description"]
                        };

                        await TableStorageService.InsertEntity(tags, Constants.TagsTableName);

                        return(RedirectToAction("Index", "Tags", new { ac = "The tag was successfully added!", type = "success" }));
                    }
                    else
                    {
                        return(View());
                    }
                }
                else
                {
                    return(View());
                }
            }
            catch (Exception)
            {
                return(View());
            }
        }
        public async Task <ActionResult> RequestSong(string pk, string rk)
        {
            var tableSong = TableStorageService.ConnectToTable("CurrentSong");
            var queryCS   = await tableSong.ExecuteQuerySegmentedAsync(new TableQuery <AzureTableSong>(), null);

            var currentSong = queryCS.Results.FirstOrDefault();

            if (currentSong.RowKey != rk)
            {
                var song = await TableStorageService.RetrieveEntity <AllSongs>(pk, rk, Constants.AllSongsTableName);

                if (song != null)
                {
                    var position = 1;

                    var channel = CookieService.Get(Request, Constants.ChannelCookieName);

                    var user = await userManager.GetUserAsync(User);

                    var userName = user.UserName;

                    var isModOwner = await userManager.IsInRoleAsync(user, "Moderator") ||
                                     await userManager.IsInRoleAsync(user, "Owner");

                    var queueSongs = await TableStorageService.RetrieveAllEntities <AzureTableSong>(Constants.QueueTableName);

                    if (queueSongs.Count > 0)
                    {
                        if (!isModOwner)
                        {
                            var friend = await TableStorageService.RetrieveEntity <Friends>(channel, "1", Constants.FriendsTableName);

                            if (friend != null)
                            {
                                var friendRequests = queueSongs.Count(x => x.RequestedById == channel);
                                if (friendRequests > 1)
                                {
                                    return(RedirectToAction("Index", "Playlist", new { ac = "Error. You already have two song requests on the queue.", type = "danger" }));
                                }
                            }
                            else
                            {
                                var userExists = queueSongs.Any(x => x.RequestedById == channel);
                                if (userExists)
                                {
                                    return(RedirectToAction("Index", "Playlist", new { ac = "Error. You already have a song request on the queue.", type = "danger" }));
                                }
                            }
                        }

                        var songExists = queueSongs.Any(x => x.RowKey == rk);
                        if (songExists)
                        {
                            return(RedirectToAction("Index", "Playlist", new { ac = $"Error. That song is already on the queue.", type = "danger" }));
                        }

                        queueSongs = queueSongs.OrderBy(x => x.Position).ToList();
                        position   = queueSongs.Last().Position + 1;
                    }

                    var lastRequest = (song.LastTimeRequested.HasValue)
                        ? MathFunctions.GetCooldownMinutes(song.LastTimeRequested.Value) : 100;

                    if (isModOwner || lastRequest > 60)
                    {
                        var updateSong = new AllSongs()
                        {
                            PartitionKey      = song.PartitionKey,
                            RowKey            = song.RowKey,
                            Counter           = song.Counter0 + 1,
                            LastTimeRequested = DateTime.UtcNow
                        };

                        await TableStorageService.MergeEntity(updateSong, Constants.AllSongsTableName);

                        var newSongQueue = new AzureTableSong()
                        {
                            PartitionKey      = song.PartitionKey,
                            RowKey            = song.RowKey,
                            Title             = song.OriginalTitle,
                            OriginalGame      = song.OriginalGame,
                            LowerCaseTitle    = song.Title,
                            Channel           = song.Channel,
                            VideoId           = song.YouTubeLink.Replace("https://youtu.be/", string.Empty),
                            YouTubeLink       = song.YouTubeLink,
                            Duration          = song.Duration,
                            TotalTime         = 0,
                            RecentlyAdded     = song.RecentlyAdded,
                            RequestedBy       = userName,
                            RequestedById     = channel,
                            Counter           = song.Counter0 + 1,
                            Likes             = song.Likes0,
                            Position          = position,
                            LastTimeRequested = song.LastTimeRequested
                        };

                        await TableStorageService.InsertEntity(newSongQueue, Constants.QueueTableName);

                        return(RedirectToAction("Index", "SongsQueue", new { ac = $"The song was added to the queue in position {position}.", type = "success" }));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Playlist", new { ac = $"Error. That song is in cooldown. Please wait {60 - lastRequest} minutes to request it again.", type = "danger" }));
                    }
                }

                return(RedirectToAction("Index", "Playlist", new { ac = "Error. The song does not exist.", type = "danger" }));
            }
            else
            {
                return(RedirectToAction("Index", "Playlist", new { ac = "Error. The song is currently playing.", type = "danger" }));
            }
        }
        public async Task <ActionResult> Create(IFormCollection collection, AllSongs song)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var youTubeLink = collection["YouTubeLink"].ToString();

                    if (!string.IsNullOrWhiteSpace(youTubeLink))
                    {
                        var table = TableStorageService.ConnectToTable(Constants.AllSongsTableName);
                        TableContinuationToken tableContinuationToken = null;
                        int maxKey     = 0;
                        var songExists = false;

                        do
                        {
                            var tableQuerySegment = await table.ExecuteQuerySegmentedAsync(new TableQuery <AllSongs>(), tableContinuationToken);

                            var songs = tableQuerySegment.Results;

                            var max = songs.Max(x => x.RowKey);
                            maxKey = Math.Max(maxKey, int.Parse(max));

                            tableContinuationToken = tableQuerySegment.ContinuationToken;
                            songExists             = songs.Any(x => x.YouTubeLink == youTubeLink);
                        }while (tableContinuationToken != null && !songExists);

                        if (!songExists)
                        {
                            var    i     = (maxKey + 1).ToString("D4");
                            string title = collection["OriginalTitle"];
                            string game  = collection["OriginalGame"];

                            var newSong = new AllSongs()
                            {
                                RowKey            = i,
                                OriginalGame      = game,
                                Game              = game.ToLower(),
                                OriginalTitle     = title,
                                PartitionKey      = StringFunctions.ReplaceChars(game.ToLower()),
                                Title             = StringFunctions.ReplaceChars(title.ToLower()),
                                Channel           = collection["Channel"],
                                Duration          = collection["Duration"],
                                YouTubeLink       = youTubeLink,
                                LastTimeRequested = null,
                                RecentlyAdded     = "✓",
                                Counter           = 0,
                                Likes             = 0
                            };

                            await TableStorageService.InsertEntity(newSong, Constants.AllSongsTableName);

                            //TODO: add tags from webpage

                            return(RedirectToAction("Index", "Playlist", new { ac = "The song was successfully added!", type = "success" }));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Playlist", new { ac = "The YouTube video URL already exists in the playlist!", type = "danger" }));
                        }
                    }
                    else
                    {
                        return(View());
                    }
                }
                else
                {
                    return(View());
                }
            }
            catch (Exception)
            {
                return(View());
            }
        }