-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.ts
41 lines (35 loc) · 981 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import say from 'say';
import iciba from './src/iciba';
import youdao from './src/youdao';
import logSymbols from 'log-symbols';
import ConfigStoreManager, { ConfigItem } from './lib/ConfigManager';
import { checkLang } from './lib/util/checkLang';
import { formatQuery } from './lib/util/formatQuery';
export default async (from: string, to: string) =>
{
try
{
const {
query,
isSent,
isChinese,
} = formatQuery();
const useIciba = checkLang(from, to) && !isSent;
const useSay = ConfigStoreManager.getInstance().getConfig(ConfigItem.USE_SAY)
ConfigStoreManager.getInstance().setConfig(ConfigItem.IS_CHINESE, !!isChinese)
ConfigStoreManager.getInstance().setConfig(ConfigItem.USE_ICIBA, useIciba)
if (useIciba)
{
await iciba(query);
}
else
{
await youdao(query, from, to);
}
if (useSay) say.speak(query);
} catch (e: any)
{
const msg = e.message || '出现了一个错误...';
console.error(logSymbols.error + ' ' + msg);
}
};