Example #1
0
        public async Task AddAsync(string name,
                                   string source,
                                   string id,
                                   CancellationToken cancellationToken = default)
        {
            name = FixCollectionName(name);

            Doujin     doujin;
            Collection collection;

            do
            {
                collection = await _database.GetCollectionAsync(_context.User.Id, name, cancellationToken);

                if (collection == null)
                {
                    collection = new Collection
                    {
                        Name    = name,
                        OwnerId = _context.User.Id,
                        Doujins = new List <CollectionRef>()
                    };

                    _database.Add(collection);
                }

                doujin = await _database.GetDoujinAsync(GalleryUtility.ExpandContraction(source),
                                                        id,
                                                        cancellationToken);

                if (doujin == null)
                {
                    await _context.ReplyAsync("doujinNotFound");

                    return;
                }

                if (collection.Doujins.Any(x => x.DoujinId == doujin.Id))
                {
                    await _context.ReplyAsync("alreadyInCollection", new { doujin, collection });

                    return;
                }

                collection.Doujins.Add(new CollectionRef
                {
                    DoujinId = doujin.Id
                });
            }while (!await _database.SaveAsync(cancellationToken));

            await _context.ReplyAsync("addedToCollection", new { doujin, collection });
        }
Example #2
0
        public async Task RemoveAsync(string name,
                                      string source,
                                      string id,
                                      CancellationToken cancellationToken = default)
        {
            name = FixCollectionName(name);

            Doujin     doujin;
            Collection collection;

            do
            {
                collection = await _database.GetCollectionAsync(_context.User.Id, name, cancellationToken);

                if (collection == null)
                {
                    await _context.ReplyAsync("collectionNotFound", new { name });

                    return;
                }

                doujin = await _database.GetDoujinAsync(GalleryUtility.ExpandContraction(source),
                                                        id,
                                                        cancellationToken);

                if (doujin == null)
                {
                    await _context.ReplyAsync("doujinNotFound");

                    return;
                }

                var item = collection.Doujins.FirstOrDefault(x => x.DoujinId == doujin.Id);

                if (item == null)
                {
                    await _context.ReplyAsync("notInCollection", new { doujin, collection });

                    return;
                }

                collection.Doujins.Remove(item);
            }while (!await _database.SaveAsync(cancellationToken));

            await _context.ReplyAsync("removedFromCollection", new { doujin, collection });
        }
Example #3
0
        public async Task GetAsync(string source,
                                   string id,
                                   CancellationToken cancellationToken = default)
        {
            var doujin = await _database.GetDoujinAsync(GalleryUtility.ExpandContraction(source),
                                                        id,
                                                        cancellationToken);

            if (doujin == null)
            {
                await _context.ReplyAsync("doujinNotFound");

                return;
            }

            await _interactive.SendInteractiveAsync(new DoujinMessage(doujin), _context, cancellationToken);
        }
Example #4
0
        public async Task SearchAsync(string query,
                                      string source = null,
                                      CancellationToken cancellationToken = default)
        {
            if (string.IsNullOrEmpty(query))
            {
                await _context.ReplyAsync("invalidQuery", new { query });

                return;
            }

            await _interactive.SendInteractiveAsync(
                new DoujinListFromQueryMessage(new DoujinSearchArgs
            {
                Query = query,
                QualityFilter = false,
                Source = GalleryUtility.ExpandContraction(source)
            }),
                _context,
                cancellationToken);
        }