Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

line-bot-tool-1.0.tar.gz (11.0 kB view hashes)

Uploaded Source

Built Distribution

line_bot_tool-1.0-py3-none-any.whl (14.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page