Skip to content

Commit

Permalink
Bug Fix Class and Authkey Command
Browse files Browse the repository at this point in the history
Renamed 'key' DB row to 'authkey' due MySQL name reservation

Fixed REAMDE
  • Loading branch information
Hitmare committed Sep 24, 2017
1 parent 11b382e commit 2450207
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Commands/getAuthkeyCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public function execute()

$data['chat_id'] = $user_id;

if (!$message->getChat()->getTye() === 'privat' && $extchat == ''){
if ($message->getChat()->getTye() != 'private' && $extchat == ''){
$extchat = $chat_id;
}
elseif ($extchat == ''){
elseif ($message->getChat()->getTye() === 'private' && $extchat == ''){
$text = 'Please use the Command with a Chat ID in the private Chat or use the Command in the Group where you want to generate the Authkey for the Chat';
}

Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ composer require hitmare/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

```php
$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.
Expand All @@ -71,10 +79,10 @@ At the Moment it is, as far as i know, the only way to implement this without ed
$lockChat = $this->getConfig('lockChat');
$thisChat = $message->getChat()->getType();
//Check if the lock applys to this Chat Type
if (!in_array($thisChat,$lockChat)) {
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'];
if (!$isUnlocked) {
$data = ['chat_id' => $chat_id, 'text' => 'This Command is locked inside this Chat'];
return Request::sendMessage($data);
}
}
Expand Down
31 changes: 2 additions & 29 deletions chat_unlock.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
-- phpMyAdmin SQL Dump
-- version 4.2.12deb2+deb8u2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Erstellungszeit: 20. Sep 2017 um 18:40
-- Server Version: 5.5.57-0+deb8u1
-- PHP-Version: 5.6.30-0+deb8u1


SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
Expand All @@ -16,40 +9,20 @@ SET time_zone = "+00:00";
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

--
-- Datenbank: `telbot`
--

-- --------------------------------------------------------

--
-- Tabellenstruktur für Tabelle `chat_unlock`
--

CREATE TABLE IF NOT EXISTS `chat_unlock` (
`id` int(11) NOT NULL,
`chat` bigint(20) NOT NULL,
`status` tinyint(1) NOT NULL DEFAULT '0',
`key` varchar(100) NOT NULL
`authkey` varchar(100) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;

--
-- Indizes der exportierten Tabellen
--

--
-- Indizes für die Tabelle `chat_unlock`
--
ALTER TABLE `chat_unlock`
ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT für exportierte Tabellen
--

--
-- AUTO_INCREMENT für Tabelle `chat_unlock`
--
ALTER TABLE `chat_unlock`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=1;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
Expand Down
8 changes: 4 additions & 4 deletions src/Unlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public static function unlockChannel($chat_id, $key)

try {
$pdo = DB::getPdo();
$sql = 'SELECT `key` FROM `chat_unlock` WHERE `chat` = :chat';
$sql = 'SELECT `authkey` FROM `chat_unlock` WHERE `chat` = :chat';
$sth = $pdo->prepare($sql);
$sth->bindValue(':chat', $chat_id);
$sth->execute();
Expand Down Expand Up @@ -162,21 +162,21 @@ public static function getAuthKey($chat_id)
//generate and store key
$key = uniqid();
$pdo = DB::getPdo();
$sql = 'UPDATE `chat_unlock` SET `key` = :key WHERE `chat` = :chat';
$sql = 'UPDATE `chat_unlock` SET `authkey` = :key WHERE `chat` = :chat';
$sth = $pdo->prepare($sql);
$sth->bindValue(':chat', $chat_id);
$sth->bindValue(':key', $key);
$sth->execute();

// check if key is stored properly

$sql2 = 'SELECT `key` FROM `chat_unlock` WHERE `chat` = :chat';
$sql2 = 'SELECT `authkey` FROM `chat_unlock` WHERE `chat` = :chat';
$sth2 = $pdo->prepare($sql2);
$sth2->bindValue(':chat', $chat_id);
$sth2->execute();
$key_db = $sth2->fetch();
// send key if the key is stored properly. Else send Error message
if ($key_db === $key) {
if ($key_db['authkey'] === $key) {
return $key;
}

Expand Down

0 comments on commit 2450207

Please sign in to comment.