Example #1
0
        public async Task RemoveRadio(params string[] args)
        {
            if (Context.Guild == null)
            {
                await ReplyAsync(Base.Sentences.CommandDontPm(Context.Guild));

                return;
            }
            Utilities.CheckAvailability(Context.Guild, Program.Module.Radio);
            await p.DoAction(Context.User, Program.Module.Radio);

            RadioChannel radio = p.radios.Find(x => x.m_guildId == Context.Guild.Id);

            if (radio == null)
            {
                await ReplyAsync(Sentences.RadioNotStarted(Context.Guild));
            }
            else
            {
                string title = string.Join(" ", args);
                if (await radio.RemoveSong(Context.Channel, title))
                {
                    await ReplyAsync(Base.Sentences.DoneStr(Context.Guild));
                }
                else
                {
                    List <int> indexs = new List <int>();
                    foreach (var str in args)
                    {
                        if (int.TryParse(str, out int res))
                        {
                            if (!indexs.Contains(res))
                            {
                                indexs.Add(res);
                            }
                        }
                        else
                        {
                            indexs = null;
                            break;
                        }
                    }
                    if (indexs == null || !await radio.RemoveSong(Context.Channel, indexs))
                    {
                        await ReplyAsync(Sentences.InvalidSong(Context.Guild));
                    }
                    else
                    {
                        await ReplyAsync(Base.Sentences.DoneStr(Context.Guild));
                    }
                }
            }
        }
Example #2
0
        public async Task addRadio(params string[] words)
        {
            p.doAction(Context.User, Context.Guild.Id, Program.Module.Radio);
            if (words.Length == 0)
            {
                await ReplyAsync(Sentences.radioNeedArg(Context.Guild.Id));
            }
            else if (p.radios.Any(x => x.m_guildId == Context.Guild.Id) && !p.radios.Find(x => x.m_guildId == Context.Guild.Id).CanAddMusic())
            {
                await ReplyAsync(Sentences.radioTooMany(Context.Guild.Id));
            }
            else
            {
                if (!p.radios.Any(x => x.m_guildId == Context.Guild.Id))
                {
                    if (!await StartRadio(Context.Channel))
                    {
                        return;
                    }
                }
                Tuple <string, string> youtubeResult = await YoutubeModule.GetYoutubeVideo(words, Context.Channel);

                if (youtubeResult != null)
                {
                    RadioChannel radio = p.radios.Find(x => x.m_guildId == Context.Guild.Id);
                    if (radio.ContainMusic(youtubeResult.Item1))
                    {
                        await ReplyAsync(Sentences.radioAlreadyInList(Context.Guild.Id));

                        return;
                    }
                    radio.AddMusic("Saves/Radio/" + radio.m_guildId + "/" + Program.cleanWord(youtubeResult.Item2) + ".mp3", youtubeResult.Item2, youtubeResult.Item1, await Context.Guild.GetUserAsync(Sentences.myId), Context.Guild.Id.ToString());
                    YouTubeVideo video = GetYoutubeVideo(youtubeResult.Item1);
                    if (video == null)
                    {
                        radio.RemoveSong(youtubeResult.Item1);
                        await ReplyAsync(Sentences.cantDownload(Context.Guild.Id));
                    }
                    else
                    {
                        await ReplyAsync(youtubeResult.Item2 + " was added to the list.");

                        DownloadAudio(video, radio, youtubeResult.Item1, Program.cleanWord(youtubeResult.Item2));
                    }
                }
            }
        }