Konfigurasi dan penyimpanan

Konfigurasi dan Penyimpanan Permanen

Seperti yang dijelaskan di Direktori, masing-masing modul telah dialokasikan dengan sebuah folder per profil untuk konfigurasi dan penyimpanan lainnya. Path dapat diperoleh dengan menggunakan get_data_path() dengan ID modul anda. Semua penyimpanan seperti itu dikhususkan hanya untuk satu profil.

Untuk konfigurasi, kami sarankan untuk menggunakan `` <module_data_path> / config.yaml``. Demikian pula, kami menyiapkan :meth: ~ .ehforwarderbot.utils.get_config_path untuk mendapatkan path untuk file konfigurasi default. Sekali lagi, Anda tidak dipaksa untuk menggunakan nama ini atau YAML sebagai format file konfigurasi Anda.

Biasanya di folder penyimpanan tinggal:

  • File konfigurasi

  • Kredensial pengguna / penyimpanan sesi

  • Database

Penyimpanan Sementara

Saat memproses pesan multimedia, kita pasti perlu menyimpan file tertentu untuk sementara, baik di dalam saluran maupun di saluran. Biasanya, file sementara bisa ditangani dengan perpustakaan tempfile Python.

Wizard

If your module requires relatively complicated configuration, it would be helpful to provide users with a wizard to check prerequisites of your module and guide them to setup your module for use.

From version 2, EFB introduced a centralised wizard program to allow users to enable or disable modules in a text-based user interface (TUI). If you want to include your wizard program as a part of the wizard, you can include a new entry point in your setup.py with Setuptools' Entry Point feature.

The group for wizard program is ehforwarderbot.wizard, and the entry point function MUST accept 2 positional arguments: profile ID and instance ID.

Example

setup.py script

setup(
    # ...
    entry_points={
        "ehforwarderbot.wizard": ['alice.irc = efb_irc_slave.wizard:main']
    },
    # ...
)

.egg-info/entry_points.txt

[ehforwarderbot.wizard]
alice.irc = efb_irc_slave.wizard:main

efb_irc_slave/wizard.py

# ...

def main(profile, instance):
    print("Welcome to the setup wizard of my channel.")
    print("You are setting up this channel in profile "
          "'{0}' and instance '{1}'.".format(profile, instance))
    print("Press ENTER/RETURN to continue.")
    input()

    step1()

    # ...