Telegram Bot 命令处理程序

时间:2021-01-13 11:33:31

标签: javascript node.js

我正在为 Telegram 开发一个机器人。随着代码随着时间的推移激增,我的 index.js 文件变得非常混乱和不可读。我想通过制作脚本来摆脱这个问题。你能详细解释一下我需要为此做什么吗?

const { Telegraf, Context } = require('telegraf')
var fs = require("fs");
//Bot Token
const bot = new Telegraf(token)
//Start Komutu
bot.start((ctx) => ctx.reply(`Merhaba ${ctx.from.first_name} Hoşgeldin!`))
//Help/Yardım Komutu
bot.help((ctx) => ctx.reply(`Merhaba ${ctx.from.first_name},\nBu Kısım Daha Sonra Doldurulacak! Lütfen Daha Sonra Tekrar Dene!`))
//Selamlama Komutu
bot.hears('Sa', (ctx) => ctx.reply(`Aleyküm Selam ${ctx.from.first_name}! Hoşgeldin!`))
//Mesaj Kaydetme
bot.on('text',(ctx) => {
    mesaj = ("[(" + ctx.chat.title + ") (" + String(new Date().getUTCFullYear()) + "/" + String(new Date().getUTCMonth() + 1) + "/" + String(new Date().getUTCDate()) + ") "+ String(new Date().getHours()) + "." + String(new Date().getMinutes()) + "."+ String(new Date().getSeconds() + 1) + "] " + ctx.from.first_name + " " + ctx.from.last_name + " : " + ctx.update.message.text + "\n")
    console.log(mesaj)
    fs.appendFileSync(".\\Loglar\\log [(" + ctx.chat.title + ") (" + String(ctx.chat.id) + ")].txt", mesaj)
});
//Başlatma
bot.launch()

0 个答案:

没有答案