👷 Fix CI build system (#169)

* 👷 修复 ci 错误
This commit is contained in:
Xtao_dada 2022-01-20 17:30:53 +08:00 committed by GitHub
parent 621ffca6b5
commit b9dcc68956
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 23 deletions

View File

@ -1,11 +1,14 @@
""" PagerMaid features that uses external HTTP APIs other than Telegram. """ """ PagerMaid features that uses external HTTP APIs other than Telegram. """
from pygoogletranslation import Translator import translators as ts
from os import remove from os import remove
from magic_google import MagicGoogle from magic_google import MagicGoogle
from gtts import gTTS from gtts import gTTS
from gtts.tts import gTTSError from gtts.tts import gTTSError
from re import compile as regex_compile from re import compile as regex_compile
from translators.apis import TranslatorError
from pagermaid import log, silent from pagermaid import log, silent
from pagermaid.listener import listener, config from pagermaid.listener import listener, config
from pagermaid.utils import clear_emojis, attach_log, fetch_youtube_audio, lang, alias_command from pagermaid.utils import clear_emojis, attach_log, fetch_youtube_audio, lang, alias_command
@ -16,7 +19,6 @@ from pagermaid.utils import clear_emojis, attach_log, fetch_youtube_audio, lang,
parameters=lang('translate_parameters')) parameters=lang('translate_parameters'))
async def translate(context): async def translate(context):
""" PagerMaid universal translator. """ """ PagerMaid universal translator. """
translator = Translator()
reply = await context.get_reply_message() reply = await context.get_reply_message()
message = context.arguments message = context.arguments
ap_lang = config['application_language'] ap_lang = config['application_language']
@ -27,26 +29,20 @@ async def translate(context):
else: else:
await context.edit(lang('arg_error')) await context.edit(lang('arg_error'))
return return
source_text = clear_emojis(message)
try: try:
if not silent: if not silent:
await context.edit(lang('translate_processing')) await context.edit(lang('translate_processing'))
try: try:
result = translator.translate(clear_emojis(message), dest=ap_lang) result = ts.google(source_text, to_language=ap_lang.replace("zh-cn", "zh-CN"))
except: except TranslatorError:
from translate import Translator as trans return await context.edit(lang('translate_ValueError'))
result = trans(to_lang=ap_lang.replace('zh-cn', 'zh')).translate(clear_emojis(message))
except ValueError: except ValueError:
await context.edit(lang('translate_ValueError')) return await context.edit(lang('translate_ValueError'))
return if not result:
try: return await context.edit(lang('google_connection_error'))
source_lang = result.src result = f"**{lang('translate_hits')}**\n" \
source_text = result.origin f"{source_text} -> {result}"
trans_lang = result.dest
except AttributeError:
await context.edit(lang('google_connection_error'))
return
result = f"**{lang('translate_hits')}**\n{lang('translate_original_lang')}: {source_lang}\n{source_text} -> {result.text}"
if len(result) > 4096: if len(result) > 4096:
await context.edit(lang('translate_tg_limit_uploading_file')) await context.edit(lang('translate_tg_limit_uploading_file'))
@ -54,9 +50,10 @@ async def translate(context):
return return
await context.edit(result) await context.edit(result)
if len(result) <= 4096: if len(result) <= 4096:
await log(f"{lang('translate_get')}: `{source_text}` \n{lang('translate_from')} {source_lang} {lang('translate_to')} {trans_lang}") await log(f"{lang('translate_get')}: `{source_text}` \n"
f"{lang('translate_to')} {ap_lang}")
else: else:
await log(f"{lang('translate_get')}{translate('translate_from')} {source_lang} {lang('translate_to')} {trans_lang}.") await log(f"{lang('translate_get')} {lang('translate_to')} {ap_lang}.")
@listener(is_plugin=False, outgoing=True, command=alias_command('tts'), @listener(is_plugin=False, outgoing=True, command=alias_command('tts'),

View File

@ -9,12 +9,10 @@ PyYAML>=5.4.1
redis>=3.5.3 redis>=3.5.3
coloredlogs>=15.0.1 coloredlogs>=15.0.1
requests[socks]>=2.25.1 requests[socks]>=2.25.1
httpx[socks]>=0.21.3 httpx>=0.21.3
pytz>=2021.1 pytz>=2021.1
cowpy>=1.1.0 cowpy>=1.1.0
googletrans>=4.0.0-rc1 translators>=5.0.1
pygoogletranslation>=2.0.6
translate>=3.5.0
gTTS>=2.2.2 gTTS>=2.2.2
gTTS-token>=1.1.4 gTTS-token>=1.1.4
wordcloud>=1.8.1 wordcloud>=1.8.1