Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
234 lines (185 loc) Β· 6.95 KB
/
Copy pathmain.py
File metadata and controls
234 lines (185 loc) Β· 6.95 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
import logging
import requests
import json
from telegram import Update, ReplyKeyboardMarkup, ReplyKeyboardRemove
from telegram.ext import (
Application,
CommandHandler,
MessageHandler,
filters,
ContextTypes,
ConversationHandler
)
from telegram.helpers import escape_markdown
# Logging
logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=logging.INFO
)
logger = logging.getLogger(__name__)
# === CONFIG ===
API_BASE = "https://numapi.anshapi.workers.dev?num="
BOT_TOKEN = "BOT_TOKEN"
ENTER_NUMBER = 1
HEADERS = {
"User-Agent": "Mozilla/5.0",
"Accept": "application/json,*/*;q=0.8",
"Referer": "https://anish-axploits.vercel.app/"
}
FIELD_NAME_MAP = {
'number': 'π± Mobile Number',
'mobile': 'π± Mobile Number',
'name': 'π€ Full Name',
'fathername': 'π¨β𦳠Father Name',
'fname': 'π¨β𦳠Father Name',
'father_name': 'π¨β𦳠Father Name',
'address': 'π Address',
'altmobile': 'π Alternate Mobile',
'alt_mobile': 'π Alternate Mobile',
'circle': 'π Circle',
'operator': 'π’ Operator',
'state': 'πΊοΈ State',
'sim': 'π² SIM Type',
'idnumber': 'π ID Number',
'id_number': 'π ID Number'
}
def get_display_name(field_name):
f = field_name.lower()
return FIELD_NAME_MAP.get(f, field_name.replace("_", " ").title())
def normalize_response(data):
if isinstance(data, dict) and "data" in data and data["data"]:
if isinstance(data["data"], list):
return data["data"]
return [data["data"]]
if isinstance(data, list):
return data
if isinstance(data, dict):
for k, v in data.items():
if isinstance(v, list) and v:
return v
if isinstance(v, dict):
return [v]
return []
def format_address(addr):
if not addr:
return addr
return " ".join(addr.split())
# === START ===
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
keyboard = [["π Search Number"]]
await update.message.reply_text(
"π€ Welcome To Sharlix M7 Project",
reply_markup=ReplyKeyboardMarkup(keyboard, resize_keyboard=True)
)
# === ENTER NUMBER ===
async def enter_number(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text(
"π Send 10 digit mobile number:",
reply_markup=ReplyKeyboardRemove()
)
return ENTER_NUMBER
# === SEARCH ===
async def search_number(update: Update, context: ContextTypes.DEFAULT_TYPE):
number = update.message.text.strip()
if not number.isdigit() or len(number) != 10:
await update.message.reply_text("β Invalid number! Send 10 digits.\n/start")
return ConversationHandler.END
loading_msg = await update.message.reply_text("π Searching database...")
try:
url = f"{API_BASE}{number}"
response = requests.get(url, headers=HEADERS, timeout=20)
raw = response.text.strip()
try:
data = json.loads(raw)
except:
s = raw.find("{")
e = raw.rfind("}")
if s != -1 and e != -1:
try:
data = json.loads(raw[s:e+1])
except:
await safe_delete(loading_msg)
await update.message.reply_text("β No information found.\n/start")
return ConversationHandler.END
else:
await safe_delete(loading_msg)
await update.message.reply_text("β No information found.\n/start")
return ConversationHandler.END
records = normalize_response(data)
if not records:
await safe_delete(loading_msg)
await update.message.reply_text("β No information found.\n/start")
return ConversationHandler.END
await safe_delete(loading_msg)
result = f"β
*Information Found*\n\n"
result += f"π’ *Target Number:* `{escape_markdown(number, version=2)}`\n"
result += "ββββββββββββββββββββββ\n\n"
for idx, user in enumerate(records, 1):
if isinstance(user, dict):
result += f"*π Record {idx}:*\n"
priority = [
'name','fathername','father_name','fname','mobile','number',
'idnumber','id_number','address','altmobile','alt_mobile',
'circle','operator','state','sim'
]
added = set()
for field in priority:
if field in user and user[field]:
val = user[field]
if field == "address":
val = format_address(val)
display = get_display_name(field)
val = escape_markdown(str(val), version=2)
result += f"β’ *{display}:* `{val}`\n"
added.add(field)
for key, val in user.items():
if key not in added and val:
if key == "address":
val = format_address(val)
display = get_display_name(key)
val = escape_markdown(str(val), version=2)
result += f"β’ *{display}:* `{val}`\n"
result += "\nββββββββββββββββββββ\n\n"
credit = "π» *Created By Sharlix*\nπ± Join: https://t.me/starmaker_in"
result += escape_markdown(credit, version=2)
await update.message.reply_text(result, parse_mode="MarkdownV2")
keyboard = [["π Search Number"]]
await update.message.reply_text(
"Search another number:",
reply_markup=ReplyKeyboardMarkup(keyboard, resize_keyboard=True)
)
return ConversationHandler.END
except:
await safe_delete(loading_msg)
await update.message.reply_text("β Error occurred.\n/start")
return ConversationHandler.END
async def safe_delete(msg):
try:
await msg.delete()
except:
pass
async def cancel(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text(
"Cancelled.\n/start",
reply_markup=ReplyKeyboardRemove()
)
return ConversationHandler.END
def main():
app = Application.builder().token(BOT_TOKEN).build()
conv = ConversationHandler(
entry_points=[
MessageHandler(filters.Regex("^π Search Number$"), enter_number),
CommandHandler("start", start)
],
states={
ENTER_NUMBER: [
MessageHandler(filters.TEXT & ~filters.COMMAND, search_number)
]
},
fallbacks=[CommandHandler("cancel", cancel)]
)
app.add_handler(conv)
print("π€ Bot Running...")
app.run_polling()
if __name__ == "__main__":
main()