_1001_command.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:coolq-telegram-bot 作者: jqqqqqqqqqq 项目源码 文件源码
def tg_command(bot: telegram.Bot,
               update: telegram.Update):
    if update.edited_message:  # handle edit
        message: telegram.Message = update.edited_message
    else:
        message: telegram.Message = update.message

    if not message.text.startswith('!!'):  # no command indicator
        return

    tg_group_id = message.chat_id  # telegram group id
    tg_reply_to = message.reply_to_message

    text = message.text[2:]

    for command in global_vars.command_list:  # process all non-forward commands
        if command.tg_only and (text == command.command or text == command.short_command):
            command.handler(tg_group_id=tg_group_id,
                            tg_user=message.from_user,
                            tg_message_id=message.message_id,
                            tg_reply_to=tg_reply_to)
            raise DispatcherHandlerStop()

    forward_index = get_forward_index(tg_group_id=tg_group_id)
    if forward_index == -1:
        raise DispatcherHandlerStop()

    for command in global_vars.command_list:  # process all forward commands
        if not command.tg_only and not command.qq_only and (text == command.command or text == command.short_command):
            command.handler(forward_index,
                            tg_user=message.from_user,
                            tg_group_id=tg_group_id,
                            tg_message_id=message.message_id,
                            tg_reply_to=tg_reply_to)
            raise DispatcherHandlerStop()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号