-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbot.php
154 lines (99 loc) · 3.29 KB
/
bot.php
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
include 'http.php';
$content = file_get_contents("php://input");
$update = json_decode($content, true);
$api = "botTOKEN";
$chat = $update[message][chat];
$chatID = $chat[id];
$user = $update[message][from];
$username = $user[username];
$msg = $update[message][text];
$id = $update[message][reply_to_message][forward_from][id];
#---------------FUNCTION----------------
function sm($chat, $text, $pm = 'HTML')
{
global $api;
$a = array(
'chat_id' => $chat,
'text' => $text,
'parse_mode' => $pm
);
$r = new http("post", "https://api.telegram.org/$api/sendmessage", $a);
$rr = $r->getResponse();
$ar = json_decode($rr, true);
if ($ar[error_code] == "403")
{
return false;
}
else
{
return true;
}
}
#---------------Db setup-------------
$tab = 'title';
mysql_select_db("my_userapi"); //Name of Db
#----------------General Setup---------
$admin = -1001085160093; //Admin ID---- If Admin > 1 => Create a group with all the admins and type the chat id
if ($chatID == $admin or $user[id] == $admin)
$isadmin = true;
#-----------------------------UPDATE/START DB POINT-----------------------------------
if ($update and $chatID > 0)
{
$a = mysql_fetch_assoc(mysql_query("select * from $tab where chat_id = '$chatID'"));
if (!$a)
{
mysql_query("insert into $tab (chat_id, username, ban) values ('$chatID', '$username', '0')");
}
else
{
mysql_query("update $tab set username='$username' where chat_id='$chatID'");
if ($a[ban])
exit;
}
}
#-----------------Start Point-------------------------
if ($msg == "/start" and $chatID > 0)
{
$text = "Welcome! I am a bot for limited people! Type a message, my admins will reply you soon";
if ($isadmin)
$text = "Welcome! This is your bot! To reply: reply to forwarded message";
sm($chatID, $text);
}
#---------------Manage Point------------------------
if (strpos(' ' . $msg, "ban") and $isadmin)
{
if ($msg == "/ban")
$x = 1;
if ($msg == "/sban")
$t = 's';
sm($chatID, "$id $t" . "banned!");
sm($id, "You have been $t" . "banned from the bot!");
mysql_query("update $tab set ban='$x' where chat_id='$id'");
}
#---------------Forward message to admins----------
if (!$isadmin and $chatID > 0)
{
$args = array(
'chat_id' => $admin,
'from_chat_id' => $chatID,
'message_id' => $update[message][message_id]
);
$r = new http("post", "https://api.telegram.org/$api/forwardMessage", $args);
}
#------------------------Reply to a message----------------
if ($msg and $isadmin and $id)
{
$type = "Staff";
if ($chatID > 0)
$type = "Admin";
$a = sm($id, "<b>$type:</b> \n" . ucfirst($msg));
if (!$a)
sm($chatID, "$id disabled the bot");
mysql_query("DELETE FROM $tab WHERE chat_id = $id");
}
elseif (!$id and $msg and $chatID > 0 and $isadmin)
{
sm($chatID, "To reply, reply to a forwarded message");
}
?>