added init
This commit is contained in:
parent
686dd0b191
commit
fc70cc988b
|
@ -123,3 +123,5 @@ dmypy.json
|
|||
|
||||
# Pyre type checker
|
||||
.pyre/
|
||||
*.session
|
||||
spam/config.py
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
import logging
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
|
||||
from pyrogram import Client, errors
|
||||
|
||||
from spam.config import Config
|
||||
|
||||
StartTime = time.time()
|
||||
log = logging.getLogger()
|
||||
|
||||
ENABLE = Config.ENABLE
|
||||
|
||||
# if version < 3.6, stop bot.
|
||||
if sys.version_info[0] < 3 or sys.version_info[1] < 6:
|
||||
logging.error("You MUST have a python version of at least 3.6! Multiple features depend on this. Bot quitting.")
|
||||
quit(1)
|
||||
|
||||
|
||||
if ENABLE:
|
||||
logger = Config.LOGGER
|
||||
|
||||
# Must be filled
|
||||
if Config.user1_api_id and Config.user1_api_hash:
|
||||
user1_api_id = Config.user1_api_id
|
||||
user1_api_hash = Config.user1_api_hash
|
||||
|
||||
# if Config.user2_api_id and Config.user2_api_hash:
|
||||
# user2_api_id = Config.user2_api_id
|
||||
# user2_api_hash = Config.user2_api_hash
|
||||
|
||||
# if Config.user3_api_id and Config.user3_api_hash:
|
||||
# user3_api_id = Config.user3_api_id
|
||||
# user3_api_hash = Config.user3_api_hash
|
||||
|
||||
# if Config.user4_api_id and Config.user4_api_hash:
|
||||
# user4_api_id = Config.user4_api_id
|
||||
# user4_api_hash = Config.user4_api_hash
|
||||
|
||||
# if Config.user5_api_id and Config.user5_api_hash:
|
||||
# user5_api_id = Config.user5_api_id
|
||||
# user5_api_hash = Config.user5_api_hash
|
||||
|
||||
# if Config.user6_api_id and Config.user6_api_hash:
|
||||
# user6_api_id = Config.user6_api_id
|
||||
# user6_api_hash = Config.user6_api_hash
|
||||
|
||||
# if Config.user7_api_id and Config.user7_api_hash:
|
||||
# user7_api_id = Config.user7_api_id
|
||||
# user7_api_hash = Config.user7_api_hash
|
||||
|
||||
# if Config.user8_api_id and Config.user3_api_hash:
|
||||
# user8_api_id = Config.user8_api_id
|
||||
# user8_api_hash = Config.user8_api_hash
|
||||
|
||||
Command = Config.Command
|
||||
else:
|
||||
print('Enable me first in config.py')
|
||||
|
||||
if user1_api_id and user1_api_hash:
|
||||
user1 = Client("user1", api_id=user1_api_id, api_hash=user1_api_hash)
|
||||
|
||||
# if user2_api_id and user2_api_hash:
|
||||
# user2 = Client("user2", api_id=user2_api_id, api_hash=user2_api_hash)
|
||||
|
||||
# if user2_api_id and user3_api_hash:
|
||||
# user3 = Client("user3", api_id=user3_api_id, api_hash=user3_api_hash)
|
||||
|
||||
# if user4_api_id and user4_api_hash:
|
||||
# user4 = Client("user4", api_id=user4_api_id, api_hash=user4_api_hash)
|
||||
|
||||
# if user5_api_id and user5_api_hash:
|
||||
# user5 = Client("user5", api_id=user5_api_id, api_hash=user5_api_hash)
|
||||
|
||||
# if user6_api_id and user6_api_hash:
|
||||
# user6 = Client("user6", api_id=user6_api_id, api_hash=user6_api_hash)
|
||||
|
||||
# if user7_api_id and user7_api_hash:
|
||||
# user7 = Client("user7", api_id=user7_api_id, api_hash=user7_api_hash)
|
||||
|
||||
# if user8_api_id and user8_api_hash:
|
||||
# user8 = Client("user8", api_id=user8_api_id, api_hash=user8_api_hash)
|
|
@ -0,0 +1,76 @@
|
|||
import asyncio
|
||||
import importlib
|
||||
import sys
|
||||
import time
|
||||
import traceback
|
||||
|
||||
from spam import user1
|
||||
# user2, user3, user4, user5, user6, user7, user8
|
||||
from spam.modules import ALL_MODULES
|
||||
|
||||
BOT_RUNTIME = 0
|
||||
HELP_COMMANDS = {}
|
||||
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
|
||||
async def get_runtime():
|
||||
return BOT_RUNTIME
|
||||
|
||||
async def reload_userbot():
|
||||
await user1.start()
|
||||
# await user2.start()
|
||||
# await user3.start()
|
||||
# await user4.start()
|
||||
# await user5.start()
|
||||
# await user6.start()
|
||||
# await user7.start()
|
||||
# await user8.start()
|
||||
for modul in ALL_MODULES:
|
||||
imported_module = importlib.import_module("spam.modules." + modul)
|
||||
importlib.reload(imported_module)
|
||||
|
||||
async def reinitial():
|
||||
await user1.start()
|
||||
# await user2.start()
|
||||
# await user3.start()
|
||||
# await user4.start()
|
||||
# await user5.start()
|
||||
# await user6.start()
|
||||
# await user7.start()
|
||||
# await user8.start()
|
||||
|
||||
|
||||
async def start_bot():
|
||||
# sys.excepthook = except_hook
|
||||
print("----- Checking user and bot... -----")
|
||||
await reinitial()
|
||||
print("----------- Check done! ------------")
|
||||
# userbot
|
||||
# await user2.start()
|
||||
# await user3.start()
|
||||
# await user4.start()
|
||||
# await user5.start()
|
||||
# await user6.start()
|
||||
# await user7.start()
|
||||
# await user8.start()
|
||||
for modul in ALL_MODULES:
|
||||
imported_module = importlib.import_module("spam.modules." + modul)
|
||||
if hasattr(imported_module, "__MODULE__") and imported_module.__MODULE__:
|
||||
imported_module.__MODULE__ = imported_module.__MODULE__
|
||||
if hasattr(imported_module, "__MODULE__") and imported_module.__MODULE__:
|
||||
if not imported_module.__MODULE__.lower() in HELP_COMMANDS:
|
||||
HELP_COMMANDS[imported_module.__MODULE__.lower()] = imported_module
|
||||
else:
|
||||
raise Exception("Can't have two modules with the same name! Please change one")
|
||||
if hasattr(imported_module, "__HELP__") and imported_module.__HELP__:
|
||||
HELP_COMMANDS[imported_module.__MODULE__.lower()] = imported_module
|
||||
print("-----------------------")
|
||||
print("SpamProtection modules: " + str(ALL_MODULES))
|
||||
print("-----------------------")
|
||||
print("Bot run successfully!")
|
||||
await user1.idle()
|
||||
|
||||
if __name__ == '__main__':
|
||||
BOT_RUNTIME = int(time.time())
|
||||
loop.run_until_complete(start_bot())
|
|
@ -0,0 +1,17 @@
|
|||
from spam import log
|
||||
|
||||
|
||||
def __list_all_modules():
|
||||
from os.path import dirname, basename, isfile
|
||||
import glob
|
||||
# This generates a list of modules in this folder for the * in __main__ to work.
|
||||
mod_paths = glob.glob(dirname(__file__) + "/*.py")
|
||||
all_modules = [basename(f)[:-3] for f in mod_paths if isfile(f)
|
||||
and f.endswith(".py")
|
||||
and not f.endswith('__init__.py')]
|
||||
return all_modules
|
||||
|
||||
|
||||
ALL_MODULES = sorted(__list_all_modules())
|
||||
log.info("Userbot module loaded: %s", str(ALL_MODULES))
|
||||
__all__ = ALL_MODULES + ["ALL_MODULES"]
|
|
@ -0,0 +1,132 @@
|
|||
from datetime import datetime
|
||||
from asyncio import sleep
|
||||
|
||||
from pyrogram import Filters, User
|
||||
from pyrogram.api import functions
|
||||
from pyrogram.errors import PeerIdInvalid
|
||||
|
||||
from spam import user1, Command
|
||||
|
||||
__MODULE__ = "Whois"
|
||||
__HELP__ = """
|
||||
──「 **Whois** 」──
|
||||
-> `whois` @username
|
||||
-> `whois` "reply to a text"
|
||||
To find information about a person.
|
||||
|
||||
"""
|
||||
|
||||
WHOIS = (
|
||||
"**WHO IS \"{full_name}\"?**\n"
|
||||
"[Link to profile](tg://user?id={user_id})\n"
|
||||
"════════════════\n"
|
||||
"UserID: `{user_id}`\n"
|
||||
"First Name: `{first_name}`\n"
|
||||
"Last Name: `{last_name}`\n"
|
||||
"Username: `{username}`\n"
|
||||
"Last Online: `{last_online}`\n"
|
||||
"Common Groups: `{common_groups}`\n"
|
||||
"════════════════\n"
|
||||
"Bio:\n{bio}")
|
||||
|
||||
WHOIS_PIC = (
|
||||
"**WHO IS \"{full_name}\"?**\n"
|
||||
"[Link to profile](tg://user?id={user_id})\n"
|
||||
"════════════════\n"
|
||||
"UserID: `{user_id}`\n"
|
||||
"First Name: `{first_name}`\n"
|
||||
"Last Name: `{last_name}`\n"
|
||||
"Username: `{username}`\n"
|
||||
"Last Online: `{last_online}`\n"
|
||||
"Common Groups: `{common_groups}`\n"
|
||||
"════════════════\n"
|
||||
"Profile Pics: `{profile_pics}`\n"
|
||||
"Last Updated: `{profile_pic_update}`\n"
|
||||
"════════════════\n"
|
||||
"Bio:\n{bio}")
|
||||
|
||||
|
||||
def LastOnline(user: User):
|
||||
if user.is_bot:
|
||||
return ""
|
||||
elif user.status == 'recently':
|
||||
return "Recently"
|
||||
elif user.status == 'within_week':
|
||||
return "Within the last week"
|
||||
elif user.status == 'within_month':
|
||||
return "Within the last month"
|
||||
elif user.status == 'long_time_ago':
|
||||
return "A long time ago :("
|
||||
elif user.status == 'online':
|
||||
return "Currently Online"
|
||||
elif user.status == 'offline':
|
||||
return datetime.fromtimestamp(user.status.date).strftime("%a, %d %b %Y, %H:%M:%S")
|
||||
|
||||
|
||||
async def GetCommon(client, get_user):
|
||||
common = await client.send(
|
||||
functions.messages.GetCommonChats(
|
||||
user_id=await client.resolve_peer(get_user),
|
||||
max_id=0,
|
||||
limit=0))
|
||||
return common
|
||||
|
||||
|
||||
def FullName(user: User):
|
||||
return user.first_name + " " + user.last_name if user.last_name else user.first_name
|
||||
|
||||
|
||||
def ProfilePicUpdate(user_pic):
|
||||
return datetime.fromtimestamp(user_pic[0].date).strftime("%d.%m.%Y, %H:%M:%S")
|
||||
|
||||
|
||||
@user1.on_message(Filters.me & Filters.command(["whois"], Command))
|
||||
async def whois(client, message):
|
||||
cmd = message.command
|
||||
if not message.reply_to_message and len(cmd) == 1:
|
||||
get_user = message.from_user.id
|
||||
elif message.reply_to_message and len(cmd) == 1:
|
||||
get_user = message.reply_to_message.from_user.id
|
||||
elif len(cmd) > 1:
|
||||
get_user = cmd[1]
|
||||
try:
|
||||
get_user = int(cmd[1])
|
||||
except ValueError:
|
||||
pass
|
||||
try:
|
||||
user = await client.get_users(get_user)
|
||||
except PeerIdInvalid:
|
||||
await message.edit("I don't know that User.")
|
||||
await sleep(2)
|
||||
await message.delete()
|
||||
return
|
||||
desc = await client.get_chat(get_user)
|
||||
desc = desc.description
|
||||
pic_count = await client.get_profile_photos_count(user.id)
|
||||
common = await GetCommon(client, user.id)
|
||||
|
||||
if not user.photo:
|
||||
await message.edit(
|
||||
WHOIS.format(
|
||||
full_name=FullName(user),
|
||||
user_id=user.id,
|
||||
first_name=user.first_name,
|
||||
last_name=user.last_name if user.last_name else "",
|
||||
username=user.username if user.username else "",
|
||||
last_online=LastOnline(user),
|
||||
common_groups=len(common.chats),
|
||||
bio=desc if desc else "`No bio set up.`"),
|
||||
disable_web_page_preview=True)
|
||||
elif user.photo:
|
||||
await message.edit(
|
||||
WHOIS.format(
|
||||
full_name=FullName(user),
|
||||
user_id=user.id,
|
||||
first_name=user.first_name,
|
||||
last_name=user.last_name if user.last_name else "",
|
||||
username=user.username if user.username else "",
|
||||
profile_pics=pic_count,
|
||||
last_online=LastOnline(user),
|
||||
common_groups=len(common.chats),
|
||||
bio=desc if desc else "`No bio set up.`"),
|
||||
disable_web_page_preview=True)
|
Loading…
Reference in New Issue