KitDevguides

KitDev / Guides / Plugins and structure

Plugins and structure

Creating a plugin

Create a file in kitdev/plugins/, for example kitdev/plugins/hola.py:

# kitdev/plugins/hola.py

from kitdev.core.decorators import cmd


@cmd("hola", "Saluda")
async def hola(client, message):
    await message.edit_text("Hola!")

Restart the userbot with .restart. The plugin loads by itself and the command appears in the .help menu, with the description you gave it.

Convention: put a comment with the file path on the first line of every new file, as in the example (# kitdev/plugins/hola.py).

Auto-delete. If the owner turns on auto-delete, your command's reply deletes itself when it finishes successfully. Addon commands are not deleted by default and the project plugins' are, except those that show information. To change it for your command, use keep: @cmd("hola", "Saluda", keep=False) deletes it and keep=True keeps it.

Translating your plugin

KitDev speaks Spanish and English, and the language is chosen by the owner in the assistant bot. The texts live in kitdev/locales/es.json and kitdev/locales/en.json, and are used with t():

# kitdev/plugins/hola.py

from kitdev.core.decorators import cmd
from kitdev.core.i18n import t


@cmd("hola", "Saluda")
async def hola(client, message):
    await message.edit_text(t("hola.saludo", name=message.from_user.first_name))

Add the same key in both files:

"hola.saludo": "¡Hola, {name}!"
"hola.saludo": "Hi, {name}!"
  • t("key", data=value) replaces {data} with the value. Other braces in the text are left as they are.
  • If the key is not in the chosen language, Spanish is used; if it isn't there either, the key is shown. Always put the key in both files, with the same variables.
  • Escape with html.escape whatever other people write before passing it to t().
  • JSONs don't allow comments: the first key, _file, carries the file path.
  • The console and the logs group stay in Spanish: don't use t() there.

Descriptions in .help. For the plugins in kitdev/plugins/ you can translate what the .help menu shows:

"cmd.hola": "Saluda a quien responde. Ejemplo: {prefix}hola",
"plugin.hola": "Plugin de ejemplo. Admite <code>HTML</code>."

cmd.<command> replaces the command's description and plugin.<file> adds an explanation under the plugin's title. {prefix} is replaced by your prefix. If they don't exist, the @cmd description is used. Addons always use their own.

Addons with .install

They can also be installed from the official channel: see Addons.

An addon is a plugin you install without touching the code: you reply to a .py file with .install and it is loaded, without restarting. They are stored in data/addons/ (not uploaded to Git) and appear in .help → 🧩 Addons. It needs dev mode active.

Command What it does
.install Replying to a .py file, reviews it and installs it
.install force Installs it even if the review found warnings
.uninstall name Removes an addon. Without a name, lists the installed ones

File requirements: the name in lowercase, numbers and _ (up to 32 characters), under 200 KB, not named like a plugin that already exists and whose commands don't repeat those of another plugin.

Security review. Before installing, KitDev analyzes the code without running it and marks sensitive things with 🔴 (high) or 🟡 (medium). It looks for, among other things:

  • Running text as code (eval, exec) or system commands
  • Reading environment variables or private data (API_HASH, SESSION_STRING, the .env)
  • Deleting or writing files, and loading data or compiled code (pickle, marshal, ctypes)
  • Using Telegram's raw API or exporting the session
  • Importing network modules

If it finds something, it shows the list and does not install. If you trust whoever wrote it, reply to the file again with .install force. If the addon fails to load, it isn't installed either.

An addon runs with access to your account. The review is a help, not a guarantee: read the code before installing something from another person.

Going further

  • Emojis, premium too: Premium emojis
  • Storing data and protecting commands with a key: Dev mode
  • Examples of complete plugins: kitdev/plugins/snips.py (database and translation) and kitdev/plugins/admin.py

Project structure

KitDev/
├── assets/
│   ├── avatars/            # photos for the assistant bot and the .help menu
│   └── banner.png
├── data/                   # created by itself (not uploaded to Git)
│   ├── state.json          # bot token, settings and .setdb values
│   ├── kitdev.sqlite3      # bot users, snips and warnings
│   ├── addons/             # addons installed with .install
│   └── media/              # welcome and .alive media
├── docs/                   # detailed guides
├── kitdev/
│   ├── __init__.py
│   ├── __main__.py
│   ├── addons/             # official addons (uploaded to the channel; not loaded by themselves)
│   ├── config.py
│   ├── core/
│   │   ├── adminbot.py     # assistant bot administrator mode
│   │   ├── antispam.py     # PM Bot blocked alphabets
│   │   ├── assistant.py    # assistant bot and BotFather
│   │   ├── banner.py       # logo and progress bar
│   │   ├── broadcast.py    # assistant mass sending
│   │   ├── checks.py       # .env and version checks
│   │   ├── client.py
│   │   ├── db.py           # key-value database
│   │   ├── decorators.py
│   │   ├── devmode.py      # key, lock and dev_only decorator
│   │   ├── emoji.py        # regular and premium emojis
│   │   ├── errors.py       # explained errors and notices to the logs group
│   │   ├── i18n.py         # texts in Spanish and English
│   │   ├── inline.py       # .help menu with buttons
│   │   ├── loader.py       # plugin and addon loading
│   │   ├── logs.py
│   │   ├── scanner.py      # addon security review
│   │   ├── settings.py     # assistant settings
│   │   ├── snips.py        # snips in SQLite
│   │   ├── state.py
│   │   ├── tz.py           # time zone
│   │   ├── users.py        # bot users in SQLite
│   │   ├── warns.py        # warnings in SQLite
│   │   └── welcome.py      # assistant: /start, settings, PM Bot and broadcast
│   ├── locales/
│   │   ├── en.json         # texts in English
│   │   └── es.json         # texts in Spanish
│   └── plugins/
│       ├── admin.py
│       ├── alive.py
│       ├── botfoto.py
│       ├── dev.py
│       ├── help.py
│       ├── id.py
│       ├── install.py
│       ├── ping.py
│       ├── restart.py
│       └── snips.py
├── gen_session.py
├── .env.example
├── .gitignore
├── LICENSE
├── README.md
└── requirements.txt