Add dictionary
This commit is contained in:
@@ -9,8 +9,12 @@ away - Originally by Paddo, written for v3 by Axas, final tests by aikaterna. Se
|
||||
|
||||
blurplefy - Make an avatar or an image upload blurple for Discord's 3rd anniversary.
|
||||
|
||||
cah - Cards Against Humanity, played in DM's. This can rate limit large bots via the sheer number of messages sent. Install and use with caution on larger bots.
|
||||
|
||||
chatchart - Generates a pie chart to display chat activity over the last 5000 messages. Requested by violetnyte.
|
||||
|
||||
dictonary - I stole this from UltimatePancake's v2 cogs, defines words via a dictonary. Only the "define" command for now until the dependency owner updates their files with a pending PR.
|
||||
|
||||
dungeon - New users with new accounts will be shuffled off to a locked channel on-join to help mitigate raiders. Please see the dungeon_readme.md file on this repo for more information.
|
||||
|
||||
imgwelcome - The repo can be found at: https://github.com/aikaterna/imgwelcome
|
||||
|
||||
5
dictionary/__init__.py
Normal file
5
dictionary/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from .dictionary import Dictionary
|
||||
|
||||
|
||||
def setup(bot):
|
||||
bot.add_cog(Dictionary(bot))
|
||||
38
dictionary/dictionary.py
Normal file
38
dictionary/dictionary.py
Normal file
@@ -0,0 +1,38 @@
|
||||
from redbot.core import commands
|
||||
from PyDictionary import PyDictionary
|
||||
|
||||
|
||||
class Dictionary(commands.Cog):
|
||||
"""Word, yo"""
|
||||
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.dictionary = PyDictionary()
|
||||
|
||||
@commands.command()
|
||||
async def define(self, ctx, *, word: str):
|
||||
"""Displays definitions of a given word."""
|
||||
search_msg = await ctx.send("Searching...")
|
||||
search_term = word.split(" ", 1)[0]
|
||||
result = self.dictionary.meaning(search_term)
|
||||
str_buffer = ""
|
||||
if result is None:
|
||||
await search_msg.edit(content="This word is not in the dictionary.")
|
||||
return
|
||||
for key in result:
|
||||
str_buffer += "\n**" + key + "**: \n"
|
||||
counter = 1
|
||||
j = False
|
||||
for val in result[key]:
|
||||
if val.startswith("("):
|
||||
str_buffer += str(counter) + ". *" + val + ")* "
|
||||
counter += 1
|
||||
j = True
|
||||
else:
|
||||
if j:
|
||||
str_buffer += val + "\n"
|
||||
j = False
|
||||
else:
|
||||
str_buffer += str(counter) + ". " + val + "\n"
|
||||
counter += 1
|
||||
await search_msg.edit(content=str_buffer)
|
||||
16
dictionary/info.json
Normal file
16
dictionary/info.json
Normal file
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"author": [
|
||||
"UltimatePancake"
|
||||
],
|
||||
"description": "Gets definitions for given words",
|
||||
"install_msg": "`[p]define <word>` to define a word after loading the cog with `[p]load dictionary`.",
|
||||
|
||||
"requirements": [
|
||||
"PyDictionary"
|
||||
],
|
||||
"short": "Gets definitions for given words",
|
||||
"tags": [
|
||||
"dictionary"
|
||||
],
|
||||
"type": "COG"
|
||||
}
|
||||
Reference in New Issue
Block a user