Example #1
0
        public async Task YoutubeVideo(params string[] args)
        {
            Base.Utilities.CheckAvailability(Context.Guild, Program.Module.Youtube);
            await p.DoAction(Context.User, Program.Module.Youtube);

            var result = await Features.Entertainment.YouTube.SearchYouTube(args, Program.p.youtubeService);

            switch (result.error)
            {
            case Features.Entertainment.Error.YouTube.InvalidApiKey:
                await ReplyAsync(Base.Sentences.NoApiKey(Context.Guild));

                break;

            case Features.Entertainment.Error.YouTube.Help:
                await ReplyAsync(Sentences.YoutubeHelp(Context.Guild));

                break;

            case Features.Entertainment.Error.YouTube.NotFound:
                await ReplyAsync(Sentences.YoutubeNotFound(Context.Guild));

                break;

            case Features.Entertainment.Error.YouTube.None:
                await ReplyAsync(result.answer.url);

                break;

            default:
                throw new NotImplementedException();
            }
        }
Example #2
0
            public async Task <bool> RemoveSong(IMessageChannel chan, List <int> indexs)
            {
                int didRemove = 0;

                indexs = indexs.OrderByDescending(x => x).ToList();
                string songName = null;

                foreach (int i in indexs)
                {
                    if (i == 0)
                    {
                        songName = m_musics[0].title;
                        await Skip(null);

                        didRemove++;
                    }
                    if (i > 0 && i < m_musics.Count)
                    {
                        songName = m_musics[i].title;
                        m_musics.RemoveAt(i);
                        didRemove++;
                    }
                }
                if (didRemove == 1)
                {
                    await chan.SendMessageAsync(Sentences.SongSkipped((chan as ITextChannel).Guild, songName));
                }
                else if (didRemove > 1)
                {
                    await chan.SendMessageAsync(Sentences.SongsSkipped((chan as ITextChannel).Guild, didRemove));
                }
                return(didRemove > 0);
            }
Example #3
0
        public async Task LN(params string[] mangaNameArr)
        {
            Base.Utilities.CheckAvailability(Context.Guild, Program.Module.AnimeManga);
            await p.DoAction(Context.User, Program.Module.AnimeManga);

            var result = await Features.Entertainment.AnimeManga.SearchAnime(Features.Entertainment.AnimeManga.SearchType.LightNovel, mangaNameArr, Program.p.kitsuAuth);

            switch (result.error)
            {
            case Error.AnimeManga.Help:
                await ReplyAsync(Sentences.LNHelp(Context.Guild));

                break;

            case Error.AnimeManga.NotFound:
                await ReplyAsync(Sentences.LNNotFound(Context.Guild));

                break;

            case Error.AnimeManga.None:
                if (Context.Guild != null && result.answer.nsfw && !((ITextChannel)Context.Channel).IsNsfw)
                {
                    await ReplyAsync(Base.Sentences.AnswerNsfw(Context.Guild));
                }
                else
                {
                    await ReplyAsync("", false, CreateEmbed(false, result.answer));
                }
                break;

            default:
                throw new NotImplementedException();
            }
        }
Example #4
0
        public async Task Subscribe(params string[] args)
        {
            Base.Utilities.CheckAvailability(Context.Guild.Id, Program.Module.AnimeManga);
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.AnimeManga);

            var result = await Features.Entertainment.AnimeManga.Subscribe(Context.Guild, Program.p.db, args);

            switch (result.error)
            {
            case Error.Subscribe.Help:
                await ReplyAsync(Sentences.SubscribeHelp(Context.Guild.Id));

                break;

            case Error.Subscribe.InvalidChannel:
                await ReplyAsync(Sentences.InvalidChannel(Context.Guild.Id));

                break;

            case Error.Subscribe.None:
                await ReplyAsync(Sentences.SubscribeDone(Context.Guild.Id, "anime", result.answer.chan));

                break;

            default:
                throw new NotImplementedException();
            }
        }
Example #5
0
        private Embed CreateEmbed(bool isAnime, Response.AnimeManga res)
        {
            string       fullName = res.name + ((res.alternativeTitles == null || res.alternativeTitles.Length == 0) ? ("") : (" (" + string.Join(", ", res.alternativeTitles) + ")"));
            EmbedBuilder embed    = new EmbedBuilder()
            {
                Title       = fullName.Length > 256 ? res.name : fullName,
                Url         = res.animeUrl,
                Color       = Color.Green,
                ImageUrl    = res.imageUrl,
                Description = res.synopsis
            };

            if (isAnime && res.episodeCount != null)
            {
                embed.AddField(Sentences.AnimeEpisodes(Context.Guild), res.episodeCount.Value + ((res.episodeLength != null) ? (" " + Sentences.AnimeLength(Context.Guild, res.episodeLength.Value)) : ("")), true);
            }
            if (res.rating != null)
            {
                embed.AddField(Sentences.AnimeRating(Context.Guild), res.rating.Value, true);
            }
            embed.AddField(Sentences.ReleaseDate(Context.Guild), ((res.startDate != null) ? res.startDate.Value.ToString(Base.Sentences.DateHourFormatShort(Context.Guild)) + " - " + ((res.endDate != null) ? (res.endDate.Value.ToString(Base.Sentences.DateHourFormatShort(Context.Guild))) : (Sentences.Unknown(Context.Guild))) : (Sentences.ToBeAnnounced(Context.Guild))), true);
            if (!string.IsNullOrEmpty(res.ageRating))
            {
                embed.AddField(Sentences.AnimeAudiance(Context.Guild), res.ageRating, true);
            }
            return(embed.Build());
        }
Example #6
0
        public async Task StopRadio(params string[] _)
        {
            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
            {
                await radio.Stop();

                p.radios.Remove(radio);
                await ReplyAsync(Base.Sentences.DoneStr(Context.Guild));
            }
        }
Example #7
0
        public async Task AddRadio(params string[] words)
        {
            Utilities.CheckAvailability(Context.Guild.Id, Program.Module.Radio);
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.Radio);

            if (p.youtubeService == null)
            {
                await ReplyAsync(Base.Sentences.NoApiKey(Context.Guild.Id));
            }
            else
            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;
                    }
                }
                var result = await Features.Entertainment.YouTube.SearchYouTube(words, Program.p.youtubeService);

                if (result.error == Features.Entertainment.Error.YouTube.None)
                {
                    RadioChannel radio = p.radios.Find(x => x.m_guildId == Context.Guild.Id);
                    if (radio.ContainMusic(result.answer.url))
                    {
                        await ReplyAsync(Sentences.RadioAlreadyInList(Context.Guild.Id));

                        return;
                    }
                    await ReplyAsync(Sentences.SongAdded(Context.Guild.Id, result.answer.name));

                    string fileName = "Saves/Radio/" + radio.m_guildId + "/" + Utilities.CleanWord(result.answer.name) + ".mp3";
                    radio.AddMusic(fileName, result.answer.name, result.answer.url, result.answer.imageUrl, Context.User.ToString());
                    ProcessStartInfo youtubeDownload = new ProcessStartInfo()
                    {
                        FileName       = "youtube-dl",
                        Arguments      = $"-x --audio-format mp3 -o " + fileName + " " + result.answer.url,
                        CreateNoWindow = true
                    };
                    youtubeDownload.WindowStyle = ProcessWindowStyle.Hidden;
                    Process.Start(youtubeDownload).WaitForExit();
                    radio.StopDownloading(result.answer.url);
                    await radio.Play();
                }
                else
                {
                    await ReplyAsync("YouTube error: " + result.error);
                }
            }
        }
Example #8
0
            public async Task <bool> Skip(IMessageChannel chan)
            {
                if (m_process == null)
                {
                    return(false);
                }
                await chan.SendMessageAsync(Sentences.SongSkipped((chan as ITextChannel).GuildId, m_musics[0].title));

                m_process.Kill();
                return(true);
            }
Example #9
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 #10
0
            public string GetPlaylist(ulong guildId)
            {
                if (m_process == null || m_process.HasExited)
                {
                    return(Sentences.RadioNoSong(guildId));
                }
                string finalStr = "🎵 " + Sentences.Current(guildId) + " " + m_musics[0].title + " requested by " + m_musics[0].requester + Environment.NewLine;

                for (int i = 1; i < m_musics.Count; i++)
                {
                    finalStr += i + ". " + m_musics[i].title + ((m_musics[i].downloading) ? (" " + Sentences.Downloading(guildId)) : ("")) + " requested by " + m_musics[i].requester + Environment.NewLine;
                }
                return(finalStr);
            }
Example #11
0
        public async Task ListRadio(params string[] words)
        {
            Utilities.CheckAvailability(Context.Guild.Id, Program.Module.Radio);
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.Radio);

            if (!p.radios.Any(x => x.m_guildId == Context.Guild.Id))
            {
                await ReplyAsync(Sentences.RadioNotStarted(Context.Guild.Id));
            }
            else
            {
                await ReplyAsync(p.radios.Find(x => x.m_guildId == Context.Guild.Id).GetPlaylist(Context.Guild.Id));
            }
        }
Example #12
0
 public async Task <bool> RemoveSong(IMessageChannel chan, string name)
 {
     if (m_musics.Any(x => x.title == name))
     {
         int index = m_musics.IndexOf(m_musics.Where(x => x.title == name).First());
         if (index == 0)
         {
             return(await Skip(chan));
         }
         else
         {
             string musicTitle = m_musics[index].title;
             m_musics.RemoveAt(index);
             await chan.SendMessageAsync(Sentences.SongSkipped((chan as ITextChannel).Guild, musicTitle));
         }
         return(true);
     }
     return(false);
 }
Example #13
0
        public async Task ListRadio(params string[] _)
        {
            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);

            if (!p.radios.Any(x => x.m_guildId == Context.Guild.Id))
            {
                await ReplyAsync(Sentences.RadioNotStarted(Context.Guild));
            }
            else
            {
                await ReplyAsync(p.radios.Find(x => x.m_guildId == Context.Guild.Id).GetPlaylist(Context.Guild));
            }
        }
Example #14
0
        public async Task Subscribe(params string[] args)
        {
            if (Context.Guild == null)
            {
                await ReplyAsync(Base.Sentences.CommandDontPm(Context.Guild));

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

            if (!Tools.Settings.CanModify(Context.User, Context.Guild))
            {
                await ReplyAsync(Base.Sentences.OnlyOwnerStr(Context.Guild, Context.Guild.OwnerId));
            }
            else
            {
                var result = await Features.Entertainment.AnimeManga.Subscribe(Context.Guild, Program.p.db, args);

                switch (result.error)
                {
                case Error.Subscribe.Help:
                    await ReplyAsync(Sentences.SubscribeHelp(Context.Guild));

                    break;

                case Error.Subscribe.InvalidChannel:
                    await ReplyAsync(Sentences.InvalidChannel(Context.Guild));

                    break;

                case Error.Subscribe.None:
                    await ReplyAsync(Sentences.SubscribeDone(Context.Guild, "anime", result.answer.chan));

                    break;

                default:
                    throw new NotImplementedException();
                }
            }
        }
Example #15
0
        private async Task <bool> StartRadio(IMessageChannel chan)
        {
            if (p.radios.Any(x => x.m_guildId == Context.Guild.Id))
            {
                await chan.SendMessageAsync(Sentences.RadioAlreadyStarted(Context.Guild.Id));

                return(true);
            }
            IGuildUser guildUser = Context.User as IGuildUser;

            if (guildUser.VoiceChannel == null)
            {
                await chan.SendMessageAsync(Sentences.RadioNeedChannel(Context.Guild.Id));

                return(false);
            }
            IAudioClient audioClient = await guildUser.VoiceChannel.ConnectAsync();

            p.radios.Add(new RadioChannel(guildUser.VoiceChannel, Context.Channel, audioClient)); // You need opus.dll and libsodium.dll
            return(true);
        }
Example #16
0
        public async Task SkipRadio(params string[] words)
        {
            Utilities.CheckAvailability(Context.Guild.Id, Program.Module.Radio);
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.Radio);

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

            if (radio == null)
            {
                await ReplyAsync(Sentences.RadioNotStarted(Context.Guild.Id));
            }
            else
            {
                bool suceed = await radio.Skip(Context.Channel);

                if (!suceed)
                {
                    await ReplyAsync(Sentences.RadioNoSong(Context.Guild.Id));
                }
            }
        }
Example #17
0
        public async Task Unsubcribe(params string[] args)
        {
            Base.Utilities.CheckAvailability(Context.Guild.Id, Program.Module.AnimeManga);
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.AnimeManga);

            var result = await Features.Entertainment.AnimeManga.Unsubscribe(Context.Guild, Program.p.db);

            switch (result.error)
            {
            case Error.Unsubscribe.NoSubscription:
                await ReplyAsync(Sentences.NoSubscription(Context.Guild.Id));

                break;

            case Error.Unsubscribe.None:
                await ReplyAsync(Sentences.UnsubscribeDone(Context.Guild.Id, "anime"));

                break;

            default:
                throw new NotImplementedException();
            }
        }
Example #18
0
        public async Task XkcdSearch(params string[] args)
        {
            Base.Utilities.CheckAvailability(Context.Guild.Id, Program.Module.Xkcd);
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.Xkcd);

            var result = await Features.Entertainment.Xkcd.SearchXkcd(args, Program.p.rand);

            switch (result.error)
            {
            case Features.Entertainment.Error.Xkcd.InvalidNumber:
                await ReplyAsync(Sentences.XkcdWrongArg(Context.Guild.Id));

                break;

            case Features.Entertainment.Error.Xkcd.NotFound:
                await ReplyAsync(Sentences.XkcdWrongId(Context.Guild.Id, result.answer.maxNb));

                break;

            case Features.Entertainment.Error.Xkcd.None:
                await ReplyAsync("", false, new EmbedBuilder()
                {
                    Title    = result.answer.title,
                    Color    = Color.Blue,
                    ImageUrl = result.answer.imageUrl,
                    Footer   = new EmbedFooterBuilder()
                    {
                        Text = result.answer.alt
                    }
                }.Build());

                break;

            default:
                throw new NotImplementedException();
            }
        }
Example #19
0
        public async Task Vndb(params string[] args)
        {
            Utilities.CheckAvailability(Context.Guild.Id, Program.Module.Vn);
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.Vn);

            var result = await Vn.SearchVn(args, !((ITextChannel)Context.Channel).IsNsfw);

            switch (result.error)
            {
            case Error.Vn.Help:
                await ReplyAsync(Sentences.VndbHelp(Context.Guild.Id));

                break;

            case Error.Vn.NotFound:
                await ReplyAsync(Sentences.VndbNotFound(Context.Guild.Id));

                break;

            case Error.Vn.None:
                EmbedBuilder embed = new EmbedBuilder()
                {
                    Title       = result.answer.originalTitle == null ? result.answer.title : result.answer.originalTitle + " (" + result.answer.title + ")",
                    Url         = result.answer.vnUrl,
                    ImageUrl    = result.answer.imageUrl,
                    Description = result.answer.description,
                    Color       = Color.Blue
                };
                embed.AddField(Sentences.AvailableEnglish(Context.Guild.Id), result.answer.isAvailableEnglish ? Base.Sentences.YesStr(Context.Guild.Id) : Base.Sentences.NoStr(Context.Guild.Id), true);
                embed.AddField(Sentences.AvailableWindows(Context.Guild.Id), result.answer.isAvailableWindows ? Base.Sentences.YesStr(Context.Guild.Id) : Base.Sentences.NoStr(Context.Guild.Id), true);
                string length = Sentences.Unknown(Context.Guild.Id);
                switch (result.answer.length)
                {
                case VisualNovelLength.VeryShort: length = Sentences.Hours(Context.Guild.Id, "< 2 "); break;

                case VisualNovelLength.Short: length = Sentences.Hours(Context.Guild.Id, "2 - 10 "); break;

                case VisualNovelLength.Medium: length = Sentences.Hours(Context.Guild.Id, "10 - 30 "); break;

                case VisualNovelLength.Long: length = Sentences.Hours(Context.Guild.Id, "30 - 50 "); break;

                case VisualNovelLength.VeryLong: length = Sentences.Hours(Context.Guild.Id, "> 50 "); break;
                }
                embed.AddField(Sentences.Length(Context.Guild.Id), length, true);
                embed.AddField(Sentences.VndbRating(Context.Guild.Id), result.answer.rating + " / 10", true);
                string releaseDate;
                if (result.answer.releaseYear == null)
                {
                    releaseDate = Sentences.Tba(Context.Guild.Id);
                }
                else
                {
                    releaseDate = result.answer.releaseYear.ToString();
                    if (result.answer.releaseMonth != null)
                    {
                        releaseDate = Utilities.AddZero(result.answer.releaseMonth.ToString()) + "/" + releaseDate;
                    }
                    if (result.answer.releaseDay != null)
                    {
                        releaseDate = Utilities.AddZero(result.answer.releaseDay.ToString()) + "/" + releaseDate;
                    }
                }
                embed.AddField(Sentences.ReleaseDate(Context.Guild.Id), releaseDate, true);
                await ReplyAsync("", false, embed.Build());

                break;

            default:
                throw new NotImplementedException();
            }
        }
Example #20
0
        public async Task Source(params string[] args)
        {
            Base.Utilities.CheckAvailability(Context.Guild.Id, Program.Module.AnimeManga);
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.AnimeManga);

            bool skipBeginning = false;

            if (Context.Message.Attachments.Count > 0)
            {
                args          = new[] { Context.Message.Attachments.ToArray()[0].Url };
                skipBeginning = true;
            }
            var result = await Features.Entertainment.AnimeManga.SearchSource(((ITextChannel)Context.Channel).IsNsfw, skipBeginning, Program.p.websiteUpload, Program.p.websiteUploadToken, args);

            switch (result.error)
            {
            case Error.Source.None:
                Color color;
                float certitude = result.answer.compatibility;
                if (certitude > 80f)
                {
                    color = Color.Green;
                }
                else if (certitude > 50)
                {
                    color = Color.Orange;
                }
                else
                {
                    color = Color.Red;
                }
                await ReplyAsync("", false, new EmbedBuilder
                {
                    Color       = color,
                    Title       = result.answer.name,
                    Description = Sentences.Episode(Context.Guild.Id) + " " + (result.answer.episode == -1 ? Sentences.Unknown(Context.Guild.Id) : result.answer.episode.ToString()) + " " + Base.Sentences.AtStr(Context.Guild.Id) + " " + result.answer.at,
                    ImageUrl    = result.answer.imageUrl,
                    Footer      = new EmbedFooterBuilder
                    {
                        Text = Sentences.Certitude(Context.Guild.Id) + ": " + result.answer.compatibility.ToString("0.00") + "%"
                    }
                }.Build());

                break;

            case Error.Source.Help:
                await ReplyAsync(Sentences.SourceHelp(Context.Guild.Id));

                break;

            case Error.Source.NotFound:
                await ReplyAsync(Tools.Sentences.NotAnImage(Context.Guild.Id));

                break;

            case Error.Source.NotNsfw:
                await ReplyAsync(Base.Sentences.AnswerNsfw(Context.Guild.Id));

                break;

            case Error.Source.NotAnUrl:
                await ReplyAsync(Sentences.NotAnUrl(Context.Guild.Id));

                break;

            default:
                throw new NotImplementedException();
            }
        }