Advertisement
Guest User

Untitled

a guest
Nov 11th, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.92 KB | None | 0 0
  1. import time
  2. import asyncio
  3. import string
  4. import sys
  5. import random
  6. import socket
  7. import pickle
  8. import os
  9. import datetime
  10. from random import randrange
  11. from random import randint
  12. from selenium import webdriver
  13. from selenium.webdriver.common.keys import Keys
  14. from selenium.webdriver.common.by import By
  15. from selenium.webdriver.support.ui import WebDriverWait
  16. from selenium.webdriver.support import expected_conditions as ec
  17. from selenium.webdriver.common.action_chains import ActionChains
  18.  
  19. # from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
  20.  
  21. # binary = FirefoxBinary("C:\\Program Files\\Light\\light.exe")
  22.  
  23. # get = os.listdir('C:\\Users\\Administrator\\AppData\\Roaming\\Light\\Light\\Profiles')
  24. # putanja = 'C:\\Users\\Administrator\\AppData\\Roaming\\Light\\Light\\Profiles\\' + get[0]
  25. options = webdriver.ChromeOptions()
  26. # options.add_argument("user-data-dir=C:\\Users\\Administrator\\AppData\\Local\\Google\\Chrome\\User Data")
  27. ua = "user-data-dir=C:\\Profiles\\" + str(sys.argv[1]) + "Parent"
  28. options.add_argument(ua)
  29. pd = "--profile-directory=" + str(sys.argv[1])
  30. options.add_argument(pd)
  31. # options.set_headless(headless=True)
  32. options.add_argument('window-size=1920x1080')
  33. options.add_argument('start-maximized')
  34. options.add_argument('log-level=3')
  35. # options.add_argument('--ignore-certificate-errors')
  36. # options.add_argument("--proxy-server='direct://'")
  37. # options.add_argument('--proxy-bypass-list=*')
  38. #PROXY = '190.2.140.41:37415'
  39. #options.add_argument('--proxy-server=%s' % PROXY)
  40. # options.add_argument('user-agent=Chrome/61.0.3163.79')
  41. print(ua)
  42. print(pd)
  43.  
  44. driver = webdriver.Chrome(executable_path="chromedriver.exe", chrome_options=options)
  45. # driver.set_window_size(1920, 1080)
  46. driver.get("https://discordapp.com/activity")
  47.  
  48. videle = "//video[@class='ready-36e6Vk']"
  49.  
  50. try:
  51. WebDriverWait(driver, 20).until(
  52. ec.presence_of_element_located((By.XPATH, videle)))
  53.  
  54. WebDriverWait(driver, 120).until_not(
  55. ec.presence_of_element_located((By.XPATH, videle)))
  56. except Exception as e:
  57. driver.get('https://discordapp.com/activity')
  58. time.sleep(5)
  59. # driver.implicitly_wait(5)
  60.  
  61. # gl = driver.find_elements_by_xpath("//div[@class='guildSeparator-1X4GQ1']/following-sibling::div[@class='guild-1EfMGQ']")
  62. # gl = driver.find_elements_by_class_name("guild-1EfMGQ")
  63. # loc = 60
  64. # print('CHeckujem guilde')
  65.  
  66. # home = gl[0]
  67.  
  68. # for guild in range(0,len(gl)-2):
  69. # last_height = driver.execute_script("return document.body.scrollHeight")
  70. # driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
  71. # driver.execute_script('arguments[0].scrollIntoView()', guild)
  72. ##driver.execute_script('arguments[0].scrollIntoView()', gl[guild])
  73. ##await asyncio.sleep(1)
  74. ##actions = ActionChains(driver)
  75. # actions.move_to_element(gl[guild]).click().perform()
  76. ##gl[guild].click()
  77. ##actions.perform(gl[guild])
  78. # await asyncio.sleep(1)
  79. ##driver.execute_script("arguments[0].click();", gl[guild])
  80. # gl[guild].send_keys(u'ue007')
  81. # condition = ec.visibility_of_element_located(gl[guild])
  82.  
  83. # fo = WebDriverWait(driver, 15).until(condition)
  84. # fo.click()
  85. # print('Usao u guildu')
  86. # await asyncio.sleep(10)
  87.  
  88. # driver.execute_script('arguments[0].scrollIntoView()', home)
  89. # actions.click(home).perform()
  90.  
  91. # actions = ActionChains(driver)
  92. # actions.move_to_element(home.click().perform())
  93. # driver.execute_script('arguments[0].scrollIntoView()', home)
  94. # await asyncio.sleep(1)
  95. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  96. try:
  97. PREFIX_FILE_PATH = 'C:\\BOT\\' + str(sys.argv[1])
  98. PREFIX_FILE_PATH_BF = 'C:\\BOT\\'
  99. PREFIX_FILE_PATH_PICKLE = 'Z:\\Shared\\pickles\\' + str(sys.argv[1])
  100.  
  101. breaker = False
  102. memberi = []
  103. max_number_members = 0
  104. next_member = 0
  105. servers_list_check = []
  106. data = 0
  107. cnt = 1
  108. userFile = open(PREFIX_FILE_PATH_BF + "accountConfig.txt", "r")
  109. logfile = open(PREFIX_FILE_PATH_BF + "LOG.txt", "w")
  110.  
  111.  
  112. configLoad = userFile.readlines()
  113. username = configLoad[0]
  114. password = configLoad[1]
  115. userFile.close()
  116. serverFile = open(PREFIX_FILE_PATH_BF + "serverProtocolConfig.txt", "r")
  117. serverLoad = serverFile.readlines()
  118. IPadress = serverLoad[0]
  119. portLoader = serverLoad[1]
  120. serverFile.close()
  121. messageSend = []
  122. host = IPadress
  123. port = int(portLoader)
  124. print('HOST : ', host)
  125. print('PORT : ', port)
  126.  
  127. oServersF = open(PREFIX_FILE_PATH_BF + "oservers.txt", "r")
  128. oServersX = oServersF.readlines()
  129. oServers = [x.replace("\n", "") for x in oServersX]
  130. cachedKicks = []
  131. kicksToPerform = []
  132.  
  133.  
  134. def mwconn(host, port):
  135. try:
  136. s.connect((host, port))
  137. except socket.error as exc:
  138. print('Caught exception socket.error:' + exc)
  139.  
  140.  
  141. mwconn(host, port)
  142.  
  143. iskoristi = False
  144.  
  145.  
  146. async def start_process():
  147. print('Startujem bota ')
  148. global iskoristi
  149. if iskoristi == False:
  150. iskoristi = True
  151. await start_bot()
  152.  
  153.  
  154. def init_client():
  155. global s
  156. sFileName = PREFIX_FILE_PATH_PICKLE + 'dict.pickle'
  157. messageConfigure = "GIVE_PICKLE"
  158. boolForSend = 0
  159. global messageSend
  160. while True:
  161. if boolForSend == 0:
  162. BUFFER_SIZE = 1024
  163. s.send(messageConfigure.encode())
  164. print('Poslao pickleFile request serveru')
  165. fDownloadFile = PREFIX_FILE_PATH_PICKLE + "dict.pickle"
  166. with open(fDownloadFile, 'wb') as fw:
  167. msg = s.recv(BUFFER_SIZE)
  168. fsize = int(msg.decode('utf-8').strip())
  169. rsize = 0
  170. while True:
  171. data = s.recv(BUFFER_SIZE)
  172. rsize = rsize + len(data)
  173. fw.write(data)
  174. if rsize >= fsize:
  175. break
  176. print("Zavrseno skidanje pickle-a")
  177. messageConfigure = 'GIVE_MESSAGE'
  178. sFileName = PREFIX_FILE_PATH + 'porukaZaSlanje.txt'
  179. boolForSend = boolForSend + 1
  180. time.sleep(0.1) # MORA ZBOG TPP
  181. continue # MORA ZBOG TPP extra layer
  182. if boolForSend == 1:
  183. s.send(messageConfigure.encode())
  184. print('Poslao messageFile request serveru')
  185. sData = s.recv(1024)
  186. fDownloadFile = open(sFileName, "wb")
  187. while sData:
  188. if 'done031337' in str(sData):
  189. break
  190. fDownloadFile.write(sData)
  191. sData = s.recv(1024)
  192. print("Zavrseno skidanje poruke")
  193. fDownloadFile.close()
  194. messageFile = open(PREFIX_FILE_PATH + "porukaZaSlanje.txt", "r")
  195. lineRead = messageFile.readlines()
  196. for line in lineRead:
  197. print('PORUKA : ', line, ' ZAVRSENO')
  198. messageSend.append(line)
  199. boolForSend = boolForSend + 1
  200. messageConfigure = 'GIVE_PICKLE2'
  201. messageFile.close()
  202. sFileName = PREFIX_FILE_PATH + 'serverMe8mbersConfig.txt'
  203. time.sleep(0.1)
  204. continue
  205. if boolForSend == 2:
  206. BUFFER_SIZE = 1024
  207. messageConfigure = 'GIVE_PICKLE2'
  208. s.send(messageConfigure.encode())
  209.  
  210. print('Poslao serverListFile request serveru')
  211. fDownloadFile = PREFIX_FILE_PATH + "remembServers.pickle"
  212. with open(fDownloadFile, 'wb') as fw:
  213. msg = s.recv(BUFFER_SIZE)
  214. fsize = int(msg.decode('utf-8').strip())
  215. rsize = 0
  216. while True:
  217. data = s.recv(BUFFER_SIZE)
  218. rsize = rsize + len(data)
  219. fw.write(data)
  220. if rsize >= fsize:
  221. break
  222. print("Zavrseno skidanje pickle-a 2")
  223. messageConfigure = 'GIVE_MESSAGE'
  224. sFileName = PREFIX_FILE_PATH + 'porukaZaSlanje.txt'
  225. boolForSend = boolForSend + 1
  226. time.sleep(0.1) # MORA ZBOG TPP
  227. continue # MORA ZBOG TPP extra layer
  228. if boolForSend == 3:
  229. print('LOGUJEM SE IN...')
  230. loop = asyncio.get_event_loop()
  231. loop.run_until_complete(start_process())
  232.  
  233. return
  234.  
  235.  
  236. def BMP(s):
  237. return "".join((i if ord(i) < 10000 else '\ufffd' for i in s))
  238.  
  239.  
  240. # @client.event
  241. # async def on_ready():
  242. # client.loop.create_task(start_bot())
  243.  
  244. def random_string(length):
  245. return ''.join(random.choice(string.ascii_letters) for m in range(1, length))
  246.  
  247.  
  248. def configure_message(message, length, idx):
  249. global messageSend
  250. message = messageSend[idx]
  251. message1 = ''
  252. message2 = ''
  253. messageo = message
  254. for i in range(1, randint(1, 30)):
  255. message2 += ' '
  256. messageo = messageo.replace('!!!', message2)
  257. # messageo = messageo.replace('/Gameplay', '/' + random_string(5))
  258. # messageo = messageo.replace('trailer.html', 'trailer/' + random_string(5))
  259. for i in range(1, randint(1, 50)):
  260. message1 += ' '
  261. return message + ' ' + message2
  262.  
  263.  
  264. check_flaw = 0
  265.  
  266.  
  267. async def start_bot():
  268. #pickle_in = open(PREFIX_FILE_PATH_PICKLE + "dict.pickle", "rb")
  269. #memberi_load = pickle.load(pickle_in) #
  270. serverListReader = open(PREFIX_FILE_PATH + "remembServers.pickle", "rb")
  271. loadListReader = pickle.load(serverListReader) #
  272. dict_remember = {}
  273. for passout in loadListReader:
  274. dict_remember[passout] = 0
  275. serverListReader.close()
  276. #pickle_in.close()
  277. #random_seed = []
  278. random_seed = [5, 1 , 1, 3 , 3, 4]
  279. global check_flaw1
  280. regularMESSAGE = 'GIVE_DATA'
  281. formatMESSAGE = ''
  282. global messageSend
  283. global s
  284. global cnt
  285. if len(messageSend[0]) < 6:
  286. formatMESSAGE = 'MALA PORUKA, GASIM SE'
  287. s.send(formatMESSAGE.encode())
  288. s.close()
  289. print('GASIM SE')
  290. print('Duzina poruke '+ str(len(messageSend)))
  291. sys.exit(0)
  292. while True:
  293. try:
  294.  
  295. rnd = randint(0, len(random_seed) - 1)
  296. print('PORUKA ZA SLANJE : ', messageSend[rnd])
  297.  
  298. # if cnt == 100:
  299. # driver.get('https://discordapp.com/activity')
  300. # await asyncio.sleep(2)
  301. try:
  302. WebDriverWait(driver, 20).until(
  303. ec.presence_of_element_located((By.XPATH, "//div[@class='guildSeparator-1X4GQ1']")))
  304. except Exception as e:
  305. s.close()
  306. sys.exit(1)
  307. #await asyncio.sleep(5)
  308. print('Nisam nasao GUILDe, gasim se')
  309. logfile.close()
  310. continue
  311.  
  312. gl = driver.find_elements_by_xpath(
  313. "//div[@class='guildSeparator-1X4GQ1']/following-sibling::div[contains(@class, 'guild-1EfMGQ')]/descendant::a")
  314.  
  315. cursrvs = []
  316.  
  317. for guild in gl:
  318. srvr = str(guild.get_attribute('aria-label'))
  319. cursrvs.append(srvr)
  320.  
  321. if len(cursrvs) < 2:
  322. await asyncio.sleep(5)
  323. print('Lista GUILDi je manja od 2, ranujem loop opet!')
  324. continue
  325.  
  326. for x in oServers:
  327. if x not in cursrvs:
  328. if x not in cachedKicks:
  329. print('Server ' + x + ' ne postoji u listi originalnih, DOBIO KICK')
  330. cachedKicks.append(x)
  331. kicksToPerform.append(x)
  332.  
  333. # perform pending kicks
  334. if len(kicksToPerform) > 0:
  335. por = 'LOSE ' + kicksToPerform.pop(0)
  336. s.send(por.encode())
  337. print('Poslao serveru pending kick')
  338. await asyncio.sleep(1)
  339. continue
  340.  
  341. s.send(regularMESSAGE.encode())
  342. print('Poslao REQ serveru')
  343. #await asyncio.sleep(1)
  344. data = s.recv(2048)
  345. if 'stop' in str(data):
  346. print('Stopirana sesija')
  347. break
  348. if 'napusti' in str(data):
  349. await asyncio.sleep((60 * 60) * 6)
  350. print('VRATIO SAM SE IZ OKIDANJA')
  351. if not data:
  352. await asyncio.sleep(5)
  353. continue
  354. next_member = str(data.decode('utf-8').strip())
  355. print('MEMBER DOBIJEN ', next_member)
  356. #random_index = randrange(len(random_seed))
  357. print('Dobio novi zadatak za izvrsavanje')
  358.  
  359. await asyncio.sleep(2)
  360.  
  361. bdy = driver.find_element_by_tag_name("body")
  362. bdyactions = ActionChains(driver)
  363. bdyactions.move_to_element(bdy).click().send_keys(Keys.ENTER).perform()
  364.  
  365. # try:
  366. # inputbox = WebDriverWait(driver, 20).until(
  367. # ec.presence_of_element_located((By.XPATH, "//input[@type='text']")))
  368. # print('Located input box.')
  369. # driver.execute_script('arguments[0].scrollIntoView(true)', inputbox)
  370. # except Exception as e:
  371. # print(str(e))
  372. # print('Couldnt find search box!')
  373. #
  374. # await asyncio.sleep(60 + randint(1, 13))
  375. # continue
  376.  
  377. await asyncio.sleep(10)
  378. res = driver.find_element_by_tag_name("body")
  379. ActionChains(driver).move_to_element(res).send_keys(Keys.CONTROL + 'k').perform()
  380. print('Otvaram Search Members...')
  381. await asyncio.sleep(3)
  382. ele = WebDriverWait(driver, 10).until(ec.presence_of_element_located((By.XPATH, "//input[@class='input-2VB9rf']")))
  383. driver.execute_script('arguments[0].scrollIntoView(true)', ele)
  384. #driver.execute_script('arguments[0].focus()', ele)
  385. ActionChains(driver).move_to_element(ele).click().perform()
  386. await asyncio.sleep(1)
  387. try:
  388. mname = str(next_member)
  389. firstPART = mname[:-5]
  390. secondPART = mname[len(mname) - 4:]
  391. ActionChains(driver).move_to_element(ele).perform()
  392. ele.send_keys('@')
  393. ele.send_keys('@')
  394. ActionChains(driver).move_to_element(ele).send_keys(firstPART).perform()
  395. await asyncio.sleep(3)
  396. ActionChains(driver).move_to_element(ele).send_keys('#' + secondPART).perform()
  397.  
  398. except Exception as e:
  399. formatMESSAGE = 'Poslao ' + str(cnt) + '. poruku memberu ' + BMP(mname) + '- u na serveru ' + ' FAILURE1 ' + datetime.datetime.now().strftime(
  400. '%Y-%m-%d %H:%M:%S')
  401. s.send(formatMESSAGE.encode())
  402. WebDriverWait(driver, 10).until(
  403. ec.presence_of_element_located((By.XPATH, "//a[@href='/activity']")))
  404. act = driver.find_element_by_xpath("//a[@href='/activity']")
  405. driver.execute_script('arguments[0].focus()', act)
  406. act.click()
  407. await asyncio.sleep(14 + randint(1, 8))
  408. #await asyncio.sleep(60 + randint(1, 13))
  409. continue
  410.  
  411. try:
  412. WebDriverWait(driver, 15).until(
  413. ec.presence_of_element_located((By.CSS_SELECTOR, ".resultFocused-3aIoYe")))
  414. ActionChains(driver).send_keys(Keys.ENTER).perform()
  415. await asyncio.sleep(3)
  416. WebDriverWait(driver, 10).until(ec.presence_of_element_located(
  417. (By.XPATH, "//textarea[@placeholder='Message @" + BMP(firstPART) + "']")))
  418. res3 = driver.find_element_by_xpath(
  419. "//textarea[@placeholder='Message @" + BMP(firstPART) + "']")
  420. res3.send_keys(configure_message(messageSend, 5, rnd))
  421. res3.send_keys(Keys.ENTER)
  422. cnt = cnt + 1
  423. if cnt >= 210:
  424. logfile.close()
  425. else:
  426. logfile.write(BMP(mname) + '\n')
  427. except Exception as e:
  428. print(str(e))
  429. ActionChains(driver).send_keys(Keys.ESCAPE).perform()
  430. await asyncio.sleep(2)
  431. ActionChains(driver).send_keys(Keys.ESCAPE).perform()
  432. form = 'Poslao ' + str(cnt) + '. poruku memberu ' + BMP(
  433. firstPART) + ' FAILURE ' + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  434. print('Nije moguce poslati poruku ', BMP(firstPART), ' greska = ', str(e),
  435. datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
  436. print('RAZLOG: Nisam nasao memebera u listi...')
  437. s.send(form.encode())
  438. #await asyncio.sleep(60 + randint(1, 13))
  439. #print('SPAVAM ', random_seed[rnd] * 60 + 4, ' sekundi')
  440. await asyncio.sleep(14 + randint(1, 8))
  441. continue
  442.  
  443. try:
  444. WebDriverWait(driver, 10).until(
  445. ec.presence_of_element_located((By.XPATH, "//a[@href='/activity']")))
  446. act = driver.find_element_by_xpath("//a[@href='/activity']")
  447. driver.execute_script('arguments[0].focus()', act)
  448. try:
  449. #print('Clicked activity 1st time')
  450. act.click()
  451. except Exception as e:
  452. #print('Clicked activity 2nd time')
  453. bu = driver.find_element_by_xpath("//a[@href='/activity']")
  454. bu.click()
  455. except Exception as e:
  456. print(str(e))
  457.  
  458. print('Poslao ', cnt, '. poruku memberu ', BMP(firstPART), ' ', datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
  459. formatMESSAGE = 'Poslao ' + str(cnt) + '. poruku memberu ' + BMP(
  460. BMP(firstPART)) + ' ' + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  461. s.send(formatMESSAGE.encode())
  462. await asyncio.sleep(14 + randint(1, 8))
  463.  
  464. # if cnt % (48) == 0: #prosti
  465. # await asyncio.sleep(970 + randint(1, 5))
  466. # else:
  467. #await asyncio.sleep(60 + randint(1, 13))
  468. except Exception as e:
  469. porukaLOG = 'Nije moguce poslati poruku ' + BMP(firstPART) + ' greska = ' + str(
  470. e) + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
  471. print('Nije moguce poslati poruku ', BMP(firstPART+secondPART), ' greska = ', str(e),
  472. datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
  473. s.send(porukaLOG.encode())
  474. await asyncio.sleep(14 + randint(1, 8))
  475. #await asyncio.sleep(60 + randint(1, 13))
  476.  
  477. print('Bot zavrsio sa radom')
  478. s.close()
  479. sys.exit(0)
  480.  
  481.  
  482. init_client()
  483. except Exception as e:
  484. s.close()
  485. print(str(e))
  486. print('GASIM SE1')
  487. sys.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement