async def promote(client, message: Message): if await CheckAdmin(message) is False: await message.edit("**Am I an admin here?.**") return title = "" reply = message.reply_to_message if reply: user = reply.from_user["id"] title = str(get_arg(message)) else: args = get_args(message) if not args: await message.edit("**I can't promote no-one, can I?**") return user = args[0] if len(args) > 1: title = " ".join(args[1:]) get_user = await app.get_users(user) try: await app.promote_chat_member(message.chat.id, user, can_pin_messages=True) await message.edit( f"**{get_user.first_name} is now powered with admin rights with {title} as title!**" ) except Exception as e: await message.edit(f"{e}") if title: try: await app.set_administrator_title(message.chat.id, user, title) except: pass
async def demote(client, message: Message): if await CheckAdmin(message) is False: await message.edit("**I am not admin.**") return reply = message.reply_to_message if reply: user = reply.from_user["id"] else: user = get_arg(message) if not user: await message.edit("**I can't demote no-one, can I?**") return get_user = await app.get_users(user) try: await app.promote_chat_member( message.chat.id, user, is_anonymous=False, can_change_info=False, can_delete_messages=False, can_edit_messages=False, can_invite_users=False, can_promote_members=False, can_restrict_members=False, can_pin_messages=False, can_post_messages=False, ) await message.edit( f"**{get_user.first_name} is now stripped off of their admin rights!**" ) except Exception as e: await message.edit(f"{e}")
async def pmguard(client, message): arg = get_arg(message) if not arg: await message.edit("**Set limit to what?**") return Zectdb.set_limit(int(arg)) await message.edit(f"**Limit set to {arg}**")
async def afk(client, message): afk_time = int(time.time()) arg = get_arg(message) if not arg: reason = None else: reason = arg Zect.set_afk(True, afk_time, reason) await message.edit("**I'm goin' AFK**")
async def pmguard(client, message): arg = get_arg(message) if not arg: await message.edit("**I only understand on or off**") return if arg == "off": Zectdb.set_pm(False) await message.edit("**PM Guard Deactivated**") if arg == "on": Zectdb.set_pm(True) await message.edit("**PM Guard Activated**")
async def setpmmsg(client, message): arg = get_arg(message) if not arg: await message.edit("**What message to set**") return if arg == "default": Zectdb.set_permit_message(Zectdb.PMPERMIT_MESSAGE) await message.edit("**Anti_PM message set to default**.") return Zectdb.set_permit_message(f"`{arg}`") await message.edit("**Custom anti-pm message set**")
async def setpmmsg(client, message): arg = get_arg(message) if not arg: await message.edit("**What message to set**") return if arg == "default": Zectdb.set_block_message(Zectdb.BLOCKED) await message.edit("**Block message set to default**.") return Zectdb.set_block_message(f"`{arg}`") await message.edit("**Custom block message set**")
async def get(client, message): arg = get_arg(message) if not arg: await message.edit("Get what?") return note_name = arg note = await Zect.get_note(note_name) if not note: await message.edit(f"**Note {note_name} dosen't exists**") return await app.copy_message(message.chat.id, LOG_CHAT, note) await message.delete()
async def del_filterz(client, message): note_ = await message.edit("**Processing..**") note_name = get_arg(message) if not note_name: await note_.edit("**Give A Filter Name!**") return note_name = note_name.lower() if not await filters_info(note_name, int(message.chat.id)): await note_.edit("**Filter Not Found!**") return await del_filters(note_name, int(message.chat.id)) await note_.edit(f"**Filter `{note_name}` Deleted Successfully!**")
async def clear(client, message): arg = get_arg(message) if not arg: await message.edit("What do you want to delete?") return note_name = arg note = await Zect.get_note(note_name) if not note: await message.edit(f"**Failed to delete note `{note_name}`**") return await Zect.rm_note(note_name) await message.edit(f"**Succesfully deleted note `{note_name}`**")
async def gmute(_, message): reply = message.reply_to_message if reply: user = reply.from_user["id"] else: user = get_arg(message) if not user: await message.edit("**Whome should I ungmute?**") return get_user = await app.get_users(user) ungmute_user(get_user.id) await message.edit(f"**Unmuted {get_user.first_name}, enjoy!**")
async def s_filters(client, message): note_ = await message.edit("**Processing..**") note_name = get_arg(message) if not note_name: await note_.edit("**Give A Filter Name!**") return if not message.reply_to_message: await note_.edit("Reply To Message To Save As Filter!") return note_name = note_name.lower() msg = message.reply_to_message copied_msg = await msg.copy(int(LOG_CHAT)) await add_filters(note_name, int(message.chat.id), copied_msg.message_id) await note_.edit(f"**Done! `{note_name}` Added To Filters List!**")
async def invite(client, message): reply = message.reply_to_message if reply: user = reply.from_user["id"] else: user = get_arg(message) if not user: await message.edit("**I can't invite no-one, can I?**") return get_user = await app.get_users(user) try: await app.add_chat_members(message.chat.id, get_user.id) await message.edit(f"**Added {get_user.first_name} to the chat!**") except Exception as e: await message.edit(f"{e}")
async def help(client, message): args = get_arg(message) if not args: text = "**Available Commands**\n\n" for key, value in HELP.items(): text += f"{key}: {value}\n\n" await message.edit(text) return else: module_help = CMD_HELP.get(args, False) if not module_help: await message.edit("__Invalid module name specified.__") return else: await message.edit(module_help)
async def unban(_, message: Message): if await CheckAdmin(message) is True: reply = message.reply_to_message if reply: user = reply.from_user["id"] else: user = get_arg(message) if not user: await message.edit("**Whome should I unban?**") return try: get_user = await app.get_users(user) await app.unban_chat_member(chat_id=message.chat.id, user_id=get_user.id) await message.edit(f"{get_user.first_name} was unbanned.") except: await message.edit("I can't unban this user.")
async def save(client, message): arg = get_arg(message) if not arg: await message.edit("**You must give a name for a note.**") return note_name = arg note = await Zect.get_note(note_name) if note: await message.edit(f"**Note `{note_name}` already exists**") return reply = message.reply_to_message if not reply: await message.edit("Reply to a message to save a note") return copy = await app.copy_message(LOG_CHAT, message.chat.id, reply.message_id) await Zect.save_note(note_name, copy.message_id) await message.edit("**Note saved**")
async def unban(_, message: Message): if await CheckAdmin(message) is True: reply = message.reply_to_message if reply: user = reply.from_user["id"] else: user = get_arg(message) if not user: await message.edit("**I need someone to be unbanned here.**") return try: get_user = await app.get_users(user) await app.unban_chat_member(chat_id=message.chat.id, user_id=get_user.id) await message.edit(f"**Unbanned {get_user.first_name} from the chat.**") except: await message.edit("**I can't unban this user.**") else: await message.edit("**Am I an admin here?**")
async def mute_hammer(_, message: Message): if await CheckAdmin(message) is True: reply = message.reply_to_message if reply: user = reply.from_user["id"] else: user = get_arg(message) if not user: await message.edit("**Whome should I mute?**") return try: get_user = await app.get_users(user) await app.restrict_chat_member( chat_id=message.chat.id, user_id=get_user.id, permissions=mute_permission, ) await message.edit(f"{get_user.first_name} has been muted.") except: await message.edit("I can't mute this user.")
async def ban_hammer(_, message: Message): if await CheckAdmin(message) is True: reply = message.reply_to_message if reply: user = reply.from_user["id"] else: user = get_arg(message) if not user: await message.edit("**I can't ban no-one, can I?**") return try: get_user = await app.get_users(user) await app.kick_chat_member( chat_id=message.chat.id, user_id=get_user.id, ) await message.edit(f"Banned {get_user.first_name} from the chat.") except: await message.edit("**I can't ban this user.**") else: await message.edit("**Am I an admin here?**")
async def unmute(_, message: Message): if await CheckAdmin(message) is True: reply = message.reply_to_message if reply: user = reply.from_user["id"] else: user = get_arg(message) if not user: await message.edit("**Whome should I unmute?**") return try: get_user = await app.get_users(user) await app.restrict_chat_member( chat_id=message.chat.id, user_id=get_user.id, permissions=unmute_permissions, ) await message.edit(f"**{get_user.first_name} was unmuted.**") except: await message.edit("**I can't unmute this user.**") else: await message.edit("**Am I an admin here?**")
async def upstream(client, message): status = await message.edit("`Checking for updates, please wait....`") conf = get_arg(message) off_repo = UPSTREAM_REPO_URL try: txt = "`Oops.. Updater cannot continue due to " txt += "some problems occured`\n\n**LOGTRACE:**\n" repo = Repo() except NoSuchPathError as error: await status.edit(f"{txt}\n`directory {error} is not found`") repo.__del__() return except GitCommandError as error: await status.edit(f"{txt}\n`Early failure! {error}`") repo.__del__() return except InvalidGitRepositoryError as error: if conf != "now": pass repo = Repo.init() origin = repo.create_remote("upstream", off_repo) origin.fetch() repo.create_head("master", origin.refs.master) repo.heads.master.set_tracking_branch(origin.refs.master) repo.heads.master.checkout(True) ac_br = repo.active_branch.name if ac_br != "master": await status.edit( f"**[UPDATER]:**` You are on ({ac_br})\n Please change to master branch.`" ) repo.__del__() return try: repo.create_remote("upstream", off_repo) except BaseException: pass ups_rem = repo.remote("upstream") ups_rem.fetch(ac_br) changelog = await gen_chlog(repo, f"HEAD..upstream/{ac_br}") if "now" not in conf: if changelog: changelog_str = f"**New UPDATE available for [[{ac_br}]]({UPSTREAM_REPO_URL}/tree/{ac_br}):\n\nCHANGELOG**\n\n{changelog}" if len(changelog_str) > 4096: await status.edit( "`Changelog is too big, view the file to see it.`") file = open("output.txt", "w+") file.write(changelog_str) file.close() await app.send_document( message.chat.id, "output.txt", caption="Do `.update now` to update.", reply_to_message_id=status.message_id, ) remove("output.txt") else: return await status.edit( f"{changelog_str}\n\nDo `.update now` to update.", disable_web_page_preview=True, ) else: await status.edit( f"\n`Your BOT is` **up-to-date** `with` **[[{ac_br}]]({UPSTREAM_REPO_URL}/tree/{ac_br})**\n", disable_web_page_preview=True, ) repo.__del__() return if HEROKU_API is not None: import heroku3 heroku = heroku3.from_key(HEROKU_API) heroku_app = None heroku_applications = heroku.apps() if not HEROKU_APP_NAME: await status.edit( "`Please set up the HEROKU_APP_NAME variable to be able to update userbot.`" ) repo.__del__() return for app in heroku_applications: if app.name == HEROKU_APP_NAME: heroku_app = app break if heroku_app is None: await status.edit( f"{txt}\n`Invalid Heroku credentials for updating userbot dyno.`" ) repo.__del__() return await status.edit( "`Userbot dyno build in progress, please wait for it to complete.`" ) ups_rem.fetch(ac_br) repo.git.reset("--hard", "FETCH_HEAD") heroku_git_url = heroku_app.git_url.replace( "https://", "https://*****:*****@") if "heroku" in repo.remotes: remote = repo.remote("heroku") remote.set_url(heroku_git_url) else: remote = repo.create_remote("heroku", heroku_git_url) try: remote.push(refspec=f"HEAD:refs/heads/{ac_br}", force=True) except GitCommandError as error: pass await status.edit("`Successfully Updated!\nRestarting, please wait...`" ) else: # Classic Updater, pretty straightforward. try: ups_rem.pull(ac_br) except GitCommandError: repo.git.reset("--hard", "FETCH_HEAD") await updateme_requirements() await status.edit( "`Successfully Updated!\nBot is restarting... Wait for a second!`", ) # Spin a new instance of bot args = [sys.executable, "./resources/startup/deploy.sh"] execle(sys.executable, *args, environ) return