Advertisement
renix1

bot

Jul 5th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. # coding:utf-8
  2. import pyautogui as pyag
  3. import os
  4.  
  5.  
  6. class Sender(object):
  7.     def __init__(self, pos):
  8.         self.pos = pos
  9.         self._on_position()
  10.  
  11.     def _on_position(self):
  12.         pyag.click(self.pos)
  13.  
  14.     def send_message(self, message, times=3):
  15.         for time in range(0, times, 1):
  16.             print('Mensagens enviadas: {}'.format(time))
  17.             pyag.typewrite(message)
  18.             pyag.press('enter')
  19.  
  20.     def send_chars(self, chars, times=3):
  21.         chars = chars.replace(' ', '')
  22.         for time in range(0, times, 1):
  23.             print('Mensagens enviadas: {}'.format((time+1)*len(chars)))
  24.             for char in chars:
  25.                 pyag.typewrite(char)
  26.                 pyag.press('enter')
  27.  
  28.     def send_message_creating(self, message):
  29.         length = len(message)
  30.         for i in range(0, length, 1):
  31.             pyag.typewrite(message[:i+1])
  32.             pyag.press('enter')
  33.  
  34.     def send_message_creating_inverse(self, message):
  35.         length = len(message)
  36.         for i in range(length, 0, -1):
  37.             pyag.typewrite(message[i-1:])
  38.             pyag.press('enter')
  39.  
  40.     def send_message_from_full(self, message):
  41.         length = len(message)
  42.         for i in range(length, 0, -1):
  43.             pyag.typewrite(message[:i])
  44.             pyag.press('enter')
  45.  
  46.     def triangle(self, message):
  47.         self.send_message_creating(message)
  48.         self.send_message_from_full(message)
  49.  
  50. class Recognizer(object):
  51.     IMAGES_PATH = os.path.join(os.getcwd(), 'images')
  52.     def __init__(self, image_path):
  53.         self._image_path = os.path.join(self.IMAGES_PATH, image_path)
  54.  
  55.     def run(self):
  56.         location = pyag.locateCenterOnScreen(self._image_path, grayscale=1)
  57.         if location is not None:
  58.             sender = Sender(location)
  59.             return sender
  60.         else:
  61.             return None
  62.  
  63. if __name__ == '__main__':
  64.     s = Recognizer('wpp.png').run()
  65.     if isinstance(s, Sender):
  66.         s.send_chars('Opa!')
  67.     else:
  68.         print('Não há mensageiro detectado na tela...')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement