def mute(update, context): m = extract.sudocheck(update, context) if m == 2: return elif m == 1: n = extract.sudocheck(update, context, 0) if n == 0: update.message.reply_text( "I'm afraid I can't stop an owner from speaking...") return elif n == 1: update.message.reply_text( "Dang ! I can't hold back an admin from speaking !") return msg = update.message.reply_to_message res = update.message.text.split(None, 1) user_id = msg.from_user.id chat_id = update.effective_chat.id user_name = msg.from_user.username first_name = msg.from_user.first_name current = eval(str(context.bot.getChat(chat_id).permissions)) new = { 'can_send_messages': False, 'can_send_media_messages': False, 'can_send_polls': False, 'can_send_other_messages': False, 'can_add_web_page_previews': False, 'can_invite_users': False } permissions = { 'can_send_messages': None, 'can_send_media_messages': None, 'can_send_polls': None, 'can_send_other_messages': None, 'can_add_web_page_previews': None, 'can_change_info': None, 'can_pin_messages': None } permissions.update(current) permissions.update(new) new_permissions = telegram.ChatPermissions(**permissions) context.bot.restrict_chat_member(chat_id, user_id, permissions=new_permissions) update.message.reply_text("Muted " + str(first_name) + " !")
def cus_bio(update, context): m = extract.sudocheck(update, context) if m == 2: return msg = update.message.reply_to_message chat_id = str(update.effective_chat.id) chat_id = chat_id[1:] user_id = msg.from_user.id res = update.message.text.split(None, 1) r = "" try: r = res[1] if res == None: return except: return # udat(update,context) k = push_link(chat_id=chat_id, user_id=user_id, bio=r) if k == 1: name = msg.from_user.first_name txt = ("Set " + "(<a href='tg://user?id=" + str(user_id) + "'>" + str(name) + "</a>) group <b>bio</b> as -\n\n<i>" + r + "</i>") update.message.reply_text(text=txt, parse_mode="HTML")
def rules(update, context): res = update.message.text.split(None, 1) r = "" chat_id = str(update.effective_chat.id) chat_idd = chat_id[1:] if res[0] == "/start": chat_idd = res[1] chat_idd = chat_idd[1:] k = "" k = get_chat(chat_id=chat_idd, rules=r) try: k = k[0][0] except: k = "Error" update.message.reply_text( text=k, parse_mode="HTML", disable_web_page_preview=True) return if res[0] == "/rules" or res[0] == ("/rules@"+bot_username): k = get_chat(chat_id=chat_idd, rules=r) try: k = k[0][0] except: k = "Error" #k = "<a href='t.me/jesvi_bot?start=" + chat_id + "'>Click Here</a>" + " to view the group's rules" k = get_chat(chat_id=chat_idd, rules=r) try: k = k[0][0] except: k = "No rules set in this group !" update.message.reply_text( text=k, parse_mode="HTML", disable_web_page_preview=True) return else: m = extract.sudocheck(update, context) if m == 2: return try: r = res[1] if res == None: return except: return k = push_chat(chat_id=chat_idd, rules=r) if k == 1: txt = ("Set group rules as - \n\n" + "<i>" + r + "</i>") update.message.reply_text(text=txt, parse_mode="HTML")
def unlock(update, context): m = extract.sudocheck(update, context, 1, 1) if m == 2 or m == 1: return global lock lock = 0 update.message.reply_text("Unlocked !")
def silent_delete(update, context): m = extract.sudocheck(update, context) if m == 2: return msg_frm = update.message msg = msg_frm.reply_to_message.delete() msg_frm.delete()
def lock(update, context): m = extract.sudocheck(update, context, 1, 1) if m == 2: return if m == 1: return global lock lock = 1 update.message.reply_text("Locked !")
def unpin(update, context): m = extract.sudocheck(update, context) if m == 2: return chat_id = update.effective_chat.id try: context.bot.unpinChatMessage(chat_id) except: pass
def oof(update, context): m = extract.sudocheck(update, context, 1) oof = "oof" msg = update.message.reply_text(text=oof) if m == 2: return for i in range(0, 3): oof = "o" + oof msg.edit_text(text=oof)
def silent_delete(update, context): m = extract.sudocheck(update, context) if m == 2: return msg = update.message.reply_to_message msg_frm = update.message msg_id = msg.message_id chat_id = update.effective_chat.id msg_frm.delete() context.bot.deleteMessage(chat_id, msg_id)
def delete(update, context): m = extract.sudocheck(update, context) if m == 2: return msg_frm = update.message msg = msg_frm.reply_to_message msg.delete() del_msg = update.message.reply_text("Deleted !") time.sleep(1) msg_frm.delete() del_msg.delete()
def pin(update, context): m = extract.sudocheck(update, context) if m == 2: return msg = update.effective_message.reply_to_message chat_id = update.effective_chat.id notify = True msg_id = None try: msg_id = msg.message_id except: return context.bot.pinChatMessage(chat_id, msg_id)
def clean(update, context): m = extract.sudocheck(update, context) if m == 2: return msg = update.message.reply_to_message del_msg = update.message.reply_text("Cleaning started...") msg_id = int(msg.message_id) chat_id = update.effective_chat.id del_msg_id = int(del_msg.message_id) t = 1 while t == 1: if msg_id == del_msg_id: t = 0 try: context.bot.deleteMessage(chat_id, del_msg_id) except: pass del_msg_id = del_msg_id-1 """ if msg_id >= del_msg_id: t = 0 try: context.bot.deleteMessage(chat_id, msg_id) except: pass msg_id=msg_id+1 """ cln = context.bot.send_message(chat_id, "Cleaned !") time.sleep(3) cln.delete()
def net(update, context): m = extract.sudocheck(update, context) if m == 2: return msg = update.message.reply_text(text="<code>" + "Connecting..." + "</code>", parse_mode="HTML") st = speedtest.Speedtest(secure=True) msg.edit_text(text="<code>" + "Checking download speed..." + "</code>", parse_mode="HTML") st.download() megabyte = 1./1000000 d = st.results.download d = megabyte * d d = round(d, 2) ds = "Download Speed : " + str(d) + " mb/s" msg.edit_text(text=("<code>" + ds + "\n\nChecking upload speed..." + "</code>"), parse_mode="HTML") st.upload() u = st.results.upload u = megabyte * u u = round(u, 2) us = "\nUpload Speed : " + str(u) + " mb/s" servernames = [] msg.edit_text(text=("<code>" + ds + us + "\n\nMeasuring ping..." + "</code>"), parse_mode="HTML") st.get_servers(servernames) p = str(st.results.ping) ps = "\nPing : " + p + "ms" msg.edit_text(text=("<code>" + "Test Time : " + time.strftime("%Y-%m-%d (%H:%M:%S)") + "\n\n" + ds + us + ps + "</code>"), parse_mode="HTML")
def spam_check(update, context): global spam global spam_text global spam_type global spam_user msg = update.message.reply_to_message m = extract.sudocheck(update, context) if m == 2: return try: res = update.message.text.split(None, 3) except: pass try: text_1 = res[1] except: text_1 = "" pass try: text_2 = res[2] except: text_2 = "" pass try: user_name = msg.from_user.username res = update.message.text.split(None, 1) if text_1 == "": update.message.reply_text("No Spam Text Provided !") return if text_1 == "stop" or text_1 == "off" or text_1 == "halt": del spam_user[user_name] update.message.reply_text("Halted spamming " + user_name + " !") return spam_user[user_name] = text_1 text = "Spam stormming " + user_name + \ " with '" + str(spam_user[user_name]) + "' !" update.message.reply_text(text) return except: pass if text_1.startswith("@") == True: if text_2 == "": update.message.reply_text("No Spam Text Provided !") return shrt = text_1[1:] if text_2 == "stop": del spam_user[shrt] update.message.reply_text("Halted spamming " + text_1 + " !") return spam_user[shrt] = text_2 text = "Spam stormming " + text_1 + \ " with '" + str(spam_user[shrt]) + "' !" update.message.reply_text(text) return ######################################################## text = "" temp = '' if text_1 == "": b = "off" temp = spam_text if spam == 1: b = "on" if spam_text == "": temp = "Not Set !" text = "Spam currently : " + b + "\nSpam mode : " + \ spam_type + "\nSpam text : " + temp update.message.reply_text(text) return if text_1 == "on": spam = 1 temp = " !" if spam_text == "": temp = ', spam text not asigned !' text = "Spam mode turned on" + temp elif text_1 == "off": spam = 0 text = "Spam mode turned off !" elif text_1 == "overflow": spam_type = "overflow" elif text_1 == "echo": spam_type = "echo" text = "Spam switched to 'echo' mode !" elif text_1 == "echo_overflow": spam_type = "echo_overflow" elif text_1 == "reply": spam_type = "reply" if spam_text != "": temp = '& "' + spam_text + '" set as spam text !' else: temp = '& spam text not asigned !' text = "Spam switched to 'reply' mode " + temp elif text_1 == "reply_overflow": spam_text = "reply_overflow" if text_2 != "": spam_text = text_2 else: spam_text = text_1 text = "'" + spam_text + "' set as spam text !" update.message.reply_text(text)
def set_(update, context): res = update.message.text.split(None, 2) if res[0] == "/bio": pass else: m = extract.sudocheck(update, context) if m == 2: return elif m == 1: n = extract.sudocheck(update, context, 0) if n == 0: update.message.reply_text("He got his own title boii !") return chat_id = chat_idd = "" try: chat_id = str(update.effective_chat.id) chat_idd = chat_id[1:] #user_id = update.effective_chat.username msg = update.message.reply_to_message user_id = msg.from_user.id except: return if res[0] == "/bio" or res[0] == "/about": k = get_link(chat_id=chat_idd, user_id=user_id, bio=1) name = msg.from_user.first_name d = "" try: txt = ("<b>Bio</b> - " + "<a href='tg://user?id=" + str(user_id) + "'>" + str(name) + "</a>" + "\n\n<i>" + str(k[0][1]) + "</i>") except: txt = "<b>No Bio set</b> for " + "<a href='tg://user?id=" + \ str(user_id) + "'>" + str(name) + "</a> !" update.message.reply_text(text=txt, parse_mode="HTML") return elif res[0] == "/setbio": cus_bio(update, context) return prev_message = update.message.reply_to_message if res[1] == "chatname" or res[1] == "name" or res[1] == "groupname" or res[1] == "grouptitle" or res[1] == "chattitle" or res[1] == "gname": try: context.bot.set_chat_title(chat_id=chat_id, title=res[2]) text = "Chat name changed to '" + res[2] + "' !" update.message.reply_text(text) except: pass elif res[1] == "commands": context.bot.send_message(chat_id, text='Added Command !') elif res[1] == "des" or res[1] == "desc" or res[1] == "description": try: t = prev_message.tepxt context.bot.set_chat_description(chat_id, prev_message.text) context.bot.send_message( chat_id, text='Chat descirption updated !') except: if res[2] != None or res[2] != "": context.bot.set_chat_description(chat_id, res[2]) context.bot.send_message( chat_id, text='Chat descirption updated !') else: return elif res[1] == "nick" or res[1] == "title" or res[1] == "uname" or res[1] == "nickname" or res[1] == "admintitle" or res[1] == "status": try: msg = update.message.reply_to_message chat_id = update.effective_chat.id user_id = msg.from_user.id update.effective_chat.set_administrator_custom_title( user_id=user_id, custom_title=res[2]) user_name = msg.from_user.username text = '"' + res[2]+'" set as the custom title for @' + user_name update.message.reply_text(text) except: pass
def warn_strike(update, context): database.create_settings_base() m = extract.sudocheck(update, context) if m == 2: return else: n = extract.sudocheck(update, context, objective=0, udel=0) if n == 0: update.message.reply_text("Try /rip instead...") return elif n == 1: update.message.reply_text("Can't warn an Admin !") return reason = "~" try: res = update.message.text.split(None, 1) reason = res[1] except: pass msg = update.message.reply_to_message warn_user_id = str(msg.from_user.id) warn_by_user_id = str(update.message.from_user.id) msg_id = msg.message_id chat = msg['chat'] chat_idd = chat.id chat_id = re.sub(r'[^\w]', '', str(chat_idd)) database.create_warn_base() rem = database.add_warn_base_2(chat_id=chat_id, user_id=warn_user_id, striked_by=warn_by_user_id, message_id=msg_id, reason=reason, remove=0) sett = database.add_settings_base(chat_id=chat_id) text = "" warn_lim = sett[0][0] action = sett[0][1] a = 0 if int(rem) >= int(warn_lim): text = ("<a href='tg://user?id=" + str(warn_user_id) + "'>" + msg.from_user.first_name + "</a>" + " has been warn struck by " + "<a href='tg://user?id=" + str(update.message.from_user.id) + "'>" + str(update.message.from_user.first_name) + "</a> !" "\n\nReason : '<i><a href='https://telegram.me/" + chat.username + "/" + str(msg_id) + "'>" + reason + "</a></i>'" + "\nStrikes : <b>" + rem + "/" + warn_lim + "</b> " + "\n\n<b>Limit Reached !</b>" + " (Action : <b>" + action + "</b>)") a = 1 else: text = ("<a href='tg://user?id=" + str(warn_user_id) + "'>" + msg.from_user.first_name + "</a>" + " has been warn struck by " + "<a href='tg://user?id=" + str(update.message.from_user.id) + "'>" + str(update.message.from_user.first_name) + "</a> !" "\n\nReason : '<i><a href='https://telegram.me/" + chat.username + "/" + str(msg_id) + "'>" + reason + "</a></i>'" + "\nStrikes : <b>" + rem + "/" + warn_lim + "</b> " + "\n\n<b>" + warn_lim + " of " + warn_lim + "</b>" + " strikes result in <b>" + sett[0][1] + "</b>, So watch out !") if a == 1: i = "" if action == "mute": current = eval(str(context.bot.getChat(chat_idd).permissions)) new = { 'can_send_messages': False, 'can_send_media_messages': False, 'can_send_polls': False, 'can_send_other_messages': False, 'can_add_web_page_previews': False, } permissions = { 'can_send_messages': None, 'can_send_media_messages': None, 'can_send_polls': None, 'can_send_other_messages': None, 'can_add_web_page_previews': None, 'can_change_info': None, 'can_invite_users': None, 'can_pin_messages': None } permissions.update(current) permissions.update(new) new_permissions = telegram.ChatPermissions(**permissions) context.bot.restrict_chat_member(chat_idd, warn_user_id, permissions=new_permissions) i = "<a href='tg://user?id=" + str( warn_user_id ) + "'>" + msg.from_user.first_name + "</a>" + " has been <b>Muted</b> !" pass elif action == "kick": kick = update.effective_chat.unban_member(warn_user_id) #i = "<a href='tg://user?id=" + str(warn_user_id) + "'>" + msg.from_user.first_name +"</a>" + " has been <b>Kicked</b> !" elif action == "ban": ban = update.effective_chat.kick_member(warn_user_id) i = "<a href='tg://user?id=" + str( warn_user_id ) + "'>" + msg.from_user.first_name + "</a>" + " has been <b>Banned</b> !" context.bot.send_message(chat_id=chat_idd, text=i, parse_mode="HTML") update.message.reply_text(text=text, parse_mode="HTML", disable_web_page_preview=True)
def warn_set(update, context, cl=0, re=0): database.create_settings_base() m = extract.sudocheck(update, context) if m == 2: return res = update.message.text.split(None, 2) chat_id = str(update.effective_chat.id) chat_idd = chat_id[1:] if res[0] == "/warnclear" or res[0] == "/withdraw": msg = update.message.reply_to_message warn_user_id = str(msg.from_user.id) k = database.warn_clear(chat_id=str(chat_idd), user_id=warn_user_id, reset=0) if k == 1: update.message.reply_text( text="Last warn strike on " + "<a href='tg://user?id=" + str(warn_user_id) + "'>" + msg.from_user.first_name + "</a>" + " has been <b>removed</b> !", parse_mode="HTML", disable_web_page_preview=True) return elif res[0] == "/warnreset" or res[0] == "/forgive": msg = update.message.reply_to_message warn_user_id = str(msg.from_user.id) k = database.warn_clear(chat_id=str(chat_idd), user_id=warn_user_id, reset=1) if k == 1: update.message.reply_text( text="Warn log has been <b>reset</b> for " + "<a href='tg://user?id=" + str(warn_user_id) + "'>" + msg.from_user.first_name + "</a>" + " !", parse_mode="HTML", disable_web_page_preview=True) return elif res[0] == "/warninfo": msg = update.message.reply_to_message warn_user_id = str(msg.from_user.id) inf = database.warninfo(chat_id=chat_idd, user_id=warn_user_id) c = 1 tt = tx = "Warn Info - <b><a href='tg://user?id=" + str( warn_user_id) + "'>" + msg.from_user.first_name + "</a></b>\n" for i in inf: warn_no = "\nWarn streak : " + str(c) warn_by = "\nWarned by : <b><a href='tg://user?id=" + str( i[0]) + "'>User</a></b>" reason = "\nReason : <b><i><a href='https://telegram.me/" + update.effective_chat.username + "/" + i[ 1] + "'>" + i[2] + "</a></i></b>" date = "\nDate : <i>" + str(i[3]) + "</i>\n" tx = tx + warn_no + warn_by + reason + date c += c if tx == None or tx == tt: tx = tx + "\n<i>Clean as a whistle !</i>" update.message.reply_text(text=tx, parse_mode="HTML", disable_web_page_preview=True) return elif res[0] == "/warnlist": inf = database.warninfo(chat_id=chat_idd) c = 1 cha = "" try: cha = "@" + str(update.effective_chat.username) if cha == "@None": cha = "" except: pass tx = "Warn list - " + cha + "\n" tt = tx for i in inf: no = "\n" + str(c) + " - " total_strike = "(Strikes : <b>" + str(i[1]) + "</b>) - " user = "******" + str( i[0]) + "'>" + i[0] + "</a></b>" tx = tx + no + total_strike + user c += c if tt == tx: tx = tx + "\n<i>No records in this chat !</i>" context.bot.send_message(chat_id=chat_id, text=tx, parse_mode="HTML") return if res[1] == "limit": try: if res[2] == None or isinstance(int(res[2]), int) == False: return except: return sett = database.add_settings_base(chat_id=chat_idd, warn_limit=res[2]) update.message.reply_text(text="Warn limit set to <b>" + res[2] + "</b> !", parse_mode="HTML", disable_web_page_preview=True) elif res[1] == "action": try: if res[2] == "kick" or res[2] == "mute" or res[2] == "ban": sett = database.add_settings_base(chat_id=chat_idd, warn_action=res[2]) update.message.reply_text(text="Warn action set to <b>" + res[2] + "</b> !", parse_mode="HTML", disable_web_page_preview=True) else: return except: return else: return
def message_filter(update, context): m = extract.sudocheck(update, context) if m == 2: return global msg_filter global filter_text try: chat_id = update.effective_chat.id except: return res = update.message.text.split(None, 3) text_3 = text = "" if res[0] == '/filterreset' or res[0] == "/resetfilter": chat_idd = str(chat_id)[1:] user_id = str(update.message.from_user.id) k = database.push_filter(chat_id=chat_idd, pop=2) text = "Reset filter data" update.message.reply_text(text) return try: text_1 = res[1] except: if msg_filter == 1: bo = "on" else: bo = "off" text = ("Currently filter is " + str(bo) + " !") update.message.reply_text(text) return try: text_2 = res[2] except: text_2 = "" if text_1 == 'off' or text_1 == "on": msg_filter = 0 text = 'Filter turned off !' elif text_1 == 'remove': if text_2 != "": chat_idd = str(chat_id)[1:] user_id = str(update.message.from_user.id) k = database.push_filter(chat_id=chat_idd, filterr=text_2, pop=1) text = 'Removed "' + str(text_2) + '" from filter !' elif text_1 == 'warn' or text_1 == "delete" or text_1 == "reply": if text_2 == "": text = "No filter-warn word passed !" else: if text_1 == "reply": try: text_3 = res[3] except: return chat_idd = str(chat_id)[1:] user_id = str(update.message.from_user.id) k = database.push_filter(chat_id=chat_idd, filterr=text_2, action=text_1, set_by=user_id, replyt=text_3) text = 'Use of "' + str(text_2) + '" will - the user !' elif text_1 == 'list': k = database.get_filter(chat_id=chat_idd, filterr=None, al=1) text = "Here is a list of filters stored :\n" else: chat_idd = str(chat_id)[1:] user_id = str(update.message.from_user.id) database.push_filter(chat_id=chat_idd, filterr=text_1, set_by=user_id, res=1) text = 'Added "' + str(text_1) + '" to filter !' update.message.reply_text(text)
def notes(update, context): global notes_data msg = update.message res = update.message.text.split(None, 3) chat_id = update.effective_chat.id text_1 = text_3 = text = "" try: text_1 = res[1] except: try: chat_idd = str(chat_id)[1:] user_id = str(msg.from_user.id) u = get_note(chat_id=chat_idd, all_name=1) if u == -1: raise text = "Available notes -\n\n" for i in u: text = text + "• <code>" + i[0] + "</code>\n" text = text + "\nUse #notename to view the note" update.message.reply_text(text=text, parse_mode="HTML", disable_web_page_preview=True) return except: update.message.reply_text(text="Notes not available..", parse_mode="HTML", disable_web_page_preview=True) return try: text_2 = res[2] except: text_2 = "" m = extract.sudocheck(update, context) if m == 2: return # ss if text_1 == 'remove': if text_2 != "": chat_idd = str(chat_id)[1:] user_id = str(msg.from_user.id) u = push_note(chat_id=chat_idd, note_name=text_2, pop=1) if u == 1: text = "Note #" + text_2 + " deleted !" elif u == -2: text = "Noet #" + text_2 + " does not exist !" else: text = "Error !" elif text_1 == 'set': try: text_2 = res[2] except: update.message.reply_text("Note Name & Content not provided !") return try: text_3 = res[3] except: update.message.reply_text("Note content not provided !") return chat_idd = str(chat_id) chat_idd = chat_idd[1:] user_id = str(msg.from_user.id) push_note(chat_id=chat_idd, note_name=text_2, note=text_3, set_by=user_id) text = 'Note #' + str(text_2) + ' - \n"' + str(text_3) + '"' else: text = "Wrong format !" update.message.reply_text(text)
def rules(update, context): res = update.message.text.split(None, 1) r = "" chat_id = str(update.effective_chat.id) chat_idd = chat_id[1:] if res[0] == "/start": chat_idd = res[1] chat_idd = chat_idd[1:] k = "" k = get_chat(chat_id=chat_idd, rules=None) try: # uncomment the below line and comment the other lines after changing rules=r in k = get_chat_base values # k = k[0][0] try: k = "Group Rules ( " + "<a href='telegram.me/" + \ k[0][1] + "'>" + k[0][2] + "</a> ) -\n\n" + k[0][6] except: try: k = "Group rules ( " + k[0][2] + " ) -\n\n" + k[0][6] except: k = "Group rules ( " + k[0][0] + " ) - \n\n" + k[0][6] except: k = "Error" update.message.reply_text(text=k, parse_mode="HTML", disable_web_page_preview=True) return if res[0] == "/rules" or res[0] == ("/rules@" + bot_username): k = get_chat(chat_id=chat_idd, rules=r) try: k = k[0][0] # comment the below line code to change to type 2 rule method k = ("<a href='t.me/jesvi_bot?start=" + chat_id + "'>Click Here</a>" + " to view the group's rules") except: k = "No rules set in this group !" update.message.reply_text(text=k, parse_mode="HTML", disable_web_page_preview=True) return elif res[0] == "/rule": k = get_chat(chat_id=chat_idd, rules=r) try: k = k[0][0] except: k = "No rules set in this group !" update.message.reply_text(text=k, parse_mode="HTML", disable_web_page_preview=True) return else: m = extract.sudocheck(update, context) if m == 2: return try: r = res[1] if res == None: return except: return k = push_chat(chat_id=chat_idd, rules=r) if k == 1: txt = ("Set group rules as - \n\n" + "<i>" + r + "</i>") update.message.reply_text(text=txt, parse_mode="HTML")