This commit is contained in:
Lukian 2023-06-20 15:25:19 +02:00
parent 13ec9babde
commit 68f4b60012
1429 changed files with 2481 additions and 272836 deletions

View file

@ -1,27 +1,5 @@
const fs = require('fs');
function isTrue(message, ctx, bot) {
if (message != undefined) {
var totalSum = 0
for (var i = 0; i < message.length; i++) {
totalSum += message.charCodeAt(i)
}
if (totalSum%2 == 0) {
bot.telegram.sendMessage(ctx.chat.id, "This message is true", {"reply_to_message_id": ctx.update.message.reply_to_message.message_id});
console.log("[Telegram] sent true for the query: " + message);
addToLogs("[Telegram] sent true for the query: " + message);
}
else {
bot.telegram.sendMessage(ctx.chat.id, "This message is false", {"reply_to_message_id": ctx.update.message.reply_to_message.message_id});
console.log("[Telegram] sent false for the query: " + message);
addToLogs("[Telegram] sent false for the query: " + message);
}
} else {
bot.telegram.sendMessage(ctx.chat.id, "Please reply to a text message", {'reply_to_message_id': ctx.update.message.message_id});
}
}
function addToLogs(message) {
fs.appendFile('./logs/logs.txt', message + "\n", err => {
if (err) {
@ -30,22 +8,4 @@ function addToLogs(message) {
});
}
function getHelp(commandName, ctx, bot) {
const commands = [ 'images', 'games', 'r34', 'openai', 'tools' ];
const commandsPaths = { 'images': './src/telegram_helps/images.txt', 'games': './src/telegram_helps/games.txt', 'r34': './src/telegram_helps/r34.txt', 'openai': './src/telegram_helps/openAI.txt', 'tools': './src/telegram_helps/tools.txt' };
if (commands.includes(commandName)) {
fs.readFile(commandsPaths[commandName], 'utf8', (err, data) => {
if (err) {
console.log(err);
bot.telegram.sendMessage(ctx.chat.id, "Something went wrong", {});
} else {
bot.telegram.sendMessage(ctx.chat.id, data, {parse_mode: 'Markdown'});
}
});
} else {
bot.telegram.sendMessage(ctx.chat.id, "This command doesn't exist", {});
}
}
module.exports = { addToLogs, isTrue, getHelp };
module.exports = { addToLogs };

View file

@ -1,27 +0,0 @@
const request = require('request');
function getJoke(ctx, bot) {
const options = {
method: 'GET',
url: 'https://dad-jokes.p.rapidapi.com/random/joke',
headers: {
'X-RapidAPI-Key': process.env.DADJOKES,
'X-RapidAPI-Host': 'dad-jokes.p.rapidapi.com',
useQueryString: true
}
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
res = JSON.parse(body)
bot.telegram.sendMessage(ctx.chat.id, res.body[0].setup, {});
setTimeout(() => {
bot.telegram.sendMessage(ctx.chat.id, res.body[0].punchline, {});
}, 500);
});
}
module.exports = { getJoke };

View file

@ -1,56 +0,0 @@
function rockPaperScissorsAgainstBot(userChoice, ctx, bot) {
const choices = ["rock", "paper", "scissors"];
if (choices.includes(userChoice) == true)
{
const botChoice = choices[Math.floor(Math.random() * choices.length)];
bot.telegram.sendMessage(ctx.chat.id, "You chose " + userChoice + " and I chose " + botChoice, {})
//wait 50ms
setTimeout(function() {
if (userChoice == botChoice)
{
bot.telegram.sendMessage(ctx.chat.id, "It's a tie!", {});
}
else if (userChoice == "rock")
{
if (botChoice == "paper")
{
bot.telegram.sendMessage(ctx.chat.id, "You lose! Paper beats rock.", {});
}
else
{
bot.telegram.sendMessage(ctx.chat.id, "You win! Rock beats scissors.", {});
}
}
else if (userChoice == "paper")
{
if (botChoice == "scissors")
{
bot.telegram.sendMessage(ctx.chat.id, "You lose! Scissors beats paper.", {});
}
else
{
bot.telegram.sendMessage(ctx.chat.id, "You win! Paper beats rock.", {});
}
}
else if (userChoice == "scissors")
{
if (botChoice == "rock")
{
bot.telegram.sendMessage(ctx.chat.id, "You lose! Rock beats scissors.", {});
}
else
{
bot.telegram.sendMessage(ctx.chat.id, "You win! Scissors beats paper.", {});
}
}
}, 50);
} else
{
bot.telegram.sendMessage(ctx.chat.id, "Please choose between rock, paper and scisors", {});
}
}
module.exports = { rockPaperScissorsAgainstBot };

View file

@ -1,91 +0,0 @@
//
// Rule34 Fuctions for the Rule34 Bot
//
const https = require('https');
const { addToLogs } = require('./botTools');
const blockedChannels = [ -1001845876532 ];
function rtag(query, ctx, bot) {
if (blockedChannels.includes(ctx.chat.id)) {
bot.telegram.sendMessage(ctx.chat.id, "This command is disabled in this channel", {});
return;
}
console.log("--> r34sTag query: " + query);
addToLogs("--> r34sTag query: " + query);
https.get("https://rule34.xxx/public/autocomplete.php?q=" + query, (resp) => {
let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
res = JSON.parse(data);
message = "Tags for the query " + query + " :\n" ;
if (res.length == 0) {
console.log("--> no tags found for the query: " + query);
addToLogs("--> no tags found for the query: " + query);
bot.telegram.sendMessage(ctx.chat.id, "No tags found for the query: " + query, {});
} else {
for (var i = 0; i < res.length; i++) {
message += "\n - `" + res[i].value+"`";
}
message += "\n\nUse `/r34 <tag>` to get a random image for the tag" + "\nExample: `/r34 " + res[0].value + "`";
bot.telegram.sendMessage(ctx.chat.id, message, {parse_mode: "Markdown"});
console.log("--> sent the tags for the query: " + query);
addToLogs("--> sent the tags for the query: " + query);
}
});
}).on("error", (err) => {
console.log(err);
addToLogs("--> error : " + err);
})
}
function r34(tag, ctx, bot) {
//
//Search for the tag on r34 and send a random image
//
if (blockedChannels.includes(ctx.chat.id)) {
bot.telegram.sendMessage(ctx.chat.id, "This command is disabled in this channel", {});
return;
}
console.log("--> r34 query: " + tag);
addToLogs("--> r34 query: " + tag);
https.get('https://api.rule34.xxx/index.php?page=dapi&s=post&q=index&json=1&tags=' + tag, (resp) => {
let data = '';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
if (data == "") {
console.log("--> no images found for the query: " + tag);
addToLogs("--> no images found for the query: " + tag);
bot.telegram.sendMessage(ctx.chat.id, "No images found for the query: " + tag + "\nUse /r34tag command to find a tag before searching an image", {});
} else {
res = JSON.parse(data);
bot.telegram.sendPhoto(ctx.chat.id, res[Math.floor(Math.random() * res.length)].file_url, {"caption": "This is a random image for the tag : " + tag}).catch(err => {
console.log(err);
addToLogs("--> error : " + err);
bot.telegram.sendMessage(ctx.chat.id, "Something went wrong", {});
});
}
});
}).on("error", (err) => {
console.log("Error: " + err.message);
addToLogs("--> error : " + err);
bot.telegram.sendMessage(ctx.chat.id, "Something went wrong", {});
});
}
module.exports = { rtag, r34 };