Skip to content

Commit

Permalink
Updated
Browse files Browse the repository at this point in the history
  • Loading branch information
mahdiMGF2 committed Jun 11, 2024
1 parent 711227b commit 7f62f92
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 30 deletions.
29 changes: 29 additions & 0 deletions cron/sendmessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
ini_set('error_log', 'error_log');
date_default_timezone_set('Asia/Tehran');
require_once '../config.php';
require_once '../botapi.php';
require_once '../functions.php';
if(!is_file('info'))return;
if(!is_file('users.json'))return;


$userid = json_decode(file_get_contents('users.json'));
$info = json_decode(file_get_contents('info'),true);
$count = 0;
if(count($userid) == 0){
if(isset($info['id_admin'])){
sendmessage($info['id_admin'], "📌 پیام برای تمامی کاربران ارسال گردید.", null, 'HTML');
unlink('info');
}
return;

}
foreach ($userid as $iduser){
if($count == 20)break;
sendmessage($iduser->id, $info['text'], null, 'HTML');
unset($userid[0]);
$userid = array_values($userid);
$count +=1;
}
file_put_contents('users.json',json_encode($userid,true));
16 changes: 16 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,13 +327,15 @@ function DirectPayment($order_id){
if ($affiliatescommission['status_commission'] == "oncommission" &&($Balance_id['affiliates'] !== null || $Balance_id['affiliates'] != 0)) {
$result = ($get_invoice['price_product'] * $affiliatescommission['affiliatespercentage']) / 100;
$user_Balance = select("user", "*", "id", $Balance_id['affiliates'],"select");
if(isset($user_Balance)){
$Balance_prim = $user_Balance['Balance'] + $result;
update("user","Balance",$Balance_prim, "id",$Balance_id['affiliates']);
$result = number_format($result);
$textadd = "🎁 پرداخت پورسانت
مبلغ $result تومان به حساب شما از طرف زیر مجموعه تان به کیف پول شما واریز گردید";
sendmessage($Balance_id['affiliates'], $textadd, null, 'HTML');
}
}
$Balance_prims = $Balance_id['Balance'] - $get_invoice['price_product'];
if($Balance_prims <= 0) $Balance_prims = 0;
Expand Down Expand Up @@ -393,3 +395,17 @@ function DirectPayment($order_id){
🛒 کد پیگیری شما: {$Payment_report['id_order']}", null, 'HTML');
}
}
function savedata($type,$namefiled,$valuefiled){
global $from_id;
if($type == "clear"){
$datauser = [];
$datauser[$namefiled] = $valuefiled;
$data = json_encode($datauser);
update("user","Processing_value",$data,"id",$from_id);
}elseif($type == "save"){
$userdata = select("user","*","id",$from_id,"select");
$dataperevieos = json_decode($userdata['Processing_value'],true);
$dataperevieos[$namefiled] = $valuefiled;
update("user","Processing_value",json_encode($dataperevieos),"id",$from_id);
}
}
64 changes: 35 additions & 29 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
ini_set('error_log', 'error_log');
$version = "4.8.5.1";
$version = "4.8.5.2";
date_default_timezone_set('Asia/Tehran');
require_once 'config.php';
require_once 'botapi.php';
Expand Down Expand Up @@ -100,6 +100,14 @@
$datatextbot[$item['id_text']] = $item['text'];
}
}

$existingCronCommands = shell_exec('crontab -l');
$phpFilePath = "https://$domainhosts/cron/sendmessage.php";
$cronCommand = "*/1 * * * * curl $phpFilePath";
if (strpos($existingCronCommands, $cronCommand) === false) {
$command = "(crontab -l ; echo '$cronCommand') | crontab -";
shell_exec($command);
}
#---------channel--------------#
$tch = '';
if (isset ($channels['link']) && $from_id != 0) {
Expand Down Expand Up @@ -2362,36 +2370,34 @@
sendmessage($from_id, $textbotlang['users']['selectoption'], $sendmessageuser, 'HTML');
} elseif ($text == "✉️ ارسال همگانی") {
sendmessage($from_id, $textbotlang['Admin']['ManageUser']['GetText'], $backadmin, 'HTML');
step('gettextforsendall', $from_id);
step('getconfirmsendall', $from_id);
}elseif($user['step'] == "getconfirmsendall"){
savedata("clear","text",$text);
savedata("save","id_admin",$from_id);
sendmessage($from_id,"در صورت تایید متن زیر را ارسال نمایید
تایید", $backadmin, 'HTML');
step("gettextforsendall",$from_id);
} elseif ($user['step'] == "gettextforsendall") {
if (!$text) {
sendmessage($from_id, $textbotlang['Admin']['mesage']['nottextmessage'], $backadmin, 'HTML');
return;
}
sendmessage($from_id, "درحال ارسال پیام", $keyboardadmin, 'HTML');
step('home', $from_id);
$filename = 'user.txt';
$stmt = $pdo->prepare("SELECT id FROM user");
$stmt->execute();
if ($result) {
$ids = array();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$ids[] = $row['id'];
}
$idsText = implode("\n", $ids);
file_put_contents($filename, $idsText);
}
$file = fopen($filename, 'r');
if ($file) {
while (($line = fgets($file)) !== false) {
$line = trim($line);
sendmessage($line, $text, null, 'HTML');
usleep(1000000);
$userdata = json_decode($user['Processing_value'],true);
if($text == "تایید"){
step('home', $from_id);
$result = select("user","id","User_Status","Active","fetchAll");
$Respuseronse = json_encode([
'inline_keyboard' => [
[
['text' => "لغو ارسال", 'callback_data' => 'cancel_sendmessage'],
],
]
]);
file_put_contents('cron/users.json',json_encode($result));
file_put_contents('cron/info',$user['Processing_value']);
sendmessage($from_id, "📌 پیام شما در صف ارسال قرار گرفت پس از ارسال پیام تایید برای شما ارسال می شود ( ارسال پیام ممکن است حداکثر 8 ساعت زمان ببرد بدلیل محدودیت های تلگرام )", $Respuseronse, 'HTML');
}
sendmessage($from_id, "✅ پیام به تمامی کاربران ارسال شد", $keyboardadmin, 'HTML');
fclose($file);
}
unlink($filename);
}elseif($datain == "cancel_sendmessage"){
unlink('cron/users.json');
unlink('cron/info');
deletemessage($from_id, $message_id);
sendmessage($from_id, "📌 ارسال پیام لغو گردید.", null, 'HTML');
} elseif ($text == "📤 فوروارد همگانی") {
sendmessage($from_id, $textbotlang['Admin']['ManageUser']['ForwardGetext'], $backadmin, 'HTML');
step('gettextforwardMessage', $from_id);
Expand Down
3 changes: 2 additions & 1 deletion table.php
Original file line number Diff line number Diff line change
Expand Up @@ -784,4 +784,5 @@
}
} catch (Exception $e) {
file_put_contents('error_log',$e->getMessage());
}
}
$connect->query("ALTER TABLE `user` CHANGE `Processing_value` `Processing_value` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL;");

0 comments on commit 7f62f92

Please sign in to comment.