Example #1
0
def cmd_wyw(expr, chatid, replyid, msg):
    '''/wyw [c|m] <something> Translate something to or from classical Chinese.'''
    if expr[:2].strip() == 'c':
        lang = 'c2m'
        expr = expr[2:]
    elif expr[:2].strip() == 'm':
        lang = 'm2c'
        expr = expr[2:]
    else:
        lang = None
    tinput = ''
    if 'reply_to_message' in msg:
        tinput = msg['reply_to_message'].get('text', '')
    tinput = (expr or tinput).strip()
    if len(tinput) > 800:
        tinput = tinput[:800] + '……'
    if not tinput:
        sendmsg('Syntax error. Usage: ' + cmd_wyw.__doc__, chatid, replyid)
        return
    typing(chatid)
    if lang is None:
        cscore, mscore = zhutil.calctxtstat(tinput)
        if cscore == mscore:
            lang = None
        elif zhutil.checktxttype(cscore, mscore) == 'c':
            lang = 'c2m'
        else:
            lang = 'm2c'
    if lang:
        tres = mosesproxy.translate(tinput, lang, 0, 0, 0)
        sendmsg(tres, chatid, replyid)
    else:
        sendmsg(tinput, chatid, replyid)
Example #2
0
def cmd_wyw(tinput, lang):
    if lang is None:
        cscore, mscore = zhutil.calctxtstat(tinput)
        if cscore == mscore:
            lang = None
        elif zhutil.checktxttype(cscore, mscore) == 'c':
            lang = 'c2m'
        else:
            lang = 'm2c'
    if lang:
        return mosesproxy.translate(tinput, lang, 0, 0, 0)
    else:
        return tinput