Chinese-English translation plug-in

foreword

Paste my api address here: Mengxinyuan API

Please ask less if you can request less, after all, a small server cannot withstand a large number of visits, thank you

use

Command : #translate+ translate content

No need to specify the translation type, automatic text recognition

use screenshot

code part

The code is written very clearly for you.

isn't it sweet

"""
作者:萌新源
时间:2022/4/1
操作系统:debian for raspberry pi
修改请保留本插件的版权
本插件版权属于萌新源
要发布请注明出处
"""
'''
翻译 调用API http://hm.suol.cc/API/fy.php?msg=
命令:#翻译
'''
from nonebot import on_keyword
from nonebot.typing import T_State
from nonebot.adapters.onebot.v11 import GroupMessageEvent, Bot, Message, Event
import requests

translate = on_keyword ( {
    
    '#翻译'} )


@translate.handle ()
async def sj(bot: Bot, event: Event, state: T_State):
    get_msg = str ( event.get_message () ).strip ()
    get_msg = get_msg.strip ( '#翻译' )
    url = f'http://hm.suol.cc/API/fy.php?msg={get_msg}'
    get_data = requests.get ( url )
    get_txt = get_data.text
    mxy = '——Power by 萌新源'
    msg = f'{get_txt}\n{mxy}'
    await translate.finish ( Message ( f'{msg}' ) )

Summarize

This plugin uses Python's requests library, which should be of high learning value for novices, and it also uses regular matching

I look forward to seeing all the cute new friends who can become big bosses as soon as possible, I am still the cute new source

Guess you like

Origin blog.csdn.net/m0_66648798/article/details/128060355