diff --git a/app/define_method.py b/app/define_method.py new file mode 100644 index 00000000..7d54ea9a --- /dev/null +++ b/app/define_method.py @@ -0,0 +1,16 @@ +import requests +import help_methods +def get_definition(content): + if len(content.split()) > 1: + word = content.split()[1:] + try: + definition = requests.get( + "https://api.urbandictionary.com/v0/define?term={}".format('%20'.join(word)) + ).json()['list'][0]['definition'] + + except IndexError: + definition = 'No definition found' + + return "`{}`\n```{}```".format(' '.join(word), definition) + else: + return help_methods.get_help_message('define') diff --git a/app/dragon-bot.py b/app/dragon-bot.py index 74e16354..6ddefcf9 100644 --- a/app/dragon-bot.py +++ b/app/dragon-bot.py @@ -2,7 +2,7 @@ import random import sys import requests import os - +import define_method import help_methods import discord import docker @@ -134,17 +134,8 @@ async def on_message(message): print('fuck u') if message.content.startswith('!define'): - if len(message.content.split()) > 1: - word = message.content.split()[1:] - try: - definition = requests.get( - "https://api.urbandictionary.com/v0/define?term={}".format('%20'.join(word)) - ).json()['list'][0]['definition'] - except IndexError: - definition = 'No definition found' - await client.send_message(message.channel, "`{}`\n```{}```".format(' '.join(word), definition)) - else: - await client.send_message(message.channel, help_methods.get_help_message('define')) + define = define_method.get_definition(message.content) + await client.send_message(message.channel, define) if message.content.startswith('!help'): await client.send_message( @@ -268,4 +259,4 @@ async def on_message(message): await client.send_message(message.channel, "There arent {} lines of output yet".format(num_lines)) -client.run(tokens[dragon_environment]) \ No newline at end of file +client.run(tokens[dragon_environment])