def post(self): """ Accepts POST requests, and processes the form; Redirect to index when completed. """ try: name = request.form['name'] # check if nothing was inputted. if name == '': name = None except: name = None try: species = request.form['species'] species = species.lower() except: species = None try: breed = request.form['breed'] except: breed = "Unknown" try: age = request.form['age'] except: age = "Unknown" try: sex = request.form['sex'] except: sex = "Unknown" try: traits = request.form['traits'] # check if nothing was inputted. if traits == '': traits = "Unknown" except: traits = "Unknown" # Based off the species assign either a dog or cat image. if species == "dog": # if the breed is cocker spaniel the breed is spaniel but # the subbreed would be cocker. So we split the input to # grab both identifiers. rand_fact = df.gimme_dog_fact() # Make sure we actually have a breed. if breed is not "Unknown": # if we have a subbreed get breed and subbreed. if ' ' in breed: subbreed, breed = (request.form['breed'].lower()).split() rand_image = dog.random_image(breed, subbreed) # we only have a major breed. else: rand_image = dog.random_image(breed) # get random image of any dog breed. else: rand_image = dog.random_image() # if we have a cat. elif species == "cat": rand_fact = cf.gimme_cat_fact() if breed == "Unknown": rand_image = cat.random_image() else: rand_image = cat.breeds(breed) # should never hit. else: rand_image = None rand_fact = None if name is not None and species is not None: model = gbmodel.get_model() model.insert(name, species, breed, age, sex, traits, rand_image, rand_fact) return redirect(url_for('index'))
def test_random_image__subbreed(): breed = 'retriever' subbreed = 'golden' res = dog.random_image(breed, subbreed) assert isinstance(res, str), "The response should be a string." assert res[0:4] == 'http', "The response should begin with 'http'"
def test_random_image__breed(): breed = 'poodle' res = dog.random_image(breed) assert isinstance(res, str), "The response should be a string." assert res[0:4] == 'http', "The response should begin with 'http'"
def test_random_image__all(): """Tests a call to get a random image.""" res = dog.random_image() assert isinstance(res, str), "The response should be a string." assert res[0:4] == 'http', "The response should begin with 'http'"
async def no_sad(message): # Sends a corgi to people who are sad. await message.channel.send("It's okay, don't be sad...\nHave a corgi...") # Fetch the corgi and SEND IT! await message.channel.send(file=discord.File(dog.random_image('corgi')))
async def on_message(message): global inquiz, quizzee, mystery, quiztime, warning, start, stop, quizmessage, quiz_voice FFMPEG_OPTIONS = { 'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn' } if not inquiz: quiztime = 0 # Prevents bot from replying to itself if message.author == client.user: return if message.content.lower() in mystery.lower() and len( message.content) >= 4 and inquiz: await message.channel.send( f"Congratulations, the Anime is {mystery}") voice_player = message.guild.voice_client voice_player.stop() voice_player.play(discord.FFmpegPCMAudio('Sounds/success.mp3')) inquiz = False quizzee = '' warning = False quiztime = 0 if message.content.lower().startswith('$join'): voice_player = await message.author.voice.channel.connect() await message.channel.send('Joined Voice Channel') if message.content.lower().startswith('$leave'): voice_player = message.guild.voice_client await voice_player.disconnect() await message.channel.send('Left Voice Channel') inquiz = False if message.content.lower().startswith('$stop'): voice_player = message.guild.voice_client if voice_player.is_playing(): voice_player.stop() if inquiz: await quizmessage.channel.send( f'Too bad, the anime was {mystery}') inquiz = False warning = False quiztime = 0 await message.channel.send('Video Stopped') else: await message.channel.send( 'I can\'t stop the voices in your head') if message.content.startswith('$play'): if inquiz: inquiz = False warning = False quizzee = '' quiztime = 0 await quizmessage.channel.send( f'Too bad, the anime was {mystery}') try: URL, title = getVideo(message.content.split(' ', 1)[1]) voice_player = message.guild.voice_client if voice_player is None: voice_player = await message.author.voice.channel.connect() if voice_player.is_playing(): voice_player.stop() inquiz = False await message.channel.send(f'Now Playing {title}') voice_player.play(discord.FFmpegPCMAudio( URL, **FFMPEG_OPTIONS)) except: await message.channel.send( 'Something went wrong when trying to retrieve the Video') try: if message.content.split()[0].lower() in ('$hi', '$hello', '$howdy'): await message.channel.send(f'Hello {message.author}!') except: pass if message.content.lower().startswith('$quiz'): try: # Threading can lead to some problems in sharing memory if inquiz: await quizmessage.channel.send( f"Too bad, the anime was {mystery}") inquiz = False warning = False quizmessage = message quizzee = message.author await message.channel.send(f'Starting Quiz with {quizzee}') mystery = animelist[random.randint(0, 250)][1] URL, title = getVideo(mystery + ' Anime Opening') voice_player = message.guild.voice_client if voice_player is None: voice_player = await message.author.voice.channel.connect() quiz_voice = voice_player if voice_player.is_playing(): voice_player.stop() inquiz = True voice_player.play(discord.FFmpegPCMAudio( URL, **FFMPEG_OPTIONS)) await message.channel.send( f'Now Playing Mystery Opening\nCan you guess this?') quiztime = 0 except: await message.channel.send('Something Went Wrong') if message.content.lower().startswith('$how are you?'): await message.channel.send("I'm Wonderful, Thanks for asking") if message.content.lower().startswith('$joke'): joke = random.choice(puns) await message.channel.send(joke) if message.content.lower().startswith('$help'): actions = '\n'.join(options) helpbed = discord.Embed(color=0x0000ff) helpbed.title = 'General Purpose Bot Commands' helpbed.set_thumbnail( url= 'https://images.discordapp.net/avatars/692723897887490138/5d4e9766c52fa9142924df3bb9a1d514.png?size=512' ) helpbed.description = actions await message.channel.send(embed=helpbed) if message.content.lower().startswith('$time'): await message.channel.send( f'It\'s currently {time.ctime()} in Kuwait') if message.content.lower().startswith('$ban'): user = message.content.split()[1] await message.channel.send(f'Ban {user}? [y/n]') await asyncio.sleep(2) await message.channel.send(f'Banning {user}') await asyncio.sleep(1) await message.channel.send('JK I Can\'t do that\nUnless.....') if message.content.lower().startswith('$weather'): channel = message.channel city = message.content.split(' ', 1)[1] text = getWeather(city, channel) await message.channel.send(text) if message.content.lower().startswith('$wiki'): wikibed = discord.Embed(color=0x0000ff) content = message.content.split(' ', 1)[1] summary, success = getSummary(content) if success: wikipage = wikipedia.page(title=content, preload=False) wikibed.title = wikipage.title wikibed.description = summary wikibed.set_thumbnail(url=wikipage.images[0]) await message.channel.send(embed=wikibed) else: await message.channel.send( 'Your Query was too Ambiguous, or the Details don\'t Exist' ) if message.content.lower().startswith('$wolfram'): query = message.content.split(' ', 1)[1] try: solutions = wolfclient.query(query) answer = next(solutions.results).text wolfbed = discord.Embed(color=0xffa500) wolfbed.title = query wolfbed.description = answer await message.channel.send(embed=wolfbed) except: await message.channel.send( "Wolfram cannot find the Answer to that Question") if message.content.lower().startswith('$dogbreed'): breeds = dog.all_breeds() doglist = '\n'.join(breeds) await message.channel.send( f'```These are the Dog Breeds on this Planet:\n{doglist}```') if message.content.lower().startswith('$rdog'): words = message.content.split() try: if len(words) == 1: await message.channel.send(dog.random_image()) else: await message.channel.send( dog.random_image(words[1].lower())) except: await message.channel.send("Invalid Breed")