mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 11:48:55 -05:00
Support for definition # in !urban, info > userinfo, server > serverinfo
This commit is contained in:
parent
153f272164
commit
881a1d3212
@ -155,7 +155,7 @@ class General:
|
||||
await self.bot.say(msg)
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
async def info(self, ctx, user : discord.Member = None):
|
||||
async def userinfo(self, ctx, user : discord.Member = None):
|
||||
"""Shows users's informations"""
|
||||
author = ctx.message.author
|
||||
if not user:
|
||||
@ -175,7 +175,7 @@ class General:
|
||||
await self.bot.say(data)
|
||||
|
||||
@commands.command(pass_context=True, no_pm=True)
|
||||
async def server(self, ctx):
|
||||
async def serverinfo(self, ctx):
|
||||
"""Shows server's informations"""
|
||||
server = ctx.message.server
|
||||
online = str(len([m.status for m in server.members if str(m.status) == "online" or str(m.status) == "idle"]))
|
||||
@ -199,20 +199,38 @@ class General:
|
||||
await self.bot.say(data)
|
||||
|
||||
@commands.command()
|
||||
async def urban(self, *, search_terms : str):
|
||||
"""Urban Dictionary search"""
|
||||
async def urban(self, *, search_terms : str, definition_number : int=1):
|
||||
"""Urban Dictionary search
|
||||
|
||||
Definition number must be between 1 and 10"""
|
||||
# definition_number is just there to show up in the help
|
||||
# all this mess is to avoid forcing double quotes on the user
|
||||
search_terms = search_terms.split(" ")
|
||||
search_terms = "+".join(search_terms)
|
||||
search = "http://api.urbandictionary.com/v0/define?term=" + search_terms
|
||||
try:
|
||||
async with aiohttp.get(search) as r:
|
||||
if len(search_terms) > 1:
|
||||
pos = int(search_terms[-1]) - 1
|
||||
search_terms = search_terms[:-1]
|
||||
else:
|
||||
pos = 0
|
||||
if pos not in range(0, 11): # API only provides the
|
||||
pos = 0 # top 10 definitions
|
||||
except ValueError:
|
||||
pos = 0
|
||||
search_terms = "+".join(search_terms)
|
||||
url = "http://api.urbandictionary.com/v0/define?term=" + search_terms
|
||||
try:
|
||||
async with aiohttp.get(url) as r:
|
||||
result = await r.json()
|
||||
if result["list"] != []:
|
||||
definition = result['list'][0]['definition']
|
||||
example = result['list'][0]['example']
|
||||
await self.bot.say("**Definition:** " + definition + "\n\n" + "**Example:** " + example )
|
||||
if result["list"]:
|
||||
definition = result['list'][pos]['definition']
|
||||
example = result['list'][pos]['example']
|
||||
defs = len(result['list'])
|
||||
await self.bot.say("**Definition #{} out of {}:\n**{}\n\n"
|
||||
"**Example:\n**{}".format(pos+1, defs, definition, example))
|
||||
else:
|
||||
await self.bot.say("Your search terms gave no results.")
|
||||
except IndexError:
|
||||
await self.bot.say("There is no definition #{}".format(pos+1))
|
||||
except:
|
||||
await self.bot.say("Error.")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user