Useful tool for line bot
Project description
line-bot-tool
LINEBot用の便利ツール
PIP
pipからインストール可能
$ pip install line-bot-tool
Usage
LINEBotで使用するコマンドを生成
$ lb-tool gen:command help
Generate success! commands/help_command.py
デフォルトで ./commands 配下に生成される。
環境変数 COMMAND_OUTPUT_PATH に設定することで、生成されるファイルの保存場所を変更できる。
生成されたファイル
# Generated by CommandGenerator on 2021-06-23 20:55:00
from typing import Optional, Tuple
from line_bot_tool.base.commnad import BaseCommand
from . import settings
class HelpCommand(BaseCommand):
prefixes: Optional[Tuple[str, ...]] = settings.PREFIXES
cmd: str = 'help'
description: str = 'Please input here command description.'
同じ階層のディレクトリに settings.py が生成される。
# Generated by CommandGenerator on 2021-06-23 20:55:00
from typing import Optional, Tuple
PREFIXES: Optional[Tuple[str, ...]] = ('/', '@')
PREFIXES の値を書き換えることでコマンドの接頭辞を設定できる。
接頭辞が費用な場合は、None を入れる。
from commands.help_command import HelpCommand
HelpCommand.is_executable('/help') # True
HelpCommand.is_executable('@help') # True
HelpCommand.is_executable('help') # False
引数があるコマンドの場合
例えば、/name:引数 というコマンド(引数にユーザーIDを指定し、名前を返す)がある場合、以下のようにコマンドの生成、判定を行う。
また、接頭辞は / のみとする。
$ lb-tool gen:command name
Generate success! commands/name_command.py
commands/name_command.py を少し書き換え。
# Generated by CommandGenerator on 2021-06-23 21:34:39
from typing import Optional, Tuple
from line_bot_tool.base.commnad import BaseCommand
from . import settings
class NameCommand(BaseCommand):
- prefixes: Optional[Tuple[str, ...]] = settings.PREFIXES
- cmd: str = 'name'
+ prefixes: Optional[Tuple[str, ...]] = ('/')
+ cmd: str = 'name:'
description: str = 'Please input here command description.'
from commands.name_command import NameCommand
NameCommand.is_executable_with_arg('/name:UXXXXXXXXXX') # True, UXXXXXXXXXX
# セイウチ演算子を使って書く
if (result := NameCommand.is_executable_with_arg('/name:UXXXXXXXXXX'))[0]:
print(result[1]) # UXXXXXXXXXX
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file line-bot-tool-1.0.tar.gz.
File metadata
- Download URL: line-bot-tool-1.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2d97e9ea1dda5f3a857d42c8772bfdeb206f3a6913454238a7526e08453b057
|
|
| MD5 |
4aeba5144b4625062857b384fe898213
|
|
| BLAKE2b-256 |
29ec85380c8a2c217a7b960df8fc6b3accbfbe1c9fdbaae1adcc24082b484d43
|
File details
Details for the file line_bot_tool-1.0-py3-none-any.whl.
File metadata
- Download URL: line_bot_tool-1.0-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ef85769c48aadeb38467b3fd0dfcba907d5b2e9eab2363c9514d9d736633b724
|
|
| MD5 |
27f50431bddb2ca77b71a3169f4da4fd
|
|
| BLAKE2b-256 |
15eb1cb6cc9ccaa1f3f0b497e434902e58108b4a01d4babb50eee4e543185d05
|