AwesomeHamster/koishi-plugin-hitokoto

Feature: Send sentences from local

Closed this issue · 1 comments

It is possible to download hitokoto sentences bundle that open sourced in https://github.com/hitokoto-osc/sentences-bundle
via links mentioned in https://sentences-bundle.hitokoto.cn/ without the license.

So we can add an option to let user to switch to local database that stores these sentences.

Workaround:

Command Invoking

  1. Add an option named source with value local and remote
  2. When a user invoked command, check the value of source
    2.1 If the value is remote, then request to the url of apiUrl to fetch the content.
    2.2 If the value is local, then fetch content from databases (that means send-from-local requires database)
    2.3 If the value is local, but there is no data, or it failed when fetch data from database (e.g. database disconnected), then print a warning message and goes 2.1.
  3. Send the content that fetched above.

Bundle Cache Updating (only if database installed)

  1. Add an option named bundleEndpoint, which would set to https://raw.githubusercontent.com/hitokoto-osc/sentences-bundle/master/ by default. (see https://sentences-bundle.hitokoto.cn/ for more information.)
    1.1 Should also declare its license!!

  2. Add a progress bar or something similar in plugin configuration page, to indicate how large is the cache currently.
    Format:

    • Hitokoto Sentences Cache: <version> <count> sentences, <size>MiB.
    • Remote Sentences Bundle: <version> (update available)
      • Shows (update available) only if remote differs to the local cache.

    2.1 If there is no data, says No Data; otherwise, display the size and count.

  3. Add a button in plugin configuration page, named Fetch Cache (if no data) or Update Cache (if data exists)
    3.1 If user clicked the button, then fetch data from bundleEndpoint
    3.2 Update the information of cache once updated.

  4. Add a command named hitokoto.cache as a sub-command
    4.1 hitokoto.cache fetch command: fetch the sentences bundle cache
    4.2 hitokoto.cache clear command: clear the sentences bundle cache
    4.3 hitokoto.cache info command: view the information of the current cache.
    The format of the command should cover all the information that shows in 2).