Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion nana/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import platform
import sys
import time
from inspect import getfullargspec

import requests
from pydrive.auth import GoogleAuth
from pyrogram import Client, errors
from pyrogram.types import Message
from sqlalchemy import create_engine, exc
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, scoped_session
Expand Down Expand Up @@ -56,7 +58,7 @@
device_model = platform.machine()
app_version = "💝 Nana v{}".format(USERBOT_VERSION)
system_version = platform.platform()

time_country = get_var('time_country', None)
# Must be filled
api_id = get_var('api_id', None)
api_hash = get_var('api_hash', None)
Expand Down Expand Up @@ -97,6 +99,9 @@
remove_bg_api = get_var('remove_bg_api', None)
HEROKU_API = get_var('HEROKU_API', None)
BINDERBYTE_API = get_var('BINDERBYTE_API', None)
sw_api = get_var('sw_api', None)
IBM_WATSON_CRED_URL = get_var('IBM_WATSON_CRED_URL', None)
IBM_WATSON_CRED_PASSWORD = get_var('IBM_WATSON_CRED_PASSWORD', None)
# Spotify
SPOTIPY_CLIENT_ID = get_var('SPOTIPY_CLIENT_ID', None)
SPOTIPY_CLIENT_SECRET = get_var('SPOTIPY_CLIENT_SECRET', None)
Expand Down Expand Up @@ -213,3 +218,8 @@ async def get_bot():

app = Client(APP_SESSION, api_id=api_id, api_hash=api_hash, app_version=app_version, device_model=device_model,
system_version=system_version, lang_code=lang_code, workers=NANA_WORKER, test_mode=TEST_MODE)

async def edrep(msg: Message, **kwargs):
func = msg.edit_text if msg.from_user.is_self else msg.reply
spec = getfullargspec(func.__wrapped__).args
await func(**{k: v for k, v in kwargs.items() if k in spec})
2 changes: 2 additions & 0 deletions nana/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ async def start_bot():
if not imported_module.__MODULE__.lower() in HELP_COMMANDS:
HELP_COMMANDS[imported_module.__MODULE__.lower()] = imported_module
else:
print(HELP_COMMANDS[imported_module.__MODULE__.lower()])
pass
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
Expand Down
5 changes: 2 additions & 3 deletions nana/assistant/stickers.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ def get_stickerlist(message):
global TEMP_KEYBOARD, USER_SET
if message.from_user and message.from_user.id in list(USER_SET):
return True
else:
TEMP_KEYBOARD = []
USER_SET = {}
TEMP_KEYBOARD = []
USER_SET = {}


@setbot.on_message(get_stickerlist)
Expand Down
9 changes: 9 additions & 0 deletions nana/helpers/expand.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import aiohttp


async def expand_url(url):
async with aiohttp.ClientSession() as session:
async with session.get(f"http://expandurl.com/api/v1/?url={url}") as resp:
expanded = await resp.text()

return expanded if expanded != "false" and expanded[:-1] != url else None
71 changes: 37 additions & 34 deletions nana/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
from nana import USERBOT_LOAD, USERBOT_NOLOAD, 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')]

if USERBOT_LOAD or USERBOT_NOLOAD:
to_load = USERBOT_LOAD
if to_load:
if not all(any(mod == module_name for module_name in all_modules) for mod in to_load):
log.error("Invalid Module name for userbot!")
quit(1)

else:
to_load = all_modules

if USERBOT_NOLOAD:
log.info("Userbot No load: {}".format(USERBOT_NOLOAD))
return [item for item in to_load if item not in USERBOT_NOLOAD]

return to_load

return all_modules


ALL_MODULES = sorted(__list_all_modules())
log.info("Userbot module loaded: %s", str(ALL_MODULES))
__all__ = ALL_MODULES + ["ALL_MODULES"]
"""
Directory for modules.
"""
from nana import USERBOT_LOAD, USERBOT_NOLOAD, 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')]

if USERBOT_LOAD or USERBOT_NOLOAD:
to_load = USERBOT_LOAD
if to_load:
if not all(any(mod == module_name for module_name in all_modules) for mod in to_load):
log.error("Invalid Module name for userbot!")
quit(1)

else:
to_load = all_modules

if USERBOT_NOLOAD:
log.info("Userbot No load: {}".format(USERBOT_NOLOAD))
return [item for item in to_load if item not in USERBOT_NOLOAD]

return to_load

return all_modules


ALL_MODULES = sorted(__list_all_modules())
log.info("Userbot module loaded: %s", str(ALL_MODULES))
__all__ = ALL_MODULES + ["ALL_MODULES"]
21 changes: 9 additions & 12 deletions nana/modules/afk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pyrogram import filters
from pyrogram.types import InlineKeyboardMarkup, InlineKeyboardButton

from nana import app, setbot, Owner, OwnerName, Command, DB_AVAILABLE
from nana import app, setbot, Owner, OwnerName, Command, DB_AVAILABLE, edrep
from nana.helpers.msg_types import Types, get_message_type
from nana.helpers.parser import mention_markdown, escape_markdown

Expand Down Expand Up @@ -33,7 +33,7 @@
DELAY_TIME = 60 # seconds


@app.on_message(filters.me & (filters.command(["afk"], Command) | filters.regex("^brb ")))
@app.on_message(filters.me & (filters.command("afk", Command)))
async def afk(_client, message):
if not DB_AVAILABLE:
await message.edit("Your database is not avaiable!")
Expand Down Expand Up @@ -64,22 +64,19 @@ async def afk_mentioned(_client, message):
else:
cid = str(message.chat.id)

if cid in list(AFK_RESTIRECT):
if int(AFK_RESTIRECT[cid]) >= int(time.time()):
return
if cid in list(AFK_RESTIRECT) and int(AFK_RESTIRECT[cid]) >= int(
time.time()
):
return
AFK_RESTIRECT[cid] = int(time.time()) + DELAY_TIME
if get['reason']:
await message.reply(
"Sorry, {} is AFK!\nBecause of {}".format(mention_markdown(Owner, OwnerName), get['reason']))
await edrep(message, text=f"Sorry, {mention_markdown(Owner, OwnerName)} is AFK!\nBecause of {get['reason']}")
else:
await message.reply("Sorry, {} is AFK!".format(mention_markdown(Owner, OwnerName)))
await edrep(message, text=f"Sorry, {mention_markdown(Owner, OwnerName)} is AFK!")

_, message_type = get_message_type(message)
if message_type == Types.TEXT:
if message.text:
text = message.text
else:
text = message.caption
text = message.text if message.text else message.caption
else:
text = message_type.name

Expand Down
56 changes: 56 additions & 0 deletions nana/modules/alive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@

import time

from pyrogram import filters

from nana import setbot, AdminSettings, BotUsername, app, Command, OwnerUsername, StartTime
from nana.helpers.PyroHelpers import ReplyCheck


def get_readable_time(seconds: int) -> str:
count = 0
ping_time = ""
time_list = []
time_suffix_list = ["s", "m", "h", "days"]

while count < 4:
count += 1
remainder, result = divmod(seconds, 60) if count < 3 else divmod(seconds, 24)
if seconds == 0 and remainder == 0:
break
time_list.append(int(result))
seconds = int(remainder)

for x in range(len(time_list)):
time_list[x] = str(time_list[x]) + time_suffix_list[x]
if len(time_list) == 4:
ping_time += time_list.pop() + ", "

time_list.reverse()
ping_time += ":".join(time_list)

return ping_time


@setbot.on_callback_query(filters.regex("^alive_message"))
async def alivemsg_callback(client, query):
start_time = time.time()
uptime = get_readable_time((time.time() - StartTime))
reply_msg = f"{OwnerUsername}@nana-remix\n"
reply_msg += "------------------\n"
end_time = time.time()
ping_time = round((end_time - start_time) * 1000, 3)
reply_msg += f"Ping: {ping_time}ms\n"
reply_msg += f"Userbot uptime: {uptime}"
await client.answer_callback_query(query.id, reply_msg, show_alert=True)


@app.on_message(filters.user(AdminSettings) & filters.command("alive", Command))
async def google_search(client, message):
x = await client.get_inline_bot_results(f"{BotUsername}", "alive")
await message.delete()
await client.send_inline_bot_result(chat_id=message.chat.id,
query_id=x.query_id,
result_id=x.results[0].id,
reply_to_message_id=ReplyCheck(message),
hide_via=True)
Loading