コード例 #1
0
ファイル: Doujinshi.cs プロジェクト: TheIndra55/Sanara
        public async Task GetDownloadCosplay(params string[] args)
        {
            Base.Utilities.CheckAvailability(Context.Guild, Program.Module.Doujinshi);
            await p.DoAction(Context.User, Program.Module.Doujinshi);
            IMessage msg = null;
            var result = await Features.NSFW.Doujinshi.SearchDownloadCosplay(Context.Channel is ITextChannel ? !((ITextChannel)Context.Channel).IsNsfw : false, args, async () =>
            {
                msg = await ReplyAsync("Preparing download, this might take some time...");
            });
            switch (result.error)
            {
                case Features.NSFW.Error.Download.ChanNotSafe:
                    await ReplyAsync(Base.Sentences.ChanIsNotNsfw(Context.Guild));
                    break;

                case Features.NSFW.Error.Download.Help:
                    await ReplyAsync(Sentences.DownloadCosplayHelp(Context.Guild));
                    break;

                case Features.NSFW.Error.Download.NotFound:
                    await ReplyAsync(Sentences.DownloadCosplayNotFound(Context.Guild));
                    break;

                case Features.NSFW.Error.Download.None:
                    await GetDownloadResult(msg, result.answer);
                    break;

                default:
                    throw new NotImplementedException();
            }
        }
コード例 #2
0
        private static async Task PostImage(ABooru booru, IMessageChannel chan, string[] tags, IGuild guild, ulong userId)
        {
            var result = await Features.NSFW.Booru.SearchBooru(chan is ITextChannel? !((ITextChannel)chan).IsNsfw : false, tags, booru, Program.p.rand);

            switch (result.error)
            {
            case Features.NSFW.Error.Booru.ChanNotNSFW:
                await chan.SendMessageAsync(Base.Sentences.ChanIsNotNsfw(guild));

                break;

            case Features.NSFW.Error.Booru.NotFound:
                await chan.SendMessageAsync(Base.Sentences.TagsNotFound(guild, tags));

                break;

            case Features.NSFW.Error.Booru.None:
                IUserMessage msg;
                if (!Utilities.IsImage(result.answer.url))
                {
                    msg = await chan.SendMessageAsync(result.answer.url + Environment.NewLine + "*" + Sentences.ImageInfo(guild, result.answer.saveId) + "*");
                }
                else
                {
                    msg = await chan.SendMessageAsync("", false, new EmbedBuilder()
                    {
                        Color    = result.answer.colorRating,
                        ImageUrl = result.answer.url,
                        Footer   = new EmbedFooterBuilder()
                        {
                            Text = (result.answer.newTags != null ? "Some of your tags were invalid. The current search tags are: " + string.Join(", ", result.answer.newTags) + "\n\n" :
                                    "") + (result.answer.saveId == null ? "" : Sentences.ImageInfo(guild, result.answer.saveId))
                        }
                    }.Build());
                }
                foreach (string t in tags)
                {
                    await Program.p.cm.ProgressAchievementAsync(AchievementID.DoDifferentsBoorus, 1, t.GetHashCode().ToString(), msg, userId);
                }
                if (Program.p.sendStats)
                {
                    await Program.p.UpdateElement(new Tuple <string, string>[] { new Tuple <string, string>("booru", booru.ToString().Split('.').Last().ToLower()) });
                }
                break;

            default:
                throw new NotImplementedException();
            }
        }
コード例 #3
0
ファイル: Doujinshi.cs プロジェクト: TheIndra55/Sanara
 public Embed CreateFinalEmbed(Features.NSFW.Response.Doujinshi result, Func<IGuild, string, string> downloadInfo)
 {
     return new EmbedBuilder()
     {
         Color = new Color(255, 20, 147),
         Description = string.Join(", ", result.tags),
         Title = result.title,
         Url = result.url,
         ImageUrl = result.imageUrl,
         Footer = new EmbedFooterBuilder()
         {
             Text = Sentences.ClickFull(Context.Guild) + (downloadInfo == null ? "" : "\n\n" + downloadInfo(Context.Guild, result.id.ToString()))
         }
     }.Build();
 }
コード例 #4
0
 public Embed CreateFinalEmbed(Features.NSFW.Response.Doujinshi result, ulong guildId)
 {
     return(new EmbedBuilder()
     {
         Color = new Color(255, 20, 147),
         Description = string.Join(", ", result.tags),
         Title = result.title,
         Url = result.url,
         ImageUrl = result.imageUrl,
         Footer = new EmbedFooterBuilder()
         {
             Text = Sentences.ClickFull(guildId)
         }
     }.Build());
 }
コード例 #5
0
ファイル: Doujinshi.cs プロジェクト: TheIndra55/Sanara
        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.Doujinshi);
            await p.DoAction(Context.User, Program.Module.Doujinshi);
            if (!Tools.Settings.CanModify(Context.User, Context.Guild))
            {
                await ReplyAsync(Base.Sentences.OnlyOwnerStr(Context.Guild, Context.Guild.OwnerId));
            }
            else
            {
                var result = await Features.NSFW.Doujinshi.Subscribe(Context.Guild, Program.p.db, args, !((ITextChannel)Context.Channel).IsNsfw);
                switch (result.error)
                {
                    case Features.NSFW.Error.Subscribe.ChanNotSafe:
                        await ReplyAsync(Base.Sentences.ChanIsNotNsfw(Context.Guild));
                        break;

                    case Features.NSFW.Error.Subscribe.DestChanNotSafe:
                        await ReplyAsync(Sentences.SubscribeSafeDestination(Context.Guild));
                        break;

                    case Features.NSFW.Error.Subscribe.Help:
                        await ReplyAsync(Sentences.SubscribeNHentaiHelp(Context.Guild));
                        break;

                    case Features.NSFW.Error.Subscribe.InvalidChannel:
                        await ReplyAsync(Entertainment.Sentences.InvalidChannel(Context.Guild));
                        break;

                    case Features.NSFW.Error.Subscribe.None:
                        await ReplyAsync(Entertainment.Sentences.SubscribeDone(Context.Guild, "doujinshi", result.answer.chan) + Environment.NewLine
                            + Sentences.Blacklist(Context.Guild) + result.answer.subscription.GetBlacklistTags() + Environment.NewLine
                            + Sentences.Whitelist(Context.Guild) + result.answer.subscription.GetWhitelistTags());
                        break;

                    default:
                        throw new NotImplementedException();
                }
            }
        }
コード例 #6
0
        private static async Task PostImage(BooruSharp.Booru.Booru booru, ITextChannel chan, string[] tags, ulong guildId)
        {
            var result = await Features.NSFW.Booru.SearchBooru(!chan.IsNsfw, tags, booru, Program.p.rand);

            switch (result.error)
            {
            case Features.NSFW.Error.Booru.ChanNotNSFW:
                await chan.SendMessageAsync(Base.Sentences.ChanIsNotNsfw(chan.GuildId));

                break;

            case Features.NSFW.Error.Booru.NotFound:
                await chan.SendMessageAsync(Base.Sentences.TagsNotFound(guildId, tags));

                break;

            case Features.NSFW.Error.Booru.None:
                if (!Utilities.IsImage(result.answer.url.Split('.').Last()))
                {
                    await chan.SendMessageAsync(result.answer.url + Environment.NewLine + "*" + Sentences.ImageInfo(guildId, result.answer.saveId) + "*");
                }
                else
                {
                    await chan.SendMessageAsync("", false, new EmbedBuilder()
                    {
                        Color    = result.answer.colorRating,
                        ImageUrl = result.answer.url,
                        Footer   = new EmbedFooterBuilder()
                        {
                            Text = Sentences.ImageInfo(guildId, result.answer.saveId)
                        }
                    }.Build());
                }
                if (Program.p.sendStats)
                {
                    await Program.p.UpdateElement(new Tuple <string, string>[] { new Tuple <string, string>("booru", booru.ToString().Split('.').Last().ToLower()) });
                }
                break;

            default:
                throw new NotImplementedException();
            }
        }
コード例 #7
0
        public async Task TagsSearch(params string[] tags)
        {
            Base.Utilities.CheckAvailability(Context.Guild.Id, Program.Module.Booru);
            await p.DoAction(Context.User, Context.Guild.Id, Program.Module.Booru);

            var result = await Features.NSFW.Booru.SearchTags(tags);

            switch (result.error)
            {
            case Features.NSFW.Error.BooruTags.NotFound:
                await ReplyAsync(Sentences.InvalidId(Context.Guild.Id));

                break;

            case Features.NSFW.Error.BooruTags.Help:
                await ReplyAsync(Sentences.HelpId(Context.Guild.Id));

                break;

            case Features.NSFW.Error.BooruTags.None:
                EmbedBuilder eb = new EmbedBuilder()
                {
                    Color       = result.answer.rating,
                    Title       = result.answer.booruName,
                    ImageUrl    = result.answer.imageUrl.AbsoluteUri,
                    Description = result.answer.width + " x " + result.answer.height +
                                  (result.answer.width == result.answer.aspectRatio.Item1 ? "" : " (" + result.answer.aspectRatio.Item1 + ":" + result.answer.aspectRatio.Item2 + ")")
                };
                eb.AddField(((result.answer.sourceTags.Length > 1) ? (Sentences.Sources(Context.Guild.Id)) : (Sentences.Source(Context.Guild.Id))), "`" + string.Join(", ", result.answer.sourceTags) + "`");
                eb.AddField(((result.answer.characTags.Length > 1) ? (Sentences.Characters(Context.Guild.Id)) : (Sentences.Character(Context.Guild.Id))), "`" + string.Join(", ", result.answer.characTags) + "`");
                eb.AddField(((result.answer.artistTags.Length > 1) ? (Sentences.Artists(Context.Guild.Id)) : (Sentences.Artist(Context.Guild.Id))), "`" + string.Join(", ", result.answer.artistTags) + "`");
                await ReplyAsync("", false, eb.Build());

                break;

            default:
                throw new NotImplementedException();
            }
        }
コード例 #8
0
ファイル: Doujinshi.cs プロジェクト: TheIndra55/Sanara
 public async Task GetDownloadResult(IMessage msg, Features.NSFW.Response.Download answer)
 {
     FileInfo fi = new FileInfo(answer.filePath);
     if (fi.Length < 8000000)
         await Context.Channel.SendFileAsync(answer.filePath);
     else
     {
         if (Program.p.websiteUpload == null)
             throw new NullReferenceException("File bigger than 8MB and websiteUpload key null");
         else
         {
             string now = DateTime.Now.ToString("yyyyMMddHHmmss");
             Directory.CreateDirectory(Program.p.websiteUpload + "/" + now);
             File.Copy(answer.filePath, Program.p.websiteUpload + "/" + now + "/" + answer.id + ".zip");
             await ReplyAsync(Program.p.websiteUrl + "/" + now + "/" + answer.id + ".zip" + Environment.NewLine + Sentences.DeleteTime(Context.Guild, "10"));
             _ = Task.Run(async () =>
             {
                 await Task.Delay(600000); // 10 minutes
                 File.Delete(Program.p.websiteUpload + "/" + now + "/" + answer.id + ".zip");
                 Directory.Delete(Program.p.websiteUpload + "/" + now);
             });
         }
     }
     await msg.DeleteAsync();
     File.Delete(answer.filePath);
     Directory.Delete(answer.directoryPath);
 }
コード例 #9
0
ファイル: Doujinshi.cs プロジェクト: TheIndra55/Sanara
 public async Task GetDownloadDefault(params string[] _)
 {
     Base.Utilities.CheckAvailability(Context.Guild, Program.Module.Doujinshi);
     await p.DoAction(Context.User, Program.Module.Doujinshi);
     await ReplyAsync(Sentences.DownloadHelp(Context.Guild));
 }