RenegadesBot.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. """
  2. running bot for renegades group
  3. """
  4. from time import sleep
  5. import telegram
  6. from telegram.error import NetworkError, Unauthorized
  7. import unicodedata
  8. from threading import Thread
  9. import sqlite3
  10. update_id = None
  11. token = ""
  12. class main():
  13. def runBot(self, bot):
  14. self.bot = bot
  15. try:
  16. update_id = self.bot.getUpdates()[0]['update_id']
  17. except IndexError:
  18. update_id = None
  19. print("last update_id {}".format(update_id))
  20. sleep(1)
  21. while True:
  22. try:
  23. for update in self.bot.getUpdates(offset=update_id, timeout=4):
  24. print("update > {}".format(update))
  25. update_id = update.update_id + 1
  26. try:
  27. thBot = Thread(target=cyBot,args=[bot,update])
  28. thBot.start()
  29. #cyBot(bot, update)
  30. except:
  31. pass
  32. sleep(0.4)
  33. except NetworkError:
  34. sleep(1)
  35. except Unauthorized:
  36. # The user has removed or blocked the bot.
  37. update_id += 1
  38. class misc():
  39. def isAdm(user_id, admin_list):
  40. for adm in admin_list:
  41. admid = adm.user.id
  42. if admid == user_id:
  43. return True
  44. return False
  45. def isArabic(first_name):
  46. for letter in first_name:
  47. try:
  48. encoding = unicodedata.name(letter).lower()
  49. if 'arabic' in encoding or 'persian' in encoding:
  50. return True
  51. except ValueError:
  52. pass
  53. return False
  54. def parserEntities(entities, post):
  55. titlechk = False
  56. urlchk = False
  57. title = ''
  58. url = ''
  59. hashtags = []
  60. for entity in entities:
  61. if entity.type == "hashtag":
  62. offset = entity.offset
  63. length = offset + entity.length
  64. hashtags.append(post[offset:length])
  65. elif entity.type == "bold" and not titlechk:
  66. titlechk = True
  67. offset = entity.offset
  68. length = offset + entity.length
  69. title = post[offset:length]
  70. elif entity.type == "url" and not urlchk:
  71. urlchk = True
  72. offset = entity.offset
  73. length = offset + entity.length
  74. url = post[offset:length]
  75. if not titlechk or not urlchk:
  76. return False
  77. response = {"hashtags": hashtags, "title": title, "url": url}
  78. return response
  79. class cyBot():
  80. allowed_chats = []
  81. allowed_channels = []
  82. mimetypes = ["application/pdf", "application/epub+zip", "application/x-mobipocket-ebook", "application/msword", "application/x-bittorrent", "text/plain", "application/x-rar-compressed", "application/zip", "application/x-7z-compressed"]
  83. misc = misc()
  84. log_channel = "-1001183412743"
  85. file_channel = "@cyfiles"
  86. replytomessage = False
  87. def __init__(self, bot, update):
  88. if update and update.message or update.callback_query:
  89. self.bot = bot
  90. self.update = update
  91. conn = sqlite3.connect('cyfiles.db')
  92. db = conn.cursor()
  93. try:
  94. self.chat_id = self.update.message.chat.id
  95. self.message_id = self.update.message.message_id
  96. except:
  97. pass
  98. else:
  99. return
  100. if self.update.message:
  101. if self.update.message.reply_to_message:
  102. self.replytomessage = True
  103. self.target_user_id = self.update.message.reply_to_message.from_user.id
  104. self.target_message_id = self.update.message.reply_to_message.message_id
  105. self.target_fname = self.update.message.reply_to_message.from_user.first_name
  106. self.target_username = update.message.reply_to_message.from_user.username
  107. if self.update.message.document:
  108. file_id = self.update.message.document.file_id
  109. file_name = self.update.message.document.file_name
  110. file_size = self.update.message.document.file_size
  111. file_mimetype = self.update.message.document.mime_type
  112. file_by = update.message.from_user.id
  113. # make backup of file
  114. if file_mimetype in self.mimetypes:
  115. file_data = "`{id}` -- *{name}*\n_{size}_ | {mimetype}\n\nby: `#id{uid}`".format(id=file_id,name=file_name,size=file_size,mimetype=file_mimetype,uid=file_by)
  116. try:
  117. db.execute('insert into files values ("", ?, ?, ?, ?, ?)', (file_id, file_name, file_size, file_mimetype, file_by))
  118. conn.commit()
  119. self.bot.sendDocument(chat_id=self.file_channel, caption=file_data, parse_mode="Markdown", document=file_id, disable_notification=1)
  120. except sqlite3.IntegrityError:
  121. conn.close()
  122. return
  123. if self.update.message.new_chat_members:
  124. for member in self.update.message.new_chat_members:
  125. if misc.isArabic(member.first_name):
  126. self.bot.kickChatMember(chat_id=self.chat_id, user_id=member.id)
  127. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, parse_mode="HTML", text="<b>[ban]</b> <i>allahu akabur!1!</i>")
  128. return
  129. fname = member.first_name.replace('_', '\_')
  130. log_nmember = "{fname}\n`#id{id}`\n\nIn: {ctitle}\n> [{fname}](tg://user?id={id})".format(fname=fname,id=member.id,ctitle=update.message.chat.id)
  131. self.bot.restrictChatMember(chat_id=self.chat_id, user_id=member.id, until_date=None, can_send_messages=0, can_send_media_messages=0, can_send_other_messages=0, can_add_web_page_previews=0)
  132. self.bot.sendMessage(chat_id=self.log_channel, parse_mode="Markdown", text=log_nmember)
  133. captcha = [
  134. [
  135. telegram.InlineKeyboardButton("ClickMe",callback_data=member.id)
  136. ]
  137. ]
  138. reply_markup = telegram.InlineKeyboardMarkup(captcha)
  139. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, parse_mode="Markdown", text="**welcome!\n[simple user verification]**", reply_markup=reply_markup)
  140. if self.update.callback_query:
  141. tgcll = Thread(self.tgCallback())
  142. tgcll.start()
  143. if self.update.message and self.update.message.chat.id in self.allowed_chats:
  144. tgmsg = Thread(self.tgMessage())
  145. tgmsg.start()
  146. def tgMessage(self):
  147. if not self.update.message.text:
  148. return
  149. backup_channel = "@pr1v8_board"
  150. admin_list = self.bot.getChatAdministrators(chat_id=self.chat_id)
  151. user_id = self.update.message.from_user.id
  152. user_fname = self.update.message.from_user.first_name
  153. sudo = misc.isAdm(user_id, admin_list)
  154. txt = self.update.message.text.split(" ")
  155. command = txt[0]
  156. remain_txt = ' '.join(txt[1:])
  157. query = True
  158. if not remain_txt:
  159. remain_txt = "-"
  160. query = False
  161. if command == "/getme":
  162. me = self.bot.getMe()
  163. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, text="@" + me.username)
  164. elif command == "/sudo" and sudo:
  165. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, text="hello root")
  166. elif command == "/free" and self.replytomessage and sudo:
  167. self.bot.restrictChatMember(chat_id=self.chat_id, user_id=self.target_user_id, until_date=None, can_send_messages=1, can_send_media_messages=1, can_send_other_messages=1, can_add_web_page_previews=1)
  168. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, parse_mode="Markdown", text="user liberado")
  169. elif command == "/link":
  170. link = self.bot.exportChatInviteLink(chat_id=self.chat_id)
  171. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, text=link)
  172. elif command == "/afk" or command == "/off":
  173. afk = "*user* [{fname}](tg://user?id={id}) *is afk*\n *> {reason}*".format(fname=user_fname,id=user_id,reason=remain_txt)
  174. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, parse_mode="Markdown", text=afk)
  175. elif command == "/back" or command == "/on":
  176. back = "*user* [{fname}](tg://user?id={id}) *is back*".format(fname=user_fname,id=user_id)
  177. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, parse_mode="Markdown", text=back)
  178. elif command == "/ban" and self.replytomessage and sudo:
  179. ban = "*user* [{fname}](tg://user?id={id}) *banned*".format(fname=self.target_fname,id=self.target_user_id)
  180. self.bot.kickChatMember(chat_id=self.chat_id, user_id=self.target_user_id)
  181. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, parse_mode="Markdown", text=ban)
  182. elif command == "/unban" and self.replytomessage and sudo:
  183. unban = "*user* [{fname}](tg://user?id={id}) *unbanned*".format(fname=self.target_fname,id=self.target_user_id)
  184. self.bot.unbanChatMember(chat_id=self.chat_id, user_id=self.target_user_id)
  185. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, parse_mode="Markdown", text=unban)
  186. elif command == "/mute" and self.replytomessage and sudo:
  187. mute = "*user* [{fname}](tg://user?id={id}) *muted*".format(fname=self.target_fname,id=self.target_user_id)
  188. self.bot.restrictChatMember(chat_id=self.chat_id, user_id=self.target_user_id, until_date=None, can_send_messages=0, can_send_media_messages=0, can_send_other_messages=0, can_add_web_page_previews=0)
  189. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, parse_mode="Markdown", text=mute)
  190. elif command == "/unmute" and self.replytomessage and sudo:
  191. unmute = "*user* [{fname}](tg://user?id={id}) *unmuted*".format(fname=self.target_fname,id=self.target_user_id)
  192. self.bot.restrictChatMember(chat_id=self.chat_id, user_id=self.target_user_id, until_date=None, can_send_messages=1, can_send_media_messages=1, can_send_other_messages=1, can_add_web_page_previews=1)
  193. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, parse_mode="Markdown", text=unmute)
  194. elif command == "/pin" and self.replytomessage and sudo:
  195. self.bot.pinChatMessage(chat_id=self.chat_id, message_id=self.target_message_id,disable_notification=1)
  196. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, parse_mode="Markdown", text="*message pinned*")
  197. elif command == "/uinfo" and self.replytomessage and sudo:
  198. uinfo = "*user info* | [{fname}](tg://user?id={id})\nname: {fname}\nid: `#id{id}`\nusername: @{username}".format(fname=self.target_fname,id=self.target_user_id,username=self.target_username)
  199. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, parse_mode="Markdown", text=uinfo)
  200. elif command == "/ginfo":
  201. gmember = self.bot.getChatMembersCount(chat_id=self.chat_id)
  202. ginfo = "*group info* | [{title}](tg://chat?id={id})\nTitle: {title}\nid: `{id}`\nMembers: {count}".format(title=self.update.message.chat.title,id=self.chat_id,count=gmember)
  203. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, parse_mode="Markdown", text=ginfo)
  204. elif command == "/sendfile" and sudo:
  205. if len(txt) != 2:
  206. return
  207. self.bot.sendDocument(chat_id=self.chat_id,reply_to_message_id=self.message_id,document=txt[1])
  208. elif command == "/save" and self.replytomessage and sudo:
  209. self.bot.forwardMessage(chat_id=self.backup_channel, from_chat_id=self.chat_id, message_id=self.target_message_id)
  210. elif command == "/cynet":
  211. links_list = [
  212. [
  213. telegram.InlineKeyboardButton("cyPunkrs",url="https://t.me/joinchat/DE9ViFBkvVx65PpKfvtuZg"),
  214. telegram.InlineKeyboardButton("R3neg4des",url="https://t.me/joinchat/DE9ViEUaKNz34rzPzqcjSA")
  215. ],
  216. [
  217. telegram.InlineKeyboardButton("Parisburn", url="https://t.me/parisburns"),
  218. telegram.InlineKeyboardButton("warezme",url="https://t.me/warezme")
  219. ],
  220. [
  221. telegram.InlineKeyboardButton("r/cyberpub", url="https://www.reddit.com/r/cyberpub/"),
  222. telegram.InlineKeyboardButton("Twitter", url="https://twitter.com/0xpr1v8")
  223. ],
  224. [
  225. telegram.InlineKeyboardButton("cyGithub", url="https://github.com/cyberpunkrs/")
  226. ]
  227. ]
  228. reply_markup = telegram.InlineKeyboardMarkup(links_list)
  229. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, text="**cyNetwork**", parse_mode="Markdown", reply_markup=reply_markup)
  230. elif command == "@adm":
  231. adms = ""
  232. for adm in admin_list:
  233. username = adm.user.username
  234. if not username:
  235. username = "null"
  236. else:
  237. username = "- @{}".format(username)
  238. adms += "<a href=\"tg://user?id={id}\">{fname}</a> {username}\n".format(fname=adm.user.first_name,id=adm.user.id,username=username)
  239. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, parse_mode="HTML", text=adms)
  240. elif command == "/rtfm":
  241. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, parse_mode="Markdown", text="**read the fucking manual**\nhttps://en.wikipedia.org/wiki/RTFM")
  242. elif command == "/w":
  243. who = [
  244. [
  245. telegram.InlineKeyboardButton("me",callback_data='w')
  246. ]
  247. ]
  248. reply_markup = telegram.InlineKeyboardMarkup(who)
  249. self.bot.sendMessage(chat_id=self.chat_id, reply_to_message_id=self.message_id, text="**Quem ta on fdps**", parse_mode="Markdown", reply_markup=reply_markup)
  250. def tgCallback(self):
  251. cid = self.update.callback_query.message.chat.id
  252. uid = str(self.update.callback_query.from_user.id)
  253. if self.update.callback_query.data == uid:
  254. self.bot.restrictChatMember(chat_id=cid, user_id=self.update.callback_query.from_user.id, until_date=None, can_send_messages=1, can_send_media_messages=1, can_send_other_messages=1, can_add_web_page_previews=1)
  255. self.bot.deleteMessage(chat_id=cid, message_id=self.update.callback_query.message.message_id)
  256. self.bot.sendMessage(chat_id=cid, reply_to_message_id=self.update.callback_query.message.reply_to_message.message_id, parse_mode="HTML", text="user <b>{}</b> free".format(self.update.callback_query.from_user.first_name))
  257. elif self.update.callback_query.data == 'w':
  258. self.bot.sendMessage(chat_id=cid, reply_to_message_id=self.update.callback_query.message.reply_to_message.message_id, parse_mode="Markdown", text=" {} present@".format(self.update.callback_query.from_user.first_name))
  259. if __name__ == '__main__':
  260. bot = main()
  261. btobj = telegram.Bot(token)
  262. bot.runBot(btobj)