承接 hitmare/unlockptb 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hitmare/unlockptb

Composer 安装命令:

composer require hitmare/unlockptb

包简介

PHP Telegram Bot Lock and Unlock

README 文档

README

Table of Contents

Introduction

This is unlock Class for the PHP Telegram Bot Libary to lock an unlock the Bot in Private and Group Channels

Instructions

Installation

Install this package through [Composer][composer]. Edit your project's composer.json file to require hitmare/unlockptb.

Edit composer.json file and add hitmare/unlockptb under require

{
    "name": "yourproject/yourproject",
    "type": "project",
    "require": {
        "php": ">=5.5",
        "longman/telegram-bot": "*",
        "hitmare/unlockptb": "*"
    }
}

and run composer update

or

run this command in your command line:

composer require hitmare/unlockptb
  • Then you have to import the chat_unlock.sql file into your existend Telegram Database

  • Add the following into the hook.php where $telegram->setCommandConfig is located

    $unlockptb = array('private','group','supergroup');
    $telegram->setCommandConfig('lockstatus', ['lockChat' => $unlockptb]);
    $telegram->setCommandConfig('lock', ['lockChat' => $unlockptb]);
    $telegram->setCommandConfig('unlock', ['lockChat' => $unlockptb]);

You also have to add for every Command what you want to lock a CommandConfig line in the hook.php
eg

    $telegram->setCommandConfig('lockedcommand', ['lockChat' => $unlockptb]);

Add the Lockstatus Check to your Files

To use the Libary you have to add the Code for checking the Lockstatus in every Command File where you want to include the Lock function. At the Moment it is, as far as i know, the only way to implement this without editing the Main Code of the Bot

  • Add the required Namespace
    use Hitmare\UnlockPTB\Unlock;
  • Add the Lockstatus Check as first inside the execute() funciton
    $message    = $this->getMessage();
    $chat_id    = $message->getChat()->getId();
    $isUnlocked = Unlock::isUnlocked($chat_id);

    $lockChat = $this->getConfig('lockChat');
    $thisChat = $message->getChat()->getType();
    //Check if the lock applys to this Chat Type
    if (in_array($thisChat,$lockChat)) {
      //Check if Command is unlocked
      if (!$isUnlocked) {
        $data = ['chat_id' => $chat_id, 'text' => 'This Command is locked inside this Chat'];
        return Request::sendMessage($data);
      }
    }

    // Your Code down here

To define in wich Type of Chat the Lock should applys, just add or delete the Chat type in the hoop.php

    $unlockptb = array('private','group','supergroup');

The Lock applys to every Chat that matches the type of the Array above.

How to use

  1. Generate the Authkey

To generate the Authkey there are two ways:
Get the wanted Chat or User ID through the /chats * Command and execute /getAutchkey <id> directly to the Bot

OR

(Only for Group Chats) Execute /getAutchkey inside of the Group Chat and the Bot will send the Botadmin who send the Command the Authkey

  1. Unlock the Bot For Private Chat:
    • Execute /unlock <Authkey> and the Bot will be unlocked. For Group Chats:
    • Execute /unlock <Authkey> as an Bot Admin or as an Channel Owner and the Bot will be unlocked.

To Lock the Bot execute /lock. In Group Chats only the Bot Admin and the Group Chat Owner can use it
To Show the Lockstatus execute /lockstatus. In Group Chats only the Bot Admin and the Group Chat Owner can use it

Aviable Commands

This Library includes four (4) Commands

  • /getAuthkey - Generates the Unlock Authkey. Can only be used from Bot Admin
  • /unlock - Unlocks the Bot. In Group Chats only the Bot Admin and the Group Chat Owner can use it
  • /lock - Locks the Bot. In Group Chats only the Bot Admin and the Group Chat Owner can use it
  • /lockstatus - Shows the Lockstatus of the Bot. In Group Chats only the Bot Admin and the Group Chat Owner can use it

Installation of the Commands

You can copy all four Commands into your custom Command folder or add the following path to your custom Command array inside of your hook.php to stay up to date with your Commandfiles

/vendor/hitmare/unlockptb/Commands/

eg:

$commands_path = [
__DIR__ . '/Commands/',
__DIR__ . '/vendor/hitmare/unlockptb/Commands/',
];

统计信息

  • 总下载量: 72
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-09-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固