Code Monkey home page Code Monkey logo

nsfw-bot's People

Contributors

bird-up73 avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

kira0x1

nsfw-bot's Issues

More sites

Add more sites such as

sankakucomplex (api url = capi-v2.sankakucomplex.com)

Does not fetch counts, so using a random page will be impossible

  • hentai34

Test

Test issue for discord

Generifying even more

The class PostMessage has several methods that can also be used by the PageEmbedMessage, and therefore also by AbstractPost.

These are

  • fetch_total_posts()
  • fetch_post_for_page()

Caching in favorites and history

When scrolling through posts in the favorites and history command, a post is fetched for every time a user scrolls through the pages.
This result should maybe be cached. So that posts are not re-fetched every time.

When storing posts in the history it should be possible to store the whole post?

Refactor on_reaction_add

The on_reaction_add functions are kind of a mess right now?

Is there any way to simplify them, while also using inheritance?

One idea is to use a dictionary with emojis

emojis = {
    '⬅': handle_next_page(),
    '➡': handle_previous_page()
}

For the class handling reactions, the on_reaction_add(reaction, user) should get the emoji, and then

Tangential:

  • Remove ctx from classes?

Folder structure

Files are in folders that dont really explain what they are for

Do not use Cogs?

Since each command requires quite a lot of options, it might be better to create separate classes for them instead of in 1 cog.

Observer pattern

Using the observer pattern might decouple some more dependencies

Refactoring

There is still a lot of code duplication.

I wanna find a way to reduce this.

Some more ideas:

  • Store short url in postdata? Might have disadvantages
  • Make separate class for handling the actual fetching? TODO: How to handle the actual reactions then?

Displaying pages

The pages used in the API might start with 0.
This might need to be corrected for when displaying pages

Add logging in more places

Add logging for the following cases

  • Deleting a message
  • Caching a post
  • Fetching a post that is not cached
  • A nonexistent post is fetched
  • A post is added to the history

Non-random posts

Right now it is only possible to see random posts by reacting with 🔁.

Maybe it should be possible to browse through posts in order.

This should include two reactions for generic post commands.
⬅ and ➡ to cycle through pages

Danbooru does not keep track of page numbers in posts.
This makes it impossible to fetch a random post. Which page are you even on?

Save timestamp for favorite

If a user stores a favorite, the time at which they did so should be stored.

This should be added as a column in the database.
When fetching the favorites, these should be sorted by this datetime.

This makes sure that the class PostHistEntry can be removed, since it would be identical to PostEntry

When a user asks for favorites, the embed timestamp should show when the favorite was saved in the timstamp.

Delete posts

Right now posts are probably not deleted.

There should be a cog to manage posts and delete them if a message is deleted.

Events and observers

There are three events that would be nice to handle.

  1. If a user adds a favorite. This should update all favorites messages for that user.
  2. If a user removes a favorite. This should update all favorites messages for that user.
  3. If the history gets updated. This should update all history messages for a specific channel.

Composition over inheritance

There is more inheritance than composition right now, this should be changed.

It might be useful to define responsibilities per class to give these the appropriate methods.

How to handle the FavoritesMessage behavior though? How to delete favorites and handle reactions?

Guild-specific history

The post history is stored globally. This history should be stored per guild and/or DM.

Handle deleted posts

If the favorites or history contain a deleted post, this should be shown in the embed.

It should also not be possible to store a deleted post as favorite.

Generify URL usage

Make sure all URLs are used in one place.

Especially the URL for danbooru.

Favorites

Find a way to store favorites.

  • Add an emoji that users can use to add something to their favorites
  • Add a way so that users can get their list of favorites
  • Remove favorites? Conflict with removing previous posts

Handle disallowed posts while refreshing

When refreshing a post, there should be some kind of embed showing an error if the post contains a disallowed tag.

It should still be possible to refresh again or delete.

The Post class should have an abstract method is_allowed().

The PostData should have an extension class that displays an error.
An abstract class AbstractPostData or something should be added.

Fetch amount of posts for XML api only once

For xml-based APIs the total amount of posts is fetched for every request that is made.

This should only be done once since it will probably increase performance.

One disadvantage is that the total amount of posts can change while you browse.
However this probably does not have a lot of impact, since you only don't see posts that were created after u requested them.

Use JSON instead of XML in APIs

Instead of fetching post information in XML format, check if it is possible to use JSON.
It will be easier to parse and u only need one parser.

TODO:

  • Check if all sites support JSON
  • Check if all sites return similar JSON

Messageable content class

A lot of different classes use logic to create a dict with message content:

dict(content=..., embed=...)

and will create embeds depending on whether content is set.

It would probably be better to create a class that handles this.

Command groups

The bot has lots of different commands, maybe it is good to put them in separate groups.

This will make the help command shorter, and might make it easier to see which command goes where.
A possible disadvantage of using groups is that I don't know if u can invoke commands on their own if they are in a group.

This is something I need to figure out.

Store posts by id

It might be better to store posts by ID instead of several attributes used now.

This makes it possible to scroll through favorites and post history easier.

It also makes it possible to store both animated and static posts.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.