Untitled
rain
typescript
3 years ago
2.2 kB
10
Indexable
import { deunionize, Scenes, session, Telegraf } from "telegraf";
import "dotenv/config";
if (!process.env.BOT_TOKEN) {
console.log("Please provide BOT_TOKEN");
process.exit();
}
if (!process.env.ADMINS) {
console.log("Please provide at least one ADMIN");
process.exit();
}
const ADMINS = process.env.ADMINS.split(" ").map((x) => +x);
interface MyWizardSession extends Scenes.WizardSessionData {
vidName: string;
vidImg: string;
vidHash: string;
}
type MyContext = Scenes.WizardContext<MyWizardSession>;
const createVidScene = new Scenes.WizardScene<MyContext>(
"create-vid-scene",
async (ctx) => {
await ctx.reply("Send the video you want to posted");
return ctx.wizard.next();
},
async (ctx) => {
const message = deunionize(ctx.message);
// https://t.me/TelegrafJSChat/74686
if (message && message.video) {
ctx.scene.session.vidHash = message.video.file_id;
await ctx.reply("Now input the name of the video");
return ctx.wizard.next();
} else ctx.reply("kirim vid yang benar");
},
async (ctx) => {
const message = deunionize(ctx.message);
if (message && message.text) {
ctx.scene.session.vidName = message.text;
await ctx.reply("kirim pict untuk preview vidnya cug");
return ctx.wizard.next();
} else ctx.reply("kirim yang benar");
},
async (ctx) => {
const message = deunionize(ctx.message);
if (message && message.photo) {
ctx.scene.session.vidImg = message.photo.at(-1).file_id;
await ctx.reply("kirim pict untuk preview vidnya cug");
return ctx.wizard.next();
} else ctx.reply("kirim yang benar");
}
);
const app = new Telegraf<MyContext>(process.env.BOT_TOKEN);
const stage = new Scenes.Stage<MyContext>([createVidScene]);
app.use(session());
app.use(stage.middleware());
app.start((ctx) => ctx.reply("Hi"));
app.command("/createvid", (ctx) => {
if (ADMINS.includes(ctx.message.from.id)) ctx.scene.enter("create-vid-scene");
});
app.launch().then(() => console.log("App running!"));
process.once("SIGINT", () => app.stop("SIGINT"));
process.once("SIGTERM", () => app.stop("SIGTERM"));
Editor is loading...