Files
limoka/Fl1yd/FTG-Modules/dictionary.py
2025-07-10 21:02:34 +03:00

50 lines
1.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import json, requests
from .. import loader, utils
def register(cb):
cb(DictionaryMod())
class DictionaryMod(loader.Module):
"""Словарь."""
strings = {'name': 'Dictionary'}
async def meancmd(self, message):
"""Использование: .mean <слово>."""
args = utils.get_args_raw(message)
if not args:
return await message.edit('<b>Нет аргументов.</b>')
await message.edit('<b>Узнаем...</b>')
lang = None
alphabet = {"а","б","в","г","д","е","ё","ж","з","и","й","к","л","м","н","о",
"п","р","с","т","у","ф","х","ц","ч","ш","щ","ъ","ы","ь","э","ю","я"}
for char in args:
if char in alphabet:
lang = 'ru'
else:
lang = 'en'
r = requests.get(f'https://api.dictionaryapi.dev/api/v2/entries/{lang}/{args}')
js = json.loads(r.text)
df = ''
try:
for i in js[0]["meanings"][0]["definitions"]:
try:
df += (f'{i["definition"]} ')
except:
return
except:
await message.edit(f'◆ <b>{args}</b> - <i>Такого слова нет в словаре.</i>')
return
ex = ''
count = 0
mess = (f'<b>{js[0]["word"]}</b>, <i>{js[0]["meanings"][0]["partOfSpeech"]}</i>.\n\n'
f'◆ <b>Значение:</b> <i>{df}</i>\n')
try:
for i in js[0]["meanings"][0]["definitions"]:
count += 1
ex += f'\n<b>{count})</b> <i>{i["example"]}</i>'
alert = ''.join(ex)
except:
await message.edit(mess)
return
await message.edit(f'{mess}◆ <b>Примеры применения слова:</b> {alert}')