-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
78 lines (62 loc) · 2.83 KB
/
main.js
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const fetch = require("node-fetch");
const discord = require("discord.js");
const fs = require("fs");
const option = {ws: {intents: discord.Intents.ALL}, restTimeOffset: 10};
const client = new discord.Client(option);
const logger = require("./util/logger");
const BOT_DATA = require("./config/config.json");
let channelID = require("./config/channel.json");
client.on("ready", message => {
logger.info(`{green}${BOT_DATA.NAME}{reset} is ready! ver. ${BOT_DATA.VERSION} \n login: {cyan}${client.user.tag}\n`);
client.user.setActivity(`${BOT_DATA.NAME} Ver ${BOT_DATA.VERSION}`, { type: 'PLAYING' })
});
client.on("message", async message => {
if(channelID.indexOf(message.channel.id)>-1 && !message.author.bot && !message.content.startsWith("//")){
bouyomiTalk(`${message.author.username}\n${message.content}`);
}
if(message.content.startsWith(BOT_DATA.PREFIX)){
const [command, ...args] = message.content.slice(BOT_DATA.PREFIX.length).split(' ');
if(command == BOT_DATA.COMMAND){
switch(args[0]){
case "add" :
channelID.push(message.channel.id);
message.channel.send(`チャンネル(${message.channel.name})を、読み上げリストに追加しました。`);
fs.writeFileSync('./config/channel.json', JSON.stringify(channelID, null, "\t"),'utf8');
break;
case "delete" :
case "del" :
if(channelID.indexOf(message.channel.id)==-1){
message.channel.send(`そのチャンネル(${message.channel.name})は、読み上げリストに存在しません。`);
return;
}
delete channelID[channelID.indexOf(message.channel.id)];
channelID = channelID.filter(Boolean);
message.channel.send(`チャンネル(${message.channel.name})を、読み上げリストから削除しました。`);
fs.writeFileSync('./config/channel.json', JSON.stringify(channelID, null, "\t"),'utf8');
break;
}
}
};
})
function bouyomiTalk(text, voice, volume, speed, tone) {
let url=new URL('http://localhost:50080/talk');
let query = {
text : text,
voice : voice,
volume: volume,
speed : speed,
tone : tone
};
Object.entries(query).map( e => {
if(e[1] !== undefined) url.searchParams.set(e[0], e[1]);
});
fetch(url)
.then(res => res.json())
.then(dat => console.log(dat.taskId));
}
if(!BOT_DATA.NAME && !BOT_DATA.VERSION && !BOT_DATA.token){
logger.error("Please set config data.")
process.exit(0);
}
bouyomiTalk(`${BOT_DATA.NAME}を起動しました。`);
client.login(BOT_DATA.token);