Skip to content

Commit 384d0fd

Browse files
authored
Update bot.php
1 parent 38faaa5 commit 384d0fd

File tree

1 file changed

+104
-23
lines changed

1 file changed

+104
-23
lines changed

bot.php

Lines changed: 104 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,13 @@
111111
$userName = $info['name'];
112112

113113
if($match[1] == "Plan"){
114+
$offset = 0;
115+
$limit = 20;
116+
114117
$condition = array_values(array_keys(json_decode($info['discount_percent'],true)['plans']??array()));
115118
$condition = count($condition) > 0? "WHERE `id` NOT IN (" . implode(",", $condition) . ")":"";
116-
$stmt = $connection->prepare("SELECT * FROM `server_plans` $condition");
119+
$stmt = $connection->prepare("SELECT * FROM `server_plans` $condition LIMIT ? OFFSET ?");
120+
$stmt->bind_param("ii", $limit, $offset);
117121
$stmt->execute();
118122
$list = $stmt->get_result();
119123
$stmt->close();
@@ -130,6 +134,9 @@
130134
$keys[] = [['text'=>$row['title'] . " " . $catInfo['title'],'callback_data'=>"editAgentDiscountPlan" . $match[2] . "_" . $row['id']]];
131135
}
132136

137+
if($list->num_rows >= $limit){
138+
$keys[] = [['text'=>"▶️",'callback_data'=>"nextAgentDiscountPlan" . $match[2] . "_" . ($offset + $limit)]];
139+
}
133140
$keys[] = [['text' => $buttonValues['back_button'], 'callback_data' => "agentPercentDetails" . $match[2]]];
134141
$keys = json_encode(['inline_keyboard'=>$keys]);
135142

@@ -156,6 +163,57 @@
156163
}else alert("سروری باقی نمانده است");
157164
}
158165
}
166+
if(preg_match('/^nextAgentDiscountPlan(?<agentId>\d+)_(?<offset>\d+)/',$data,$match)){
167+
$stmt = $connection->prepare("SELECT * FROM `users` WHERE `userid` = ?");
168+
$stmt->bind_param('i',$match['agentId']);
169+
$stmt->execute();
170+
$info = $stmt->get_result()->fetch_assoc();
171+
$stmt->close();
172+
$userName = $info['name'];
173+
174+
$offset = $match['offset'];
175+
$limit = 20;
176+
177+
$condition = array_values(array_keys(json_decode($info['discount_percent'],true)['plans']??array()));
178+
$condition = count($condition) > 0? "WHERE `id` NOT IN (" . implode(",", $condition) . ")":"";
179+
$stmt = $connection->prepare("SELECT * FROM `server_plans` $condition LIMIT ? OFFSET ?");
180+
$stmt->bind_param("ii", $limit, $offset);
181+
$stmt->execute();
182+
$list = $stmt->get_result();
183+
$stmt->close();
184+
185+
if($list->num_rows > 0){
186+
$keys = array();
187+
while($row = $list->fetch_assoc()){
188+
$stmt = $connection->prepare("SELECT * FROM `server_categories` WHERE `id` = ?");
189+
$stmt->bind_param("i", $row['catid']);
190+
$stmt->execute();
191+
$catInfo = $stmt->get_result()->fetch_assoc();
192+
$stmt->close();
193+
194+
$keys[] = [['text'=>$row['title'] . " " . $catInfo['title'],'callback_data'=>"editAgentDiscountPlan" . $match['agentId'] . "_" . $row['id']]];
195+
}
196+
197+
if($list->num_rows >= $limit && $offset == 0){
198+
$keys[] = [['text'=>"▶️",'callback_data'=>"nextAgentDiscountPlan" . $match['agentId'] . "_" . ($offset + $limit)]];
199+
}
200+
elseif($list->num_rows >= $limit && $offset != 0){
201+
$keys[] = [
202+
['text'=>"◀️️",'callback_data'=>"nextAgentDiscountPlan" . $match['agentId'] . "_" . ($offset - $limit)],
203+
['text'=>"▶️",'callback_data'=>"nextAgentDiscountPlan" . $match['agentId'] . "_" . ($offset + $limit)]
204+
];
205+
}
206+
elseif($offset != 0){
207+
$keys[] = [
208+
['text'=>"◀️️",'callback_data'=>"nextAgentDiscountPlan" . $match['agentId'] . "_" . ($offset - $limit)]
209+
];
210+
}
211+
$keys[] = [['text' => $buttonValues['back_button'], 'callback_data' => "agentPercentDetails" . $match['agentId']]];
212+
$keys = json_encode(['inline_keyboard'=>$keys]);
213+
214+
editText($message_id,"لطفا سرور مورد نظر را برای افزودن تخفیف به نماینده $userName انتخاب کنید",$keys);
215+
}else alert("سروری باقی نمانده است");
216+
}
159217
if(preg_match('/^removePercentOfAgent(?<type>Server|Plan)(?<agentId>\d+)_(?<serverId>\d+)/',$data,$match)){
160218
$stmt = $connection->prepare("SELECT * FROM `users` WHERE `userid` = ?");
161219
$stmt->bind_param('i',$match['agentId']);
@@ -329,7 +387,7 @@
329387
$stmt->bind_param("s", $newData);
330388
$stmt->execute();
331389
$stmt->close();
332-
}
390+
}
333391
editText($message_id,$mainValues['change_bot_settings_message'],getBotSettingKeys());
334392
}
335393
if($data=="changeUpdateConfigLinkState" && ($from_id == $admin || $userInfo['isAdmin'] == true)){
@@ -1418,8 +1476,7 @@
14181476
delMessage();
14191477

14201478
$price = $payInfo['price'];
1421-
$rate = json_decode(file_get_contents("https://api.changeto.technology/api/rate"),true)['result'];
1422-
$priceInTrx = round($price / $rate['TRX'],2);
1479+
$priceInTrx = round($price / $botState['TRXRate'],2);
14231480

14241481
$stmt = $connection->prepare("UPDATE `pays` SET `tron_price` = ? WHERE `hash_id` = ?");
14251482
$stmt->bind_param("ds", $priceInTrx, $match[1]);
@@ -1518,9 +1575,8 @@
15181575

15191576

15201577
$price = $payInfo['price'];
1521-
$rate = json_decode(file_get_contents("https://api.changeto.technology/api/rate"),true)['result'];
1522-
$priceInUSD = round($price / $rate['USD'],2);
1523-
$priceInTrx = round($price / $rate['TRX'],2);
1578+
$priceInUSD = round($price / $botState['USDRate'],2);
1579+
$priceInTrx = round($price / $botState['TRXRate'],2);
15241580
$pay = NOWPayments('POST', 'payment', [
15251581
'price_amount' => $priceInUSD,
15261582
'price_currency' => 'usd',
@@ -2693,6 +2749,7 @@
26932749
}
26942750
if($price == 0 or ($from_id == $admin)){
26952751
$keyboard[] = [['text' => '📥 دریافت رایگان', 'callback_data' => "freeTrial$id"]];
2752+
setUser($remark, 'temp');
26962753
}else{
26972754
$token = base64_encode("{$from_id}.{$id}");
26982755

@@ -5429,12 +5486,17 @@
54295486
$portType = $stmt->get_result()->fetch_assoc()['port_type'];
54305487
$stmt->close();
54315488

5432-
if($botState['remark'] == "digits"){
5433-
$rnd = rand(10000,99999);
5434-
$remark = "{$srv_remark}-{$rnd}";
5489+
if($from_id == $admin && !empty($userInfo['temp'])){
5490+
$remark = $userInfo['temp'];
5491+
setUser('','temp');
54355492
}else{
5436-
$rnd = rand(1111,99999);
5437-
$remark = "{$srv_remark}-{$from_id}-{$rnd}";
5493+
if($botState['remark'] == "digits"){
5494+
$rnd = rand(10000,99999);
5495+
$remark = "{$srv_remark}-{$rnd}";
5496+
}else{
5497+
$rnd = rand(1111,99999);
5498+
$remark = "{$srv_remark}-{$from_id}-{$rnd}";
5499+
}
54385500
}
54395501

54405502
if($portType == "auto"){
@@ -5705,23 +5767,42 @@
57055767
$remark = $email;
57065768
}
57075769
else{
5708-
$upload = sumerize($list[$keys]->up);
5709-
$download = sumerize($list[$keys]->down);
5770+
$clientUpload = $clientState[$emailKey]->up;
5771+
$clientDownload = $clientState[$emailKey]->down;
5772+
$clientTotal = $clientState[$emailKey]->total;
5773+
$clientExpTime = $clientState[$emailKey]->expiryTime;
5774+
5775+
$up = $list[$keys]->up;
5776+
$down = $list[$keys]->down;
5777+
$total = $list[$keys]->total;
5778+
$expiry = $list[$keys]->expiryTime;
5779+
5780+
if(($clientTotal != 0 || $clientTotal != null) && ($clientExpTime != 0 || $clientExpTime != null)){
5781+
$up = $clientUpload;
5782+
$down = $clientDownload;
5783+
$total = $clientTotal;
5784+
$expiry = $clientExpTime;
5785+
}
5786+
5787+
$upload = sumerize($up);
5788+
$download = sumerize($down);
57105789
$configLocation = ["uuid" => $text, "remark"=>$list[$keys]->remark];
5711-
$leftMb = $list[$keys]->total!=0?($list[$keys]->total - $list[$keys]->up - $list[$keys]->down):"نامحدود";
5790+
$leftMb = $total!=0?($total - $up - $down):"نامحدود";
57125791
if(is_numeric($leftMb)){
57135792
if($leftMb<0){
57145793
$leftMb = 0;
57155794
}else{
5716-
$leftMb = sumerize($list[$keys]->total - $list[$keys]->up - $list[$keys]->down);
5795+
$leftMb = sumerize($total - $up - $down);
57175796
}
57185797
}
5719-
$totalUsed = sumerize($list[$keys]->up + $list[$keys]->down);
5720-
$total = $list[$keys]->total!=0?sumerize($list[$keys]->total):"نامحدود";
5721-
$expiryTime = $list[$keys]->expiryTime != 0?jdate("Y-m-d H:i:s",substr($list[$keys]->expiryTime,0,-3)):"نامحدود";
5722-
$expiryDay = $list[$keys]->expiryTime != 0?
5798+
$totalUsed = sumerize($up + $down);
5799+
$total = $total!=0?sumerize($total):"نامحدود";
5800+
5801+
5802+
$expiryTime = $expiry != 0?jdate("Y-m-d H:i:s",substr($expiry,0,-3)):"نامحدود";
5803+
$expiryDay = $expiry != 0?
57235804
floor(
5724-
((substr($list[$keys]->expiryTime,0,-3)-time())/(60 * 60 * 24))
5805+
((substr($expiry,0,-3)-time())/(60 * 60 * 24))
57255806
):
57265807
"نامحدود";
57275808
if(is_numeric($expiryDay)){
@@ -9191,12 +9272,12 @@
91919272
break;
91929273
case "Max":
91939274
$txt = "ظرفیت";
9194-
break;
9275+
break;
91959276
case "Remark":
91969277
$txt ="ریمارک";
91979278
break;
91989279
case "Flag":
9199-
$txt = "پرچم";
9280+
$txt = "پرچم";
92009281
break;
92019282
default:
92029283
$txt = str_replace("_", " ", $match[1]);

0 commit comments

Comments
 (0)