-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
78 lines (67 loc) · 3.98 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
`use strict`;
const {Telegraf, Input} = require(`telegraf`);
const fs = require(`fs`);
const {getUserSettings, setUserSettings, defaultSettings} = require(`./utils/settings-functions.js`);
const {tokenFilename} = require(`./data.js`);
const {saveLogs, makeAudio, formatNumbers} = require(`./utils/data-functions.js`);
const bot = new Telegraf(fs.readFileSync(tokenFilename, {encoding:`utf8`, flag:`r`}));
bot.start(async (ctx) => {
saveLogs(ctx);
getUserSettings(ctx.update.message.from.id);
const startMsg = `Hello, I am SAM - Software Automatic Mouth!`;
ctx.reply(startMsg);
await ctx.replyWithAnimation({source : `./media/Michael\ Davies\ Crawl.gif`});
ctx.replyWithAudio({source: `./media/sam-story.mp3`});
});
bot.help((ctx) => {
saveLogs(ctx);
const helpMsg = `\/voice text to get audio.`;
ctx.reply(helpMsg);
ctx.replyWithAudio({source: makeAudio(`text to get audio.`, getUserSettings(ctx.update.message.from.id))});
ctx.reply(`\/set_profile_by_id ID - to set new profile\n\/show_all_profiles - to look at available profiles\n\/show_faith_profiles - to look profiles as pic`);
});
bot.hears(/\/show_current_profile/, (ctx) => {
saveLogs(ctx);
const spaceCount = 3;
const currentProfile = getUserSettings(ctx.update.message.from.id);
ctx.replyWithMarkdown(`Current profile: ${defaultSettings[currentProfile.id].name}\n\`\`\`\npitch${``.padEnd(spaceCount, ` `)}speed${``.padEnd(spaceCount, ` `)}mouth${``.padEnd(spaceCount, ` `)}throat\n ${formatNumbers(currentProfile.pitch)}${``.padEnd(5, ` `)}${formatNumbers(currentProfile.speed)}${``.padEnd(5, ` `)}${formatNumbers(currentProfile.mouth)}${``.padEnd(6, ` `)}${formatNumbers(currentProfile.throat)}\n\`\`\`Modern CMU: ${currentProfile.modernCMU? `Enable`: `Disable`} | Sing mode: ${currentProfile.singMode? `Enable`: `Disable`}`);
});
bot.hears(/\/show_all_profiles/, (ctx) => {
saveLogs(ctx);
let responseBuffer = ``;
const spaceCount = 3;
defaultSettings.forEach((item) => responseBuffer+=`Profile: \*\*\*${item.name}\*\*\* | id: ${item.id}\n\`\`\`\npitch${``.padEnd(spaceCount, ` `)}speed${``.padEnd(spaceCount, ` `)}mouth${``.padEnd(spaceCount, ` `)}throat\n ${formatNumbers(item.stats.pitch)}${``.padEnd(5, ` `)}${formatNumbers(item.stats.speed)}${``.padEnd(5, ` `)}${formatNumbers(item.stats.mouth)}${``.padEnd(6, ` `)}${formatNumbers(item.stats.throat)}\n\n\`\`\``);
ctx.replyWithMarkdown(responseBuffer);
});
bot.hears(/\/show_faith_profiles/, async (ctx) => {
saveLogs(ctx);
await ctx.replyWithPhoto(Input.fromLocalFile(`./media/wiki-guide.jpeg`));
});
bot.hears(/\/set_profile_by_id (.+)/, (ctx) => {
saveLogs(ctx);
const id = ctx.match[1];
if (id < defaultSettings.length) {
let currentProfile = getUserSettings(ctx.update.message.from.id);
currentProfile.id = id;
setUserSettings(ctx.update.message.from.id, currentProfile);
ctx.replyWithMarkdown(`Done! Profile \*\*\*${defaultSettings[currentProfile.id].name}\*\*\* active.`);
} else {
ctx.reply(`Wrong ID\nMin ID: 0 | Max ID: ${defaultSettings.length-1}\nYou try to set ID: ${id}`);
}
});
bot.hears(/^(\/enable|\/disable|\/toggle)_(modern_cmu|sing_mode)$/, (ctx) => {
const userSettings = getUserSettings(ctx.update.message.from.id);
userSettings[ctx.match[2] === `modern_cmu` ? `modernCMU` : `singMode`] = ctx.match[1] === `/toggle` ? !(userSettings[ctx.match[2] === `modern_cmu` ? `modernCMU` : `singMode`]) : ctx.match[1] === `/enable`;
setUserSettings(ctx.update.message.from.id, userSettings);
ctx.reply(`Modern CMU: ${userSettings.modernCMU} | Sing mode: ${userSettings.singMode}`);
});
bot.hears(/\/voice (.+)/, (ctx) => {
saveLogs(ctx);
ctx.replyWithAudio({source: makeAudio(ctx.update.message.text.slice(7, ctx.update.message.text.length), getUserSettings(ctx.update.message.from.id))});
});
bot.hears(/\/ping/, (ctx) => ctx.reply(`SAM alive !`));
bot.hears(/\/echo/, (ctx) => ctx.reply(ctx.match[1]));
bot.launch();
// Enable graceful stop
process.once(`SIGINT`, () => bot.stop(`SIGINT`));
process.once(`SIGTERM`, () => bot.stop(`SIGTERM`));