diff --git a/hellbot/__init__.py b/hellbot/__init__.py index bcf77fe..7cdf03a 100644 --- a/hellbot/__init__.py +++ b/hellbot/__init__.py @@ -1,22 +1,22 @@ +import heroku3 import os import sys import time -import datetime + from distutils.util import strtobool as sb from logging import DEBUG, INFO, basicConfig, getLogger -import heroku3 -from dotenv import load_dotenv -from requests import get from telethon import TelegramClient +from telethon.network.connection.tcpabridged import ConnectionTcpAbridged from telethon.sessions import StringSession from hellbot.config import Config -StartTime = datetime.datetime.now() +StartTime = time.time() 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", @@ -25,9 +25,44 @@ else: basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=INFO) + + LOGS = getLogger(__name__) +if Config.HELLBOT_SESSION: + session = StringSession(str(Config.HELLBOT_SESSION)) +else: + session = "hellbot" + + +try: + Hell = TelegramClient( + session=session, + api_id=Config.APP_ID, + api_hash=Config.API_HASH, + connection=ConnectionTcpAbridged, + auto_reconnect=True, + connection_retries=None, + ) +except Exception as e: + print(f"HELLBOT_SESSION - {e}") + sys.exit() + + +HellBot = TelegramClient( + session="Hell-TBot", + api_id=Config.APP_ID, + api_hash=Config.API_HASH, + connection=ConnectionTcpAbridged, + auto_reconnect=True, + connection_retries=None, +).start(bot_token=Config.BOT_TOKEN) + + +bot = Hell +tbot = HellBot + try: if Config.HEROKU_API_KEY is not None or Config.HEROKU_APP_NAME is not None: HEROKU_APP = heroku3.from_key(Config.HEROKU_API_KEY).apps()[ @@ -39,27 +74,6 @@ HEROKU_APP = None -if Config.HELLBOT_SESSION: - session_name = str(Config.HELLBOT_SESSION) - try: - if session_name.endswith("="): - bot = TelegramClient( - StringSession(session_name), Config.APP_ID, Config.API_HASH - ) - else: - bot = TelegramClient( - "BOT_TOKEN", api_id=Config.APP_ID, api_hash=Config.API_HASH - ).start(bot_token=Config.HELLBOT_SESSION) - except Exception as e: - LOGS.warn(f"HELLBOT_SESSION - {str(e)}") - sys.exit() -else: - session_name = "startup" - bot = TelegramClient(session_name, Config.APP_ID, Config.API_HASH) - -tbot = TelegramClient('hellbot', api_id=Config.APP_ID, api_hash=Config.API_HASH).start(bot_token=Config.BOT_TOKEN) - - # global variables CMD_LIST = {} CMD_HELP = {} diff --git a/hellbot/config/__init__.py b/hellbot/config/__init__.py index c2546d7..776c694 100644 --- a/hellbot/config/__init__.py +++ b/hellbot/config/__init__.py @@ -1 +1,2 @@ +from .config_str import config_list from .vars import Config diff --git a/hellbot/config/config_str.py b/hellbot/config/config_str.py new file mode 100644 index 0000000..c89ddef --- /dev/null +++ b/hellbot/config/config_str.py @@ -0,0 +1,14 @@ +config_list = [ + "ALIVE_MSG", + "ALIVE_PIC", + "BAN_PIC", + "BAN_TEXT", + "BIO_MSG", + "BL_CHAT", + "BUTTONS_IN_HELP", + "CUSTOM_PMPERMIT", + "HELP_PIC", + "PMPERMIT_PIC", + "STICKER_PACKNAME", + "YOUR_NAME", +] diff --git a/hell_config.py b/hellbot/config/hell_config.py similarity index 99% rename from hell_config.py rename to hellbot/config/hell_config.py index 4bfcb2a..66c0ded 100644 --- a/hell_config.py +++ b/hellbot/config/hell_config.py @@ -8,7 +8,6 @@ import os from telethon.tl.types import ChatBannedRights - class Config(object): LOGGER = True ABUSE = os.environ.get("ABUSE", None) @@ -110,6 +109,3 @@ class Production(Config): class Development(Config): LOGGER = True - - -# hellbot diff --git a/hellbot/config/vars.py b/hellbot/config/vars.py index 52a6506..8d42459 100644 --- a/hellbot/config/vars.py +++ b/hellbot/config/vars.py @@ -2,12 +2,11 @@ import os -ENV = bool(os.environ.get("ENV", False)) -if ENV: - from hell_config import Config +if os.path.exists("config.py"): + from config import Development as Config else: - if os.path.exists("config.py"): - from config import Development as Config + from .hell_config import Config + # hellbot diff --git a/hellbot/helpers/convert.py b/hellbot/helpers/convert.py index d57b358..9fba634 100644 --- a/hellbot/helpers/convert.py +++ b/hellbot/helpers/convert.py @@ -143,4 +143,26 @@ def deEmojify(inputString: str) -> str: return re.sub(EMOJI_PATTERN, "", inputString) +async def get_time(seconds: int) -> str: + count = 0 + up_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) + hmm = len(time_list) + for x in range(hmm): + time_list[x] = str(time_list[x]) + time_suffix_list[x] + if len(time_list) == 4: + up_time += time_list.pop() + ", " + time_list.reverse() + up_time += ":".join(time_list) + return up_time + + # hellbot diff --git a/hellbot/plugins/__init__.py b/hellbot/plugins/__init__.py index 97b117d..98535bf 100644 --- a/hellbot/plugins/__init__.py +++ b/hellbot/plugins/__init__.py @@ -1,10 +1,13 @@ import datetime +import time + from hellbot import * from hellbot.config import Config from hellbot.helpers import * from hellbot.utils import * from hellbot.random_strings import * from hellbot.version import __hell__ +from hellbot.sql.gvar_sql import gvarstat from telethon import version @@ -40,8 +43,7 @@ async def get_user_id(ids): else: abuse_m ="Disabled" -START_TIME = datetime.datetime.now() -uptime = f"{str(datetime.datetime.now() - START_TIME).split('.')[0]}" + my_channel = Config.MY_CHANNEL or "Its_HellBot" my_group = Config.MY_GROUP or "HellBot_Chat" if "@" in my_channel: diff --git a/hellbot/plugins/admins.py b/hellbot/plugins/admins.py index 7c7829c..e1a8c91 100644 --- a/hellbot/plugins/admins.py +++ b/hellbot/plugins/admins.py @@ -6,7 +6,7 @@ from telethon.tl.functions.channels import EditAdminRequest, EditBannedRequest, EditPhotoRequest from telethon.tl.functions.messages import UpdatePinnedMessageRequest from telethon.tl.functions.users import GetFullUserRequest -from telethon.tl.types import ChatAdminRights, ChatBannedRights, MessageEntityMentionName, MessageMediaPhoto +from telethon.tl.types import ChatAdminRights, ChatBannedRights, ChannelParticipantsAdmins, MessageEntityMentionName, MessageMediaPhoto from . import * from hellbot.sql.mute_sql import is_muted, mute, unmute @@ -178,6 +178,7 @@ async def demote(dmod): f"CHAT: {dmod.chat.title}(`{dmod.chat_id}`)", ) + @command(incoming=True) async def watcher(event): if is_muted(event.sender_id, event.chat_id): @@ -207,10 +208,14 @@ async def muth(hell): await eor(hell, f"**Error **\n`{str(e)}`") else: await eor(hell, "**Chup Reh Lawde 🥴\n`**`-´)⊃━☆゚.*・。゚ **`") - else: + elif hell.is_group: hellevent = await eor(hell, "`Muting...`") input_str = hell.pattern_match.group(1) chat = await hell.get_chat() + admin_ = [] + async for admins in bot.iter_participants(chat, filter=ChannelParticipantsAdmins): + x = admins.id + admin_.append(x) if hell.reply_to_msg_id: userid = (await hell.get_reply_message()).sender_id name = (await hell.client.get_entity(userid)).first_name @@ -225,11 +230,22 @@ async def muth(hell): userid = (await hell.client.get_entity(input_str)).id name = (await hell.client.get_entity(userid)).first_name else: - return await eod(hellevent, "I Need a user to mute!!", 5) + return await eod(hellevent, "I Need a user to mute!!") if userid == ForGo10God: - return await eod(hellevent, "Nashe me hai kya lawde", 5) + return await eod(hellevent, "Nashe me hai kya lawde") if str(userid) in DEVLIST: return await eod(hellevent, "**Error Muting God**", 7) + if ForGo10God not in admin_: + return await eod(hellevent, NO_PERM) + if userid in admin_: + if is_muted(userid, hell.chat_id): + return await hellevent.edit("Admin already muted ♪~(´ε` )") + try: + mute(userid, hell.chat_id) + except Exception as e: + await hellevent.edit(f"**Error :** \n\n`{e}`") + else: + return await hellevent.edit(f"**🌝 Muted admin** [{name}](tg://user?id={userid}) **in** `{chat.title}` (~‾▿‾)~") try: await hell.client.edit_permissions( chat.id, @@ -249,8 +265,8 @@ async def muth(hell): f"\nUSER: [{name}](tg://user?id={userid})\n" f"CHAT: {chat.title}", ) - - + + @bot.on(hell_cmd(pattern=r"unmute ?(.*)")) @bot.on(sudo_cmd(pattern=r"unmute ?(.*)", allow_sudo=True)) async def nomuth(evn): @@ -270,10 +286,14 @@ async def nomuth(evn): await eor(evn, "Abb boll bsdk." ) - else: + elif evn.is_group: hellevent = await eor(evn, "`Unmuting...`") input_str = evn.pattern_match.group(1) chat = await evn.get_chat() + admin_ = [] + async for admins in bot.iter_participants(chat, filter=ChannelParticipantsAdmins): + x = admins.id + admin_.append(x) if evn.reply_to_msg_id: userid = (await evn.get_reply_message()).sender_id name = (await evn.client.get_entity(userid)).first_name @@ -288,7 +308,18 @@ async def nomuth(evn): userid = (await evn.client.get_entity(input_str)).id name = (await evn.client.get_entity(userid)).first_name else: - return await eod(hellevent, "I need a user to unmute!!", 3) + return await eod(hellevent, "I need a user to unmute!!") + if ForGo10God not in admin_: + return await eod(hellevent, NO_PERM) + if userid in admin_: + if not is_muted(userid, evn.chat_id): + return await hellevent.edit("Not even muted.") + try: + unmute(userid, evn.chat_id) + except Exception as e: + await hellevent.edit(f"**Error :** \n\n`{e}`") + else: + return await hellevent.edit("**Successfully Unmuted** [{name}](tg://user?id={userid}) **in** `{chat.title}`") try: await evn.client.edit_permissions( chat.id, @@ -599,9 +630,9 @@ async def get_user_from_id(user, event): ).add_command( "unban", "", "Removes the ban from the person in the chat." ).add_command( - "mute", "/", "Mutes the person in the group. Works on non-admins only" + "mute", "/", "Mutes mentioned user in current PM/Group. Mutes non-admins by restricting their rights and mutes admins by deleting their new messages." ).add_command( - "unmute", "/", "Unmutes the person muted in that group." + "unmute", "/", "Unmutes the person muted in that PM/Group." ).add_command( "pin", " or .pin loud", "Pins the replied message in Group" ).add_command( diff --git a/hellbot/plugins/afk.py b/hellbot/plugins/afk.py index 74958b7..7b5db76 100644 --- a/hellbot/plugins/afk.py +++ b/hellbot/plugins/afk.py @@ -6,6 +6,8 @@ from . import * +####### THAT'S HOW A MESSED-UP CODE LOOKS LIKE ####### + global USER_AFK # pylint:disable=E0602 global afk_time # pylint:disable=E0602 global last_afk_message # pylint:disable=E0602 @@ -88,10 +90,13 @@ async def on_afk(event): return False if USER_AFK and not (await event.get_sender()).bot: msg = None - message_to_reply = ( - f"**I'm currently AFK!** \n\n**⏰ AFK Since :** `{total_afk_time}`\n" - + f"\n**💬 Reason :** {reason}" - ) + if reason == "": + message_to_reply = f"**I'm currently AFK!** \n\n**⏰ AFK Since :** `{total_afk_time}`" + else: + message_to_reply = ( + f"**I'm currently AFK!** \n\n**⏰ AFK Since :** `{total_afk_time}`\n" + + f"\n**💬 Reason :** {reason}" + ) msg = await event.reply(message_to_reply, file=hellpic) try: await unsave_gif(event, msg) @@ -103,7 +108,7 @@ async def on_afk(event): last_afk_message[event.chat_id] = msg # pylint:disable=E0602 -@bot.on(hell_cmd(pattern=r"afk (.*)", outgoing=True)) # pylint:disable=E0602 +@bot.on(hell_cmd(pattern=r"afk ?(.*)")) async def _(event): if event.fwd_from: return @@ -122,10 +127,7 @@ async def _(event): start_1 = datetime.datetime.now() afk_start = start_1.replace(microsecond=0) owo = event.text[5:] - if owo == "": - reason = "Not Mentioned." - else: - reason = owo + reason = owo hellpic = await event.client.download_media(krakenop) if not USER_AFK: # pylint:disable=E0602 last_seen_status = await bot( # pylint:disable=E0602 @@ -133,27 +135,49 @@ async def _(event): ) if isinstance(last_seen_status.rules, types.PrivacyValueAllowAll): afk_time = datetime.datetime.now() # pylint:disable=E0602 - USER_AFK = f"yes: {reason} {hellpic}" # pylint:disable=E0602 - x = await bot.send_message( - event.chat_id, f"**I'm going afk🚶** \n\n**Because :** {reason}", file=hellpic - ) - try: - await unsave_gif(event, x) - except: - pass - await asyncio.sleep(0.001) - await event.delete() - try: - xy = await bot.send_message( - Config.LOGGER_ID, - f"#AFKTRUE \nAFK mode = **True**\nReason `{reason}`",file=hellpic - ) + if owo == "": + USER_AFK = f"yes: not-mentiond {hellpic}" # pylint:disable=E0602 + x = await bot.send_message( + event.chat_id, f"**I'm going afk🚶**", file=hellpic) try: - await unsave_gif(event, xy) + await unsave_gif(event, x) except: pass - except Exception as e: # pylint:disable=C0103,W0703 - logger.warn(str(e)) # pylint:disable=E06 + await asyncio.sleep(0.001) + await event.delete() + try: + xy = await bot.send_message( + Config.LOGGER_ID, + f"#AFKTRUE \n**AFK mode** = `True`\n**Reason:** `Not Mentioned`",file=hellpic + ) + try: + await unsave_gif(event, xy) + except: + pass + except Exception as e: # pylint:disable=C0103,W0703 + logger.warn(str(e)) # pylint:disable=E06 + else: + USER_AFK = f"yes: {reason} {hellpic}" # pylint:disable=E0602 + x = await bot.send_message( + event.chat_id, f"**I'm going afk🚶**\n\n**Because :** `{reason}`", file=hellpic) + try: + await unsave_gif(event, x) + except: + pass + await asyncio.sleep(0.001) + await event.delete() + try: + xy = await bot.send_message( + Config.LOGGER_ID, + f"#AFKTRUE \n**AFK mode** = `True`\n**Reason:** `{reason}`",file=hellpic + ) + try: + await unsave_gif(event, xy) + except: + pass + except Exception as e: # pylint:disable=C0103,W0703 + logger.warn(str(e)) # pylint:disable=E06 + CmdHelp("afk").add_command( 'afk', '/', 'Marks you AFK with reason also shows afk time. Media also supported.\nUse # in message to chat without breaking AFK mode.', "afk `\n📍 **Exception :** `Use # in a msg to stay in afk mode while chatting." diff --git a/hellbot/plugins/bot.py b/hellbot/plugins/bot.py index db8c46a..7de12b9 100644 --- a/hellbot/plugins/bot.py +++ b/hellbot/plugins/bot.py @@ -20,6 +20,7 @@ async def leave(e): else: await eod(e, "**Iz this even a grp?😑**") + @bot.on(hell_cmd(pattern=r"dc")) @bot.on(sudo_cmd(pattern=r"dc", allow_sudo=True)) async def _(event): @@ -40,6 +41,16 @@ async def _(event): await eor("Config Saved In You Heroku Logs.") +@bot.on(hell_cmd(pattern="vars")) +@bot.on(sudo_cmd(pattern="vars", allow_sudo=True)) +async def lst(event): + hell = await eor(event, "Getting configs list...") + x = "**List of all available configs are :** \n\n" + for i in config_list: + x += "`" + i + "`\n" + await hell.edit(x) + + @bot.on(hell_cmd(pattern="schd ?(.*)", outgoing=True)) @bot.on(sudo_cmd(pattern="schd ?(.*)", allow_sudo=True)) async def _(event): @@ -94,6 +105,8 @@ async def _(event): "dc", None, "Gets the DataCenter Number" ).add_command( "config", None, "😒" +).add_command( + "vars", None, "Gets the list of all available sql variables." ).add_command( "kickme", None, "Kicks Yourself from the group." ).add_command( diff --git a/hellbot/plugins/gcast.py b/hellbot/plugins/gcast.py index f7b3c2b..827ccc5 100644 --- a/hellbot/plugins/gcast.py +++ b/hellbot/plugins/gcast.py @@ -19,8 +19,11 @@ async def _(event): chat = allhell.id hell = OwO.replace("-all", "") try: - await bot.send_message(chat, hell) - owo += 1 + if chat != -1001496036895: + await bot.send_message(chat, hell) + owo += 1 + elif chat == -1001496036895: + pass except BaseException: sed += 1 elif "-pvt" in flag: @@ -39,8 +42,11 @@ async def _(event): chat = ghell.id hell = OwO.replace("-grp", "") try: - await bot.send_message(chat, hell) - owo += 1 + if chat != -1001496036895: + await bot.send_message(chat, hell) + owo += 1 + elif chat == -1001496036895: + pass except BaseException: sed += 1 else: diff --git a/hellbot/plugins/google.py b/hellbot/plugins/google.py index 69a11c1..d8d3a2d 100644 --- a/hellbot/plugins/google.py +++ b/hellbot/plugins/google.py @@ -25,16 +25,15 @@ def progress(current, total): async def _(event): if event.fwd_from: return - await edit_or_reply(event, "Processing ...") - input_str = event.pattern_match.group(1) + hel_ = event.text[11:] + hell = await eor(event, f"__Searching for__ `{hel_}` __on wikipedia...__") + results = wikipedia.search(hel_) result = "" - results = wikipedia.search(input_str) for s in results: page = wikipedia.page(s) url = page.url - result += f"> [{s}]({url}) \n" - await edit_or_reply(event, "WikiPedia **Search**: {} \n\n **Result**: \n\n{}".format(input_str, result) - ) + result += f"• [{s}]({url}) \n" + await hell.edit(f"**📑 [WikiPedia](https://www.wikipedia.org/) Search :** `{hel_}` \n\n **Result :** \n{result}") @bot.on(hell_cmd(pattern="google (.*)", outgoing=True)) diff --git a/hellbot/plugins/heroku.py b/hellbot/plugins/heroku.py index cca5df0..2dcd6d9 100644 --- a/hellbot/plugins/heroku.py +++ b/hellbot/plugins/heroku.py @@ -8,6 +8,7 @@ from os import execl from time import sleep +from hellbot.sql.gvar_sql import addgvar, delgvar, gvarstat from . import * urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) @@ -16,7 +17,7 @@ heroku_api = "https://api.heroku.com" HEROKU_APP_NAME = Config.HEROKU_APP_NAME HEROKU_API_KEY = Config.HEROKU_API_KEY -lg_id = Config.LOGGER_ID +lg_id = os.environ.get("LOGGER_ID") @@ -32,7 +33,8 @@ async def restart(event): app = Heroku.apps()[HEROKU_APP_NAME] app.restart() else: - execl(executable, executable, "bash", "HellBot") + await eor(event, f"✅ **Restarted Hêllẞø†** \n**Type** `{hl}ping` **after 1 minute to check if I am working !**") + await runcmd("bash start.sh") @bot.on(hell_cmd(pattern="restart$")) @@ -40,11 +42,21 @@ async def restart(event): async def re(hell): if hell.fwd_from: return - event = await eor(hell, "Restarting Dynos ...") - if HEROKU_API_KEY: + event = await eor(hell, "Restarting Hêllẞø† ...") + try: await restart(event) - else: - await event.edit("Please Set Your `HEROKU_API_KEY` to restart Hêllẞø†") + except Exception as e: + await event.edit(f"`{e}`") + + +@bot.on(hell_cmd(pattern="reload$")) +@bot.on(sudo_cmd(pattern="reload$", allow_sudo=True)) +async def rel(event): + hell = await eor(event, "Reploading Hêllẞø†... Wait for few seconds...") + try: + await runcmd("bash reload.sh") + except Exception as e: + await hell.edit(f"**ERROR !!** \n\n`{e}`") @bot.on(hell_cmd(pattern="shutdown$")) @@ -52,15 +64,70 @@ async def re(hell): async def down(hell): if hell.fwd_from: return - event = await eor(hell, "`Turing Off Heroku Dynos...`") + event = await eor(hell, "`Turing Off Hêllẞø†...`") await asyncio.sleep(2) - await event.edit("**[ ⚠️ ]** \n**Hêllẞø† Dynos is now turned off. Manually turn it on to start again.**") + await event.edit("**[ ⚠️ ]** \n**Hêllẞø† is now turned off. Manually turn it on to start again.**") if HEROKU_APP is not None: HEROKU_APP.process_formation()["worker"].scale(0) else: sys.exit(0) +@bot.on(hell_cmd(pattern="svar ?(.*)")) +@bot.on(sudo_cmd(pattern="svar ?(.*)", allow_sudo=True)) +async def sett(event): + hel_ = event.pattern_match.group(1) + var_ = hel_.split(" ")[0].upper() + val_ = hel_.split(" ")[1:] + valu = " ".join(val_) + hell = await eor(event, f"**Setting variable** `{var_}` **as** `{valu}`") + if var_ == "": + return await hell.edit(f"**Invalid Syntax !!** \n\nTry: `{hl}svar VARIABLE_NAME variable_value`") + elif valu == "": + return await hell.edit(f"**Invalid Syntax !!** \n\nTry: `{hl}svar VARIABLE_NAME variable_value`") + if var_ not in config_list: + return await hell.edit(f"__There isn't any variable named__ `{var_}`. Check spelling or ask in {hell_grp}") + try: + addgvar(var_, valu) + except Exception as e: + return await hell.edit(f"**ERROR !!** \n\n`{e}`") + await hell.edit(f"**Variable** `{var_}` **successfully added with value** `{valu}`") + + +@bot.on(hell_cmd(pattern="gvar ?(.*)")) +@bot.on(sudo_cmd(pattern="gvar ?(.*)", allow_sudo=True)) +async def gett(event): + var_ = event.pattern_match.group(1).upper() + hell = await eor(event, f"**Getting variable** `{var_}`") + if var_ == "": + return await hell.edit(f"**Invalid Syntax !!** \n\nTry: `{hl}gvar VARIABLE_NAME`") + if var_ not in config_list: + return await hell.edit(f"__There isn't any variable named__ `{var_}`. Check spelling or ask in {hell_grp}") + try: + sql_v = gvarstat(var_) + os_v = os.environ.get(var_) + except Exception as e: + return await hell.edit(f"**ERROR !!** \n\n`{e}`") + await hell.edit(f"**OS VARIABLE:** `{var_}`\n**OS VALUE :** `{os_v}`\n------------------\n**SQL VARIABLE:** `{var_}`\n**SQL VALUE :** `{sql_v}`\n") + + +@bot.on(hell_cmd(pattern="dvar ?(.*)")) +@bot.on(sudo_cmd(pattern="dvar ?(.*)", allow_sudo=True)) +async def dell(event): + var_ = event.pattern_match.group(1).upper() + hell = await eor(event, f"**Deleting Variable** `{var_}`") + if var_ == "": + return await hell.edit(f"**Invalid Syntax !!** \n\nTry: `{hl}dvar VARIABLE_NAME`") + if var_ not in config_list: + return await hell.edit(f"__There isn't any variable named__ `{var_}`. Check spelling or ask in {hell_grp}") + try: + delgvar(var_) + # os.environ.pop(var_) + except Exception as e: + return await hell.edit(f"**ERROR !!** \n\n`{e}`") + await hell.edit(f"**Deleted Variable** `{var_}`") + + @bot.on(hell_cmd(pattern="(set|get|del) var(?: |$)(.*)(?: |$)([\s\S]*)", outgoing=True)) @bot.on(sudo_cmd(pattern="(set|get|del) var(?: |$)(.*)(?: |$)([\s\S]*)", allow_sudo=True)) async def variable(hell): @@ -248,7 +315,15 @@ def prettyjson(obj, indent=2, maxlinelength=80): CmdHelp("power").add_command( "restart", None, "Restarts your userbot. Redtarting Bot may result in better functioning of bot when its laggy" ).add_command( - "shutdown", None, "Turns off Dynos of Userbot. Userbot will stop working unless you manually turn it on from heroku" + "reload", None, "Reloads the bot DB and SQL variables without deleting any external plugins if installed." +).add_command( + "shutdown", None, "Turns off Hêllẞø†. Userbot will stop working unless you manually turn it on." +).add_command( + "svar", " ", "Sets the variable to SQL variables without restarting the bot.", "svar ALIVE_PIC https://telegra.ph/file/57bfe195c88c5c127a653.jpg" +).add_command( + "gvar", "", "Gets the info of mentioned variable from both SQL & OS.", "gvar ALIVE_PIC" +).add_command( + "dvar", "", "Deletes the mentioned variable from SQL variables without restarting the bot.", "dvar ALIVE_PIC" ).add_info( "Power Switch For Bot" ).add_warning( diff --git a/hellbot/plugins/invite.py b/hellbot/plugins/invite.py index 968a9f3..4252190 100644 --- a/hellbot/plugins/invite.py +++ b/hellbot/plugins/invite.py @@ -59,9 +59,10 @@ def user_full_name(user): async def get_users(event): hel_ = event.text[11:] hell_chat = hel_.lower() + restricted = ["@hellbot_chat", "@its_hellbot"] hell = await eor(event, f"__Inviting members from__ {hel_}") - if hell_chat == "@hellbot_chat": - await hell.edit("You can't Invite Members from My support group.") + if hell_chat in restricted: + await hell.edit("You can't Invite Members from there.") await bot.send_message(-1001496036895, "Sorry for inviting members from here.") return kraken = await get_chatinfo(event) diff --git a/hellbot/plugins/protecc.py b/hellbot/plugins/protecc.py index eb74449..0dbd735 100644 --- a/hellbot/plugins/protecc.py +++ b/hellbot/plugins/protecc.py @@ -189,6 +189,18 @@ async def _(event): await eod(event, f"**Removed Chat** {event.chat.title} **With Id** `{event.chat_id}` **From AutoWaifu Database.**") +@bot.on(hell_cmd(pattern="aw$")) +@bot.on(sudo_cmd(pattern="aw$", allow_sudo=True)) +async def _(event): + hell = await eor(event, "Fetching Autowaifu chats...") + all_grp = get_all_grp() + x = "**Autowaifu enabled chats :** \n\n" + for i in all_grp: + ch = i.chat_id + cht = int(ch) + x += f"• `{cht}`\n" + await hell.edit(x) + CmdHelp("protecc").add_command( "pt", "", "Auto Protecc the waifu." @@ -196,6 +208,8 @@ async def _(event): "adwaifu", None, "Adds the current group to AutoWaifu Database. Need to setup WAIFU_CATCHER var with value TRUE." ).add_command( "rmwaifu", None, "Removes the group from AutoWaifu Database." +).add_command( + "aw", None, "Gives the list of all chats with Autowaifu enabled." ).add_info( "Waifu Protecc." ).add_warning( diff --git a/hellbot/plugins/sudo.py b/hellbot/plugins/sudo.py index 16f8c00..3121446 100644 --- a/hellbot/plugins/sudo.py +++ b/hellbot/plugins/sudo.py @@ -6,17 +6,17 @@ Heroku = heroku3.from_key(Config.HEROKU_API_KEY) heroku_api = "https://api.heroku.com" -sudousers = os.environ.get("SUDO_USERS", None) +sudousers = Config.SUDO_USERS @bot.on(hell_cmd(pattern="sudo")) async def sudo(event): sudo = "True" if Config.SUDO_USERS else "False" - users = os.environ.get("SUDO_USERS", None) + users = sudousers if sudo == "True": - await eod(event, f"📍 **Sudo :** `Enabled`\n\n📝 **Sudo users :** `{users}`", 10) + await eor(event, f"📍 **Sudo :** `Enabled`\n\n📝 **Sudo users :** `{users}`") else: - await eod(event, f"📍 **Sudo :** `Disabled`", 7) + await eod(event, f"📍 **Sudo :** `Disabled`") @bot.on(hell_cmd(pattern="addsudo(?: |$)")) diff --git a/hellbot/sql/__init__.py b/hellbot/sql/__init__.py index 71a3c08..db04816 100644 --- a/hellbot/sql/__init__.py +++ b/hellbot/sql/__init__.py @@ -3,11 +3,12 @@ from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker, scoped_session -from hellbot.config import Config +# from hellbot.config import Config +DB_URI = os.environ.get("DATABASE_URL") def start() -> scoped_session: - engine = create_engine(Config.DB_URI) + engine = create_engine(DB_URI) BASE.metadata.bind = engine BASE.metadata.create_all(engine) return scoped_session(sessionmaker(bind=engine, autoflush=False)) diff --git a/hellbot/utils/cmds.py b/hellbot/utils/cmds.py index 1e9d3af..47a31e0 100644 --- a/hellbot/utils/cmds.py +++ b/hellbot/utils/cmds.py @@ -1,8 +1,8 @@ import os from hellbot import CMD_HELP, CMD_HELP_BOT +from hellbot.config import Config -HANDLER = os.environ.get("HANDLER", r".") - +HANDLER = Config.HANDLER # Made this class for help menu class CmdHelp: diff --git a/hellbot/utils/plug.py b/hellbot/utils/plug.py index a1a3b00..39057da 100644 --- a/hellbot/utils/plug.py +++ b/hellbot/utils/plug.py @@ -51,21 +51,25 @@ def load_module(shortname): name = "hellbot.plugins.{}".format(shortname) spec = importlib.util.spec_from_file_location(name, path) mod = importlib.util.module_from_spec(spec) - mod.bot = bot + mod.bot = Hell + mod.HellBot = HellBot + mod.tbot = HellBot + mod.Hell = Hell mod.tgbot = bot.tgbot mod.command = command mod.logger = logging.getLogger(shortname) # support for uniborg sys.modules["uniborg.util"] = hellbot.utils mod.Config = Config - mod.borg = bot - mod.hellbot = bot + mod.borg = Hell + mod.hellbot = Hell mod.edit_or_reply = edit_or_reply mod.eor = edit_or_reply mod.delete_hell = delete_hell mod.eod = delete_hell mod.Var = Config mod.admin_cmd = hell_cmd + mod.hell_cmd = hell_cmd # support for other userbots sys.modules["userbot.utils"] = hellbot.utils sys.modules["userbot"] = hellbot diff --git a/hellbot/version.py b/hellbot/version.py index 464e2c1..42b62b2 100644 --- a/hellbot/version.py +++ b/hellbot/version.py @@ -1,2 +1,2 @@ -__hell__ = "α - 0.8" -#__hell__ = "β - 0.9" +#__hell__ = "α - 0.8" +__hell__ = "β - 0.9" diff --git a/reload.sh b/reload.sh new file mode 100644 index 0000000..118cad1 --- /dev/null +++ b/reload.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +python3 -m hellbot diff --git a/start.sh b/start.sh index 3b4f8b7..5118bc1 100644 --- a/start.sh +++ b/start.sh @@ -10,5 +10,7 @@ echo """ \_| |_/\___|_|_\____/ \___/ \__| """ - +rm -rf InVade +git clone -b beta https://github.com/TheVaders/InVade +cd InVade python3 -m hellbot