Quadnite-Bot/bot.js

35 lines
938 B
JavaScript
Raw Normal View History

2024-01-24 20:08:35 +01:00
const { Telegraf } = require("telegraf");
const { BOT_API_KEY, FEEDBACK_ID, UGOKI_ROOT, RATE_TIMEFRAME, RATE_LIMIT } = process.env;
const fs = require("fs").promises;
const commands = require("./commands");
2019-02-12 14:32:38 +01:00
const axios = require("axios");
2021-09-27 20:23:33 +02:00
const roleplay = require("./static/roleplay.json");
const { limit } = require("@grammyjs/ratelimiter");
const bot = new Telegraf(BOT_API_KEY);
2019-03-04 10:18:26 +01:00
bot.catch((err) => console.log(err));
bot.use(limit({
// default config: 5 messages per 5 seconds
timeFrame: RATE_TIMEFRAME ?? 5000,
limit: RATE_LIMIT ?? 5,
onLimitExceeded: (ctx, next) => ctx.reply('Too many requests!'),
}))
const data = [
"questions",
"kys",
"insults",
2019-02-11 23:02:53 +01:00
"commands_list",
"words"
].map(file =>
2021-09-27 20:23:33 +02:00
fs.readFile("static/" + file + ".txt", "utf-8")
.then(list =>
list.split("\n")));
Promise.all(data)
.then(data =>
commands(bot, [...data, roleplay], FEEDBACK_ID, BOT_API_KEY, UGOKI_ROOT, axios));
bot.launch();