mirror of
https://gitlab.com/ceda_ei/Quadnite-Bot
synced 2025-10-26 06:40:06 +01:00
Compare commits
5 Commits
41ae943913
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7cf9689420 | |||
| e3a5f1a67b | |||
| cd374090f2 | |||
|
|
8274ab0980 | ||
| 80a0dbd2d3 |
@@ -13,4 +13,6 @@ roleplay gifs. Once you have an instance of Ugoki (and optionally
|
|||||||
- `export BOT_API_KEY="your-token-for-bot"`
|
- `export BOT_API_KEY="your-token-for-bot"`
|
||||||
- `export FEEDBACK_ID="chat-id-where-feedback-is-forwarded-to"`
|
- `export FEEDBACK_ID="chat-id-where-feedback-is-forwarded-to"`
|
||||||
- `export UGOKI_ROOT="https://root.of.ugoki.api/server/"`
|
- `export UGOKI_ROOT="https://root.of.ugoki.api/server/"`
|
||||||
|
- `export RATE_TIMEFRAME=5000 # rate limit time interval in milliseconds`
|
||||||
|
- `export RATE_LIMIT=5 # number of requests allowed in the timeframe`
|
||||||
- `npm start`
|
- `npm start`
|
||||||
|
|||||||
9
bot.js
9
bot.js
@@ -1,12 +1,19 @@
|
|||||||
const { Telegraf } = require("telegraf");
|
const { Telegraf } = require("telegraf");
|
||||||
const { BOT_API_KEY, FEEDBACK_ID, UGOKI_ROOT } = process.env;
|
const { BOT_API_KEY, FEEDBACK_ID, UGOKI_ROOT, RATE_TIMEFRAME, RATE_LIMIT } = process.env;
|
||||||
const fs = require("fs").promises;
|
const fs = require("fs").promises;
|
||||||
const commands = require("./commands");
|
const commands = require("./commands");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
const roleplay = require("./static/roleplay.json");
|
const roleplay = require("./static/roleplay.json");
|
||||||
|
const { limit } = require("@grammyjs/ratelimiter");
|
||||||
|
|
||||||
const bot = new Telegraf(BOT_API_KEY);
|
const bot = new Telegraf(BOT_API_KEY);
|
||||||
bot.catch((err) => console.log(err));
|
bot.catch((err) => console.log(err));
|
||||||
|
bot.use(limit({
|
||||||
|
// default config: 1 message per 1 second
|
||||||
|
timeFrame: RATE_TIMEFRAME ?? 1000,
|
||||||
|
limit: RATE_LIMIT ?? 1,
|
||||||
|
keyGenerator: (ctx) => ctx.chat?.id.toString() ?? ctx.from?.id.toString(),
|
||||||
|
}))
|
||||||
|
|
||||||
const data = [
|
const data = [
|
||||||
"questions",
|
"questions",
|
||||||
|
|||||||
@@ -5,16 +5,18 @@ module.exports = (bot, feedback_id) => (ctx) => {
|
|||||||
|
|
||||||
const from = ctx.message.from;
|
const from = ctx.message.from;
|
||||||
let contactable = "The developer might contact you regarding your feedback.";
|
let contactable = "The developer might contact you regarding your feedback.";
|
||||||
|
let message;
|
||||||
if (from.username) {
|
if (from.username) {
|
||||||
|
|
||||||
bot.telegram.sendMessage(feedback_id, `Feedback from: @${from.username}`);
|
message = `Feedback from: @${from.username}`;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
contactable = "The developer might not be able to contact you due to lack of your username.";
|
contactable = "The developer might not be able to contact you due to lack of your username.";
|
||||||
|
message = `Feedback from User ${from.id}`;
|
||||||
|
|
||||||
}
|
}
|
||||||
ctx.forwardMessage(feedback_id);
|
bot.telegram.sendMessage(feedback_id, `${message} ${ctx.message.text}`).catch(console.log);
|
||||||
return `Thanks for the feedback! ${contactable}`;
|
return `Thanks for the feedback! ${contactable}`;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ module.exports = (bot, [ questions, kys, insults, commands_list, words, roleplay
|
|||||||
.then(bot_user => {
|
.then(bot_user => {
|
||||||
|
|
||||||
const default_text = (command, text) => `Do you want to ${text} `
|
const default_text = (command, text) => `Do you want to ${text} `
|
||||||
+ `yourself?\nIf no, reply to someone with /${command} to kill`
|
+ `yourself?\nIf no, reply to someone with /${command} to ${command}`
|
||||||
+ ` them or run /${command} username/name.\nYou can suggest `
|
+ ` them or run /${command} username/name.\nYou can suggest `
|
||||||
+ `more /${command} replies using /feedback`;
|
+ `more /${command} replies using /feedback`;
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ module.exports = (forms, getGif) => (ctx) => {
|
|||||||
reply = forms.none
|
reply = forms.none
|
||||||
.replace("{}", user);
|
.replace("{}", user);
|
||||||
|
|
||||||
getGif()
|
return getGif()
|
||||||
.then(gif => ctx.replyWithAnimation(gif.data.url, {caption: reply}));
|
.then(gif => ctx.replyWithAnimation(gif.data.url, {caption: reply}));
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
11
package-lock.json
generated
11
package-lock.json
generated
@@ -9,12 +9,18 @@
|
|||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@grammyjs/ratelimiter": "^1.2.0",
|
||||||
"axios": "^0.21.0",
|
"axios": "^0.21.0",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"telegraf": "^4.15.3"
|
"telegraf": "^4.15.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@grammyjs/ratelimiter": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@grammyjs/ratelimiter/-/ratelimiter-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-xBkH/ATJsuv5JgVYX9yQM9DNg75Qqjw+gh82lVsBn4j+d0DkxxC+kuy6WFoB96Cb6oifQfaBJL8CTikdYG4v0A=="
|
||||||
|
},
|
||||||
"node_modules/@telegraf/types": {
|
"node_modules/@telegraf/types": {
|
||||||
"version": "6.9.1",
|
"version": "6.9.1",
|
||||||
"resolved": "https://registry.npmjs.org/@telegraf/types/-/types-6.9.1.tgz",
|
"resolved": "https://registry.npmjs.org/@telegraf/types/-/types-6.9.1.tgz",
|
||||||
@@ -288,6 +294,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@grammyjs/ratelimiter": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@grammyjs/ratelimiter/-/ratelimiter-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-xBkH/ATJsuv5JgVYX9yQM9DNg75Qqjw+gh82lVsBn4j+d0DkxxC+kuy6WFoB96Cb6oifQfaBJL8CTikdYG4v0A=="
|
||||||
|
},
|
||||||
"@telegraf/types": {
|
"@telegraf/types": {
|
||||||
"version": "6.9.1",
|
"version": "6.9.1",
|
||||||
"resolved": "https://registry.npmjs.org/@telegraf/types/-/types-6.9.1.tgz",
|
"resolved": "https://registry.npmjs.org/@telegraf/types/-/types-6.9.1.tgz",
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://gitlab.com/ceda_ei/Quadnite-Bot#readme",
|
"homepage": "https://gitlab.com/ceda_ei/Quadnite-Bot#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@grammyjs/ratelimiter": "^1.2.0",
|
||||||
"axios": "^0.21.0",
|
"axios": "^0.21.0",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user