added define module, fixes #3
This commit is contained in:
parent
69642d0df8
commit
883f9fef1d
16
app/define_method.py
Normal file
16
app/define_method.py
Normal file
@ -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')
|
@ -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])
|
||||
client.run(tokens[dragon_environment])
|
||||
|
Loading…
x
Reference in New Issue
Block a user