Advertisement
Metal079

Untitled

May 29th, 2017
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. import time
  2. import pyautogui
  3. try:
  4. import Image
  5. except ImportError:
  6. from PIL import Image
  7. import pytesseract
  8.  
  9. pytesseract.pytesseract.tesseract_cmd = 'C:\\Program Files (x86)\\Tesseract-OCR\\tesseract' #Needs to be here for tesseract to work for whatever reason
  10.  
  11.  
  12. def main():
  13. while True:
  14. find_notification()
  15. name_coords, reply_coords, text_coords = set_message_coords()
  16. option = read_message(text_coords)
  17. player_id(name_coords, option)
  18. answer = response(option)
  19. reply(reply_coords, answer)
  20.  
  21.  
  22. def find_notification(): #looks for a waiting PM and clicks it
  23. while True:
  24. image = pyautogui.locateCenterOnScreen('test.png', grayscale = False, confidence = .9)
  25. print(image)
  26. if image is not None:
  27. print('Found a waiting message')
  28. pyautogui.click(image)
  29. time.sleep(.1)
  30. break
  31.  
  32.  
  33. def set_message_coords(): # Creates coords for message box and screenshots name
  34. try:
  35. imagex, imagey = pyautogui.locateCenterOnScreen('upper_right_message_corner.png', grayscale = True, confidence = .8)
  36.  
  37. except:
  38. print('ERROR I SHOULD BE FINDING "upper_right_message_corner.PNG" EXITING PROGRAM')
  39. exit()
  40. name_coords = (imagex - 390), imagey, 378, 50 # The coords of where the players name would be
  41. print('Found an open message')
  42. print(imagex, imagey)
  43.  
  44. reply_coords = (imagex - 251), (imagey + 255 ) # Coords of the reply button
  45. text_coords = (imagex - 461), (imagey + 45), 430, 45 # Coords of where a players possible response is
  46. return name_coords, reply_coords, text_coords # Returns all coord values to be used by other functions
  47.  
  48.  
  49. def player_id(name_coords, option): # Indentifies person who messaged and depending on if this person has messaged before changes response
  50. players = {} # Used to store players names and where in the response is
  51. keys = players.keys()
  52.  
  53. image = pyautogui.screenshot('name_test.png', region = name_coords) # Names are screenshots
  54. name_image = str(pytesseract.image_to_string(Image.open('name_test.png')))
  55. print(name_image)
  56. if name_image in keys:
  57. print("User is previous user.")
  58. if players[name_image] == None:
  59. players[name_image] = option
  60. else:
  61. players[name_image] = players[name_image] + option
  62. return players[name_image]
  63. else:
  64. print("User was not previously found, adding to dictionary.")
  65. players[name_image] = None
  66. print(players.keys())
  67. print(players)
  68.  
  69.  
  70. def reply(reply_coords, response): #Replies to PM
  71. pyautogui.click(reply_coords)
  72. print(response)
  73. pyautogui.typewrite(response)
  74. pyautogui.press('enter')
  75. print('Replying...')
  76.  
  77.  
  78. def read_message(text_coords): # Reads PM for numbers and sets option the number
  79. if pyautogui.locateCenterOnScreen('1.png',region = text_coords, confidence = .9, grayscale = True):
  80. option = '1'
  81. print('Player messaged 1')
  82. elif pyautogui.locateCenterOnScreen('2.png',region = text_coords, confidence = .9, grayscale = True):
  83. option = '2'
  84. print('Player messaged 2')
  85. elif pyautogui.locateCenterOnScreen('3.png',region = text_coords, confidence = .9, grayscale = True):
  86. option = '3'
  87. print('Player messaged 3')
  88. elif pyautogui.locateCenterOnScreen('4.png',region = text_coords, confidence = .9, grayscale = True):
  89. option = '4'
  90. print('Player messaged 4')
  91. elif pyautogui.locateCenterOnScreen('5.png',region = text_coords, confidence = .9, grayscale = True):
  92. option = '5'
  93. print('Player messaged 5')
  94. elif pyautogui.locateCenterOnScreen('6.png',region = text_coords, confidence = .9, grayscale = True):
  95. option = '6'
  96. print('Player messaged 6')
  97. elif pyautogui.locateCenterOnScreen('7.png',region = text_coords, confidence = .9, grayscale = True):
  98. option = '7'
  99. print('Player messaged 7')
  100. elif pyautogui.locateCenterOnScreen('8.png',region = text_coords, confidence = .9, grayscale = True):
  101. option = '8'
  102. print('Player messaged 8')
  103. elif pyautogui.locateCenterOnScreen('9.png',region = text_coords, confidence = .9, grayscale = True):
  104. option = '9'
  105. print('Player messaged 9')
  106. elif pyautogui.locateCenterOnScreen('0.png',region = text_coords, confidence = .9, grayscale = True):
  107. option = '0'
  108. print('Player messaged 0')
  109. else:
  110. print('CANT FIND DIGIT ANSWER')
  111. option = None
  112. #reply(reply_coords,'ERROR PLEASE ENTER A NUMBER RESPONSE!')
  113. #main()
  114. print(option)
  115. return option
  116.  
  117.  
  118. def response(option): # All the possible responses the bot can give a player
  119. if option == None:
  120. return "Hello! I am bot made to answer your questions! PM the number for more options! 1: Bounties. 2: Bug Hunting. 3: Looting. 4: Farming."
  121. elif option == '1':
  122. return "The bounty quest allows you to hunt mobs for cash! Location: Castle, steward's room(to the right in the throne room) [PM 1 for specifics, PM 2 for TIPS, PM 3 for possible bounties]"
  123. elif option == '12':
  124. return '1. The bounty box will "drop"(stop following you, and will not pick up anything) after every kill/capture you get, and will require you to call it, or run over it to pick it up again. [PM 1 for more info, PM 9 to go back one level, PM 0 to reset choices]'
  125. elif option == '13':
  126. return '100 green blobs, 20 Lizardons, 75 Pyrats(as homage to the PQ I assume), 75 Rebel soldiers(regular green baddy), 60 dark blobs, 60 rats, 75 snakes, 75 bats, 75 bandits, 80 spiders, 50 archers, or 50 crabs. [PM 9 to go back one level, PM 0 to reset choices]'
  127.  
  128.  
  129. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement