-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy path_init__.txt
511 lines (422 loc) · 17.2 KB
/
_init__.txt
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
# Copyright (C) 2019 The Raphielscape Company LLC.
#
# Licensed under the Raphielscape Public License, Version 1.d (the "License");
# you may not use this file except in compliance with the License.
# inline credit @keselekpermen69
""" Userbot initialization. """
import os
import time
import re
from sys import version_info
from logging import basicConfig, getLogger, INFO, DEBUG
from distutils.util import strtobool as sb
from math import ceil
from pylast import LastFMNetwork, md5
from pySmartDL import SmartDL
from pymongo import MongoClient
from redis import StrictRedis
from dotenv import load_dotenv
from requests import get
from telethon.sync import TelegramClient, custom, events
from telethon.sessions import StringSession
load_dotenv("config.env")
StartTime = time.time()
CMD_LIST = {}
# for later purposes
CMD_HELP = {}
INT_PLUG = ""
LOAD_PLUG = {}
# Bot Logs setup:
CONSOLE_LOGGER_VERBOSE = sb(os.environ.get("CONSOLE_LOGGER_VERBOSE", "False"))
if CONSOLE_LOGGER_VERBOSE:
basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=DEBUG,
)
else:
basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
level=INFO)
LOGS = getLogger(__name__)
if version_info[0] < 3 or version_info[1] < 8:
LOGS.info("You MUST have a python version of at least 3.8."
"Multiple features depend on this. Bot quitting.")
quit(1)
# Check if the config was edited by using the already used variable.
# Basically, its the 'virginity check' for the config file ;)
CONFIG_CHECK = os.environ.get(
"___________PLOX_______REMOVE_____THIS_____LINE__________", None)
if CONFIG_CHECK:
LOGS.info(
"Please remove the line mentioned in the first hashtag from the config.env file"
)
quit(1)
# Telegram App KEY and HASH
API_KEY = os.environ.get("API_KEY", "")
API_HASH = os.environ.get("API_HASH", "")
# Userbot Session String
STRING_SESSION = os.environ.get("STRING_SESSION", "")
# Logging channel/group ID configuration.
BOTLOG_CHATID = int(os.environ.get("BOTLOG_CHATID", ""))
# Userbot logging feature switch.
BOTLOG = sb(os.environ.get("BOTLOG", "True"))
LOGSPAMMER = sb(os.environ.get("LOGSPAMMER", "False"))
# Bleep Blop, this is a bot ;)
PM_AUTO_BAN = sb(os.environ.get("PM_AUTO_BAN", "False"))
# Send .chatid in any group with all your administration bots (added)
G_BAN_LOGGER_GROUP = os.environ.get("G_BAN_LOGGER_GROUP", "")
if G_BAN_LOGGER_GROUP:
G_BAN_LOGGER_GROUP = int(G_BAN_LOGGER_GROUP)
# Heroku Credentials for updater.
HEROKU_MEMEZ = sb(os.environ.get("HEROKU_MEMEZ", "False"))
HEROKU_APP_NAME = os.environ.get("HEROKU_APP_NAME", "")
HEROKU_API_KEY = os.environ.get("HEROKU_API_KEY", "")
# JustWatch Country
WATCH_COUNTRY = os.environ.get("WATCH_COUNTRY", "ID")
# Github Credentials for updater and Gitupload.
GIT_REPO_NAME = os.environ.get("GIT_REPO_NAME", None)
GITHUB_ACCESS_TOKEN = os.environ.get("GITHUB_ACCESS_TOKEN", None)
# Custom (forked) repo URL for updater.
UPSTREAM_REPO_URL = os.environ.get(
"UPSTREAM_REPO_URL",
"https://github.com/meareyou/lel_remake_UserBoto.git")
UPSTREAM_REPO_BRANCH = os.environ.get(
"UPSTREAM_REPO_BRANCH", "x-sql-extended")
# Console verbose logging
CONSOLE_LOGGER_VERBOSE = sb(os.environ.get("CONSOLE_LOGGER_VERBOSE", "False"))
# SQL Database URI
DB_URI = os.environ.get("DATABASE_URL", None)
# OCR API key
OCR_SPACE_API_KEY = os.environ.get("OCR_SPACE_API_KEY", None)
# remove.bg API key
REM_BG_API_KEY = os.environ.get("REM_BG_API_KEY", None)
# Chrome Driver and Headless Google Chrome Binaries
CHROME_DRIVER = os.environ.get("CHROME_DRIVER") or "/usr/bin/chromedriver"
GOOGLE_CHROME_BIN = os.environ.get(
"GOOGLE_CHROME_BIN") or "/usr/bin/google-chrome"
# set to True if you want to log PMs to your PM_LOGGR_BOT_API_ID
NC_LOG_P_M_S = bool(os.environ.get("NC_LOG_P_M_S", False))
# send .get_id in any channel to forward all your NEW PMs to this group
PM_LOGGR_BOT_API_ID = int(os.environ.get("PM_LOGGR_BOT_API_ID", "-100"))
# OpenWeatherMap API Key
OPEN_WEATHER_MAP_APPID = os.environ.get("OPEN_WEATHER_MAP_APPID", None)
WEATHER_DEFCITY = os.environ.get("WEATHER_DEFCITY", None)
# Lydia API
LYDIA_API_KEY = os.environ.get("LYDIA_API_KEY", None)
# For MONGO based DataBase
MONGO_URI = os.environ.get("MONGO_URI", None)
# set blacklist_chats where you do not want userbot's features
UB_BLACK_LIST_CHAT = os.environ.get("UB_BLACK_LIST_CHAT", None)
# Anti Spambot Config
ANTI_SPAMBOT = sb(os.environ.get("ANTI_SPAMBOT", "False"))
ANTI_SPAMBOT_SHOUT = sb(os.environ.get("ANTI_SPAMBOT_SHOUT", "False"))
# Youtube API key
YOUTUBE_API_KEY = os.environ.get("YOUTUBE_API_KEY", None)
# Default .alive name
ALIVE_NAME = os.environ.get("ALIVE_NAME", None)
# Time & Date - Country and Time Zone
COUNTRY = str(os.environ.get("COUNTRY", "ID"))
TZ_NUMBER = int(os.environ.get("TZ_NUMBER", 1))
# Clean Welcome
CLEAN_WELCOME = sb(os.environ.get("CLEAN_WELCOME", "True"))
# Zipfile module
ZIP_DOWNLOAD_DIRECTORY = os.environ.get("ZIP_DOWNLOAD_DIRECTORY", "./zips")
# bit.ly module
BITLY_TOKEN = os.environ.get("BITLY_TOKEN", None)
# Bot Name
TERM_ALIAS = os.environ.get("TERM_ALIAS", "NONE ---")
# Bot version
BOT_VER = os.environ.get("BOT_VER", "4.0")
# Default .alive username
ALIVE_USERNAME = os.environ.get("ALIVE_USERNAME", None)
# Sticker Custom Pack Name
S_PACK_NAME = os.environ.get("S_PACK_NAME", None)
# Default .alive logo
ALIVE_LOGO = os.environ.get(
"ALIVE_LOGO") or "https://telegra.ph/file/279989e0b2152fc118bf4.mp4"
# Last.fm Module
BIO_PREFIX = os.environ.get("BIO_PREFIX", None)
DEFAULT_BIO = os.environ.get("DEFAULT_BIO", None)
LASTFM_API = os.environ.get("LASTFM_API", None)
LASTFM_SECRET = os.environ.get("LASTFM_SECRET", None)
LASTFM_USERNAME = os.environ.get("LASTFM_USERNAME", None)
LASTFM_PASSWORD_PLAIN = os.environ.get("LASTFM_PASSWORD", None)
LASTFM_PASS = md5(LASTFM_PASSWORD_PLAIN)
if LASTFM_API and LASTFM_SECRET and LASTFM_USERNAME and LASTFM_PASS:
lastfm = LastFMNetwork(api_key=LASTFM_API,
api_secret=LASTFM_SECRET,
username=LASTFM_USERNAME,
password_hash=LASTFM_PASS)
else:
lastfm = None
# Google Drive Module
G_DRIVE_DATA = os.environ.get("G_DRIVE_DATA", None)
G_DRIVE_CLIENT_ID = os.environ.get("G_DRIVE_CLIENT_ID", None)
G_DRIVE_CLIENT_SECRET = os.environ.get("G_DRIVE_CLIENT_SECRET", None)
G_DRIVE_AUTH_TOKEN_DATA = os.environ.get("G_DRIVE_AUTH_TOKEN_DATA", None)
G_DRIVE_FOLDER_ID = os.environ.get("G_DRIVE_FOLDER_ID", None)
TEMP_DOWNLOAD_DIRECTORY = os.environ.get("TMP_DOWNLOAD_DIRECTORY",
"./downloads")
# Google Photos
G_PHOTOS_CLIENT_ID = os.environ.get("G_PHOTOS_CLIENT_ID", None)
G_PHOTOS_CLIENT_SECRET = os.environ.get("G_PHOTOS_CLIENT_SECRET", None)
G_PHOTOS_AUTH_TOKEN_ID = os.environ.get("G_PHOTOS_AUTH_TOKEN_ID", None)
if G_PHOTOS_AUTH_TOKEN_ID:
G_PHOTOS_AUTH_TOKEN_ID = int(G_PHOTOS_AUTH_TOKEN_ID)
# Genius lyrics API
GENIUS = os.environ.get("GENIUS_ACCESS_TOKEN", None)
# Quotes API Token
QUOTES_API_TOKEN = os.environ.get("QUOTES_API_TOKEN", None)
# Deezloader
DEEZER_ARL_TOKEN = os.environ.get("DEEZER_ARL_TOKEN", None)
# Photo Chat - Get this value from http://antiddos.systems
API_TOKEN = os.environ.get("API_TOKEN", None)
API_URL = os.environ.get("API_URL", "http://antiddos.systems")
# Inline bot helper
BOT_TOKEN = os.environ.get("BOT_TOKEN") or None
BOT_USERNAME = os.environ.get("BOT_USERNAME") or None
# Init Mongo
MONGOCLIENT = MongoClient(MONGO_URI, 27017, serverSelectionTimeoutMS=1)
MONGO = MONGOCLIENT.userbot
def is_mongo_alive():
try:
MONGOCLIENT.server_info()
except BaseException:
return False
return True
# Init Redis
# Redis will be hosted inside the docker container that hosts the bot
# We need redis for just caching, so we just leave it to non-persistent
REDIS = StrictRedis(host='localhost', port=6379, db=0)
def is_redis_alive():
try:
REDIS.ping()
return True
except BaseException:
return False
# Setting Up CloudMail.ru and MEGA.nz extractor binaries,
# and giving them correct perms to work properly.
if not os.path.exists('bin'):
os.mkdir('bin')
binaries = {
"https://raw.githubusercontent.com/adekmaulana/megadown/master/megadown":
"bin/megadown",
"https://raw.githubusercontent.com/yshalsager/cmrudl.py/master/cmrudl.py":
"bin/cmrudl"
}
for binary, path in binaries.items():
downloader = SmartDL(binary, path, progress_bar=False)
downloader.start()
os.chmod(path, 0o755)
# 'bot' variable
if STRING_SESSION:
# pylint: disable=invalid-name
bot = TelegramClient(StringSession(STRING_SESSION), API_KEY, API_HASH)
else:
# pylint: disable=invalid-name
bot = TelegramClient("userbot", API_KEY, API_HASH)
async def check_botlog_chatid():
if not BOTLOG_CHATID and LOGSPAMMER:
LOGS.info(
"You must set up the BOTLOG_CHATID variable in the config.env or environment variables, for the private error log storage to work."
)
quit(1)
elif not BOTLOG_CHATID and BOTLOG:
LOGS.info(
"You must set up the BOTLOG_CHATID variable in the config.env or environment variables, for the userbot logging feature to work."
)
quit(1)
elif not BOTLOG or not LOGSPAMMER:
return
entity = await bot.get_entity(BOTLOG_CHATID)
if entity.default_banned_rights.send_messages:
LOGS.info(
"Your account doesn't have rights to send messages to BOTLOG_CHATID "
"group. Check if you typed the Chat ID correctly.")
quit(1)
with bot:
try:
bot.loop.run_until_complete(check_botlog_chatid())
except BaseException:
LOGS.info(
"BOTLOG_CHATID environment variable isn't a "
"valid entity. Check your environment variables/config.env file.")
quit(1)
async def check_alive():
await bot.send_message(BOTLOG_CHATID, "```@Crypto08\nBOT AKTIF TOD\nSELAMAT BERKENTOD```")
return
with bot:
try:
bot.loop.run_until_complete(check_alive())
except BaseException:
LOGS.info(
"BOTLOG_CHATID environment variable isn't a "
"valid entity. Check your environment variables/config.env file.")
quit(1)
# Global Variables
COUNT_MSG = 0
USERS = {}
COUNT_PM = {}
ENABLE_KILLME = True
LASTMSG = {}
CMD_HELP = {}
ISAFK = False
AFKREASON = None
ZALG_LIST = {}
def paginate_help(page_number, loaded_modules, prefix):
number_of_rows = 5
number_of_cols = 4
helpable_modules = [p for p in loaded_modules if not p.startswith("_")]
helpable_modules = sorted(helpable_modules)
modules = [
custom.Button.inline("{} {}".format("⚙️", x), data="ub_modul_{}".format(x))
for x in helpable_modules
]
pairs = list(zip(modules[::number_of_cols],
modules[1::number_of_cols],
modules[2::number_of_cols]))
if len(modules) % number_of_cols == 1:
pairs.append((modules[-1],))
max_num_pages = ceil(len(pairs) / number_of_rows)
modulo_page = page_number % max_num_pages
if len(pairs) > number_of_rows:
pairs = pairs[
modulo_page * number_of_rows: number_of_rows * (modulo_page + 1)
] + [
(
custom.Button.inline(
"⌫️", data="{}_prev({})".format(prefix, modulo_page)
),
custom.Button.inline(
"⌦️", data="{}_next({})".format(prefix, modulo_page)
)
)
]
return pairs
with bot:
try:
tgbot = TelegramClient(
"TG_BOT_TOKEN",
api_id=API_KEY,
api_hash=API_HASH).start(
bot_token=BOT_TOKEN)
dugmeler = CMD_HELP
me = bot.get_me()
uid = me.id
@tgbot.on(events.NewMessage(pattern="/start"))
async def handler(event):
if event.message.from_id != uid:
await event.reply("I'm [NONE ---](https://github.com/meareyou/lel_remake_UserBoto) modules helper...\nplease make your own bot, don't use mine 😋")
else:
await event.reply(f"`Hey there {ALIVE_NAME}\n\nI work for you :)`")
@tgbot.on(events.InlineQuery) # pylint:disable=E0602
async def inline_handler(event):
builder = event.builder
result = None
query = event.text
if event.query.user_id == uid and query.startswith("@UserButt"):
buttons = paginate_help(0, dugmeler, "helpme")
result = builder.article(
"Please Use Only With .help Command",
text="{}\nTotal loaded Modules: {}\n \n🖥 **Main Menu** 🖥\n".format(
"UserBoto ⟵(o_O) modules helper",
len(dugmeler),
),
buttons=buttons,
link_preview=False,
)
elif query.startswith("tb_btn"):
result = builder.article(
"UserBoto ⟵(o_O) Helper",
text="List of Modules",
buttons=[],
link_preview=True)
else:
result = builder.article(
"NONE ---",
text="""You can convert your account to bot and use them. Remember, you can't manage someone else's bot! All installation details are explained from GitHub address below.""",
buttons=[
[
custom.Button.url(
"GitHub Repo",
"https://github.com/meareyou/lel_remake_UserBoto"),
custom.Button.url(
"Support",
"www.pornhub.com")],
],
link_preview=False,
)
await event.answer([result] if result else None)
@tgbot.on(
events.callbackquery.CallbackQuery( # pylint:disable=E0602
data=re.compile(rb"helpme_next\((.+?)\)")
)
)
async def on_plug_in_callback_query_handler(event):
if event.query.user_id == uid: # pylint:disable=E0602
current_page_number = int(
event.data_match.group(1).decode("UTF-8"))
buttons = paginate_help(
current_page_number + 1, dugmeler, "helpme")
# https://t.me/TelethonChat/115200
await event.edit(buttons=buttons)
else:
reply_pop_up_alert = "Please make for yourself, don't use my bot!"
await event.answer(reply_pop_up_alert, cache_time=0, alert=True)
@tgbot.on(
events.callbackquery.CallbackQuery( # pylint:disable=E0602
data=re.compile(rb"helpme_prev\((.+?)\)")
)
)
async def on_plug_in_callback_query_handler(event):
if event.query.user_id == uid: # pylint:disable=E0602
current_page_number = int(
event.data_match.group(1).decode("UTF-8"))
buttons = paginate_help(
current_page_number - 1, dugmeler, "helpme" # pylint:disable=E0602
)
# https://t.me/TelethonChat/115200
await event.edit(buttons=buttons)
else:
reply_pop_up_alert = "Please make for yourself, don't use my bot!"
await event.answer(reply_pop_up_alert, cache_time=0, alert=True)
@tgbot.on(
events.callbackquery.CallbackQuery( # pylint:disable=E0602
data=re.compile(b"ub_modul_(.*)")
)
)
async def on_plug_in_callback_query_handler(event):
if event.query.user_id == uid: # pylint:disable=E0602
modul_name = event.data_match.group(1).decode("UTF-8")
cmdhel = str(CMD_HELP[modul_name])
if len(cmdhel) > 150:
help_string = (
str(CMD_HELP[modul_name]).replace('`', '')[:150] + "..."
+ "\n\nRead more .help "
+ modul_name
+ " "
)
else:
help_string = str(CMD_HELP[modul_name]).replace('`', '')
reply_pop_up_alert = (
help_string
if help_string is not None
else "{} No document has been written for module.".format(
modul_name
)
)
else:
reply_pop_up_alert = "Please make for yourself, don't use my bot!"
await event.answer(reply_pop_up_alert, cache_time=0, alert=True)
except BaseException:
LOGS.info(
"Support for inline is disabled on your bot. "
"To enable it, define a bot token and enable inline mode on your bot. "
"If you think there is a problem other than this, contact us.")
try:
bot.loop.run_until_complete(check_botlog_chatid())
except BaseException:
LOGS.info(
"BOTLOG_CHATID environment variable isn't a "
"valid entity. Check your environment variables/config.env file."
)
quit(1)