Spaces:
Runtime error
Runtime error
File size: 5,054 Bytes
8d21059 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | <?php
class NeleBotX
{
public $configs = [];
public $api = [];
public $v = [];
public $db = [];
public $user = [];
public $group = [];
public $channel = [];
public $response = [
'ok' => 0
];
# Initialization
public function __construct ($configs, $noupdate = false) {
$this->configs = $configs;
if (empty($this->configs)) {
return $this->response = ['ok' => 0, 'error_code' => 500, 'description' => "Internal Server Error: missing configurations"];
}
$this->api = new TelegramBot($this->configs);
if (!$this->api->response['ok']) {
return $this->response = $this->api->response;
}
if (!$noupdate) {
$update = $this->api->getUpdate();
$this->v = new Variables($this->configs, $update);
if (!$this->v->response['ok']) {
return $this->response = $this->v->response;
}
}
$this->db = new Database($this->configs);
if (!$this->db->response['ok']) {
return $this->response = $this->db->response;
}
if (!$noupdate) {
$this->user = $this->loadUser();
$this->group = $this->loadGroup();
$this->channel = $this->loadChannel();
# Stop script for banned chats
if (!$this->v->isAdmin() and ($this->user['ban'] or $this->group['ban'] or $this->channel['ban'])) return $this->response = ['ok' => false, 'error_code' => 429, 'description' => 'Banned from the Bot'];
# AntiFlood System
if ($this->configs['redis']['status'] and $this->configs['redis']['antiflood']['status']) {
if (isset($this->user['id'])) {
$af = new AntiFlood($this->db, $this->user['id']);
if ($af->banned) {
if ($af->send_notice and $this->configs['redis']['antiflood']['notice']) $this->api->sendMessage($this->user['id'], $this->configs['redis']['antiflood']['notice']);
return $this->response = ['ok' => false, 'error_code' => 429, 'description' => 'Banned user ' . $this->user['id']];
}
}
if (isset($this->group['id'])) {
$af = new AntiFlood($this->db, $this->group['id']);
if ($af->banned) {
if ($af->send_notice and $this->configs['redis']['antiflood']['notice']) $this->api->sendMessage($this->group['id'], $this->configs['redis']['antiflood']['notice']);
return $this->response = ['ok' => false, 'error_code' => 429, 'description' => 'Banned group ' . $this->group['id']];
}
} elseif (isset($this->channel['id'])) {
$af = new AntiFlood($this->db, $this->channel['id']);
if ($af->banned) {
if ($af->send_notice and $this->configs['redis']['antiflood']['notice']) $this->api->sendMessage($this->channel['id'], $this->configs['redis']['antiflood']['notice']);
return $this->response = ['ok' => false, 'error_code' => 429, 'description' => 'Banned channel ' . $this->channel['id']];
}
}
}
}
return $this->response = ['ok' => 1];
}
public function loadUser () {
if ($this->configs['database']['status']) return $this->db->getUser($this->v->getUser());
return $this->v->getUser();
}
public function loadGroup () {
if ($this->configs['database']['status']) {
$q = $this->db->getGroup($this->v->getGroup());
if (isset($q['id'])) {
if (!is_array($q['permissions']) or empty($q['permissions']) or $q['last_seen'] <= (time() - 60 * 60)) {
$q['permissions'] = [];
$chat = $this->api->getChat($q['id']);
if ($chat['ok'] and isset($chat['result'])) {
$q['description'] = $chat['result']['description'];
$q['permissions'] = $chat['result']['permissions'];
}
$this->db->query("UPDATE groups SET description = ?, permissions = ?, last_seen = ? WHERE id = ?", [$q['description'], json_encode($q['permissions']), $q['last_seen'], $q['id']]);
}
if (!is_array($q['admins']) or empty($q['admins']) or $q['last_seen'] <= (time() - 60 * 60)) {
$q['admins'] = [];
$admins = $this->api->getAdministrators($q['id']);
if ($admins['ok'] and isset($admins['result'])) {
$q['admins'] = $admins['result'];
}
$q['last_seen'] = time();
$this->db->query("UPDATE groups SET admins = ?, last_seen = ? WHERE id = ?", [json_encode($q['admins']), $q['last_seen'], $q['id']]);
}
}
$this->v->varChatAdministrators($q['admins']);
return $q;
}
return $this->v->getGroup();
}
public function loadChannel() {
if ($this->configs['database']['status']) {
$q = $this->db->getChannel($this->v->getChannel());
if (isset($q['id'])) {
if (empty($q['admins']) or $q['last_seen'] <= (time() - 60 * 60)) {
$q['admins'] = [];
$admins = $this->api->getAdministrators($q['id']);
if ($admins['ok'] and isset($admins['result'])) {
$q['admins'] = $admins['result'];
}
$q['last_seen'] = time();
$this->db->query("UPDATE channels SET admins = ?, last_seen = ? WHERE id = ?", [json_encode($q['admins']), $q['last_seen'], $q['id']]);
}
}
$this->v->varChatAdministrators($q['admins']);
return $q;
}
return $this->v->getChannel();
}
}
?>
|