Ejemplo n.º 1
0
 def __init__(self, name):
     self.name = name
     self.brain = Brain()
     self.joke = False
     self.id = 'DISCORD_API_KEY'
     time.sleep(2)
     
     super().__init__(command_prefix="")
Ejemplo n.º 2
0
            running_sum += max(0, car.last_reward)
            for idy, rand in enumerate(rands):
                dist = running_sum - rand
                if 0 < dist < dists[idy]:
                    dists[idy] = dist
                    parents[idy] = idx
        return parents


# The brain instance, which will compute what to do for a state
# In this case, every cars "brain" is added to a big module, for sake of speed,
# this way, the model has to be loaded once per step per frame
# Disadvantage: if there are less cars to step with, it will use the big model either
# so it does not matter, if only 10 cars alive from 500 or 500, the action calculation
# step will take the same time...
brain = Brain(len(ray_angles), action2movetable, species_per_population, learn,
              filename)

# Creating the Game instance
game = MyGame(show_population, 1000, 1000)
game.set_brain(brain)
if learn:
    game.set_learning()

# Generate track
game.generate_track(draw_gates=False)

# Set player number
game.set_car_number(species_per_population, ray_angles, lapse_until_won=5)

# Set length of the game
game.set_game_length(number_of_generations)
Ejemplo n.º 3
0
def start_remote_prompt():
    print("Remote Mode Activated")
    brain = Brain()
    brain.remote_mode()
Ejemplo n.º 4
0
def start_text_prompt():
    print("Text Input Mode Is Activated")
    brain = Brain()
    brain.text_mode()
Ejemplo n.º 5
0
def start_listening():
    print("Voice Mode Activated")
    brain = Brain()
    brain.voice_mode()
Ejemplo n.º 6
0
class Bot(Bot):
    
    def __init__(self, name):
        self.name = name
        self.brain = Brain()
        self.joke = False
        self.id = 'DISCORD_API_KEY'
        time.sleep(2)
        
        super().__init__(command_prefix="")
    
    def run(self):
        super().run(self.id, reconnect=True)
    
    async def on_ready(self):
        print('We have logged in as {}'.format(self.user))
    
    async def on_message(self, message):
        if message.author == self.user or self.joke:
            return

        if message.content.startswith('$hello'):
            await message.channel.send('Hello! ' + message.author.display_name)

        elif message.content.startswith('Say something good'):
            await message.channel.send(self.get_quote())

        elif message.content.startswith('Tell me a joke'):
            question, punchline = self.get_dad_joke(message)
            
            await message.channel.send(question)
            self.set_joke(True)
            
            time.sleep(5)
            
            await message.channel.send(punchline)
            self.set_joke(False)
            
        elif message.content.startswith('Send a meme'):
            await message.channel.send(self.get_meme())
            
        elif message.content.startswith('What is your name?'):
            await message.channel.send("I am Prophet")

        elif message.content.startswith('$voice on'):
            await message.channel.send('Voice Mode activated')
            self.brain.voiceModeOn()

        elif message.content.startswith('$voice off'):
            await message.channel.send('Voice Mode deactivated')
            self.brain.voiceModeOff()

        elif message.content.startswith('$flush memory'):
            self.reset_mem(str(message.channel.id))
            await message.channel.send('I am brand new')
            
        elif message.content.startswith('$Prophetize'):
            await message.channel.send("I am a prophet")
            
        else:
            self.brain.feed(str(message.channel.id), message.content)
            answer = self.brain.answer(str(message.channel.id))
            if self.brain.hasVoice:
                await message.channel.send(file=File(answer))
            else:
                await message.channel.send(answer)
    
    def set_joke(self, mode):
        self.joke = mode


    def get_quote(self):
        response = requests.get("https://zenquotes.io/api/random")
        json_data = json.loads(response.text)
        quote = json_data[0]['q'] + " -- " + json_data[0]['a']
        return quote

    def get_meme(self):
        response = requests.get("https://api.imgflip.com/get_memes")
        json_data = json.loads(response.text)
        memes = json_data['data']['memes']
        
        urls = []
        
        for m in memes:
            url = m['url']
            urls.append(url)
            
        return urls[random.randint(0, len(urls) - 1)]
        
    def reset_mem(self, channel):
        self.brain.reset_memory(channel)
        
        
    def get_dad_joke(self, message):
        msg = message.content.split()
        if "about" in msg:
            term = msg[-1]
        else:
            term = ""
        
        if term == "":
            url = "https://dad-jokes.p.rapidapi.com/random/joke"
        else:
            url = "https://dad-jokes.p.rapidapi.com/joke/search?term={}".format(term)

        headers = {
            'x-rapidapi-key': "API_KEY",
            'x-rapidapi-host': "API_URL"
        }
        response = requests.request("GET", url, headers=headers)
        
        json_data = json.loads(response.text)
        jokes = []
        for j in json_data['body']:
            question = j['setup']
            punchline = j['punchline']
            jokes.append([question, punchline])
        
        joke = jokes[random.randint(0, len(jokes) - 1)]
        
        return joke[0], joke[1]