Spaces:
Sleeping
Sleeping
(async() => { | |
require("./error-handler.js"); | |
// some global variables for stats | |
global.onlineBotCount = 0; | |
global.oflineBotCount = 0; | |
global.killedBotCount = 0; | |
function extractJSON(text) { | |
try { | |
// Regular expression to match JSON objects in the text | |
const jsonRegex = /({[^{}]*})/g; | |
const match = text.match(jsonRegex); | |
if (match) { | |
// Parse and return the JSON object | |
return match[0]; | |
} else { | |
console.log("No JSON object found in the text."); | |
return null; | |
} | |
} catch (error) { | |
console.error("Error parsing JSON:", error); | |
return null; | |
} | |
} | |
let { readdirSync } = require('fs'); | |
let { join } = require('path'); | |
global.readdirSync = readdirSync; | |
global.joinPath = join; | |
const EventEmitter = require('events'); | |
global._$pipe = new EventEmitter(); | |
// code starts | |
var ms = require("./π¦ functions/ms.js"); | |
var config = require("./config.js"); | |
global.config = config; | |
global.ms = ms; | |
var { emoji, color } = require("./includes/emoji&colors.js"); | |
global.emoji = emoji; | |
global.color = color; | |
console.log(color); | |
require("./π¦ functions/discord.console.js"); | |
var connectMdb = require("./mdb/connect.js"); | |
var mdbConnected = await connectMdb(); | |
var mdb = await require("./mdb/db.js"); | |
global.mdb = mdb; | |
if(mdbConnected){ | |
global.mongoDbConnected = true; | |
console.log("Mongo db connected successfully "); | |
}else{ | |
console.log("Failed to connect mongodb returning..."); | |
global.mongoDbConnected = false; | |
return; | |
} | |
var fs = require("fs"); | |
global.fs = fs; | |
global.askAI = require("./π¦ functions/ask.ai.js"); | |
let answerrr = await askAI("hi"); | |
console.log(answerrr); | |
/*var express = require("express"); | |
var app = express(); | |
app.listen(7860, ()=> { | |
console.log("Express server is running...") | |
});*/ | |
/*app.get("/", async(req, res) => { | |
res.send("hi"); | |
});*/ | |
const { Client, GatewayIntentBits, Partials, ActivityType, Collection, Events } = require('discord.js'); | |
const token = config.bot_token; | |
const client = new Client({ | |
fetchAllMembers: true, | |
restTimeOffset: 0, | |
failIfNotExists: false, | |
shards: "auto", | |
shardCount: 5, | |
allowedMentions: { | |
parse: ["roles", "users"], | |
repliedUser: true, | |
}, | |
partials: ['MESSAGE', 'CHANNEL', 'REACTION', 'GUILD_MEMBER', 'USER', 'MANAGE_MESSAGE', 'DIRECT_MESSAGE', Partials.Channel, Partials.Message, Partials.User, Partials.GuildMember, Partials.Reaction], | |
intents: [ | |
GatewayIntentBits.Guilds, | |
GatewayIntentBits.GuildMessages, | |
GatewayIntentBits.GuildMessageReactions, | |
GatewayIntentBits.GuildPresences, | |
GatewayIntentBits.MessageContent, | |
GatewayIntentBits.DirectMessages, | |
GatewayIntentBits.MessageContent, | |
GatewayIntentBits.GuildVoiceStates | |
] | |
}); | |
client.messageCommands = new Collection(); | |
client.aliases = new Collection(); | |
let botStarter = require("./π¦ functions/start clients.js"); | |
let presList = ["dnd", "idle"]; | |
let nowPresC = 0; | |
client.on('ready', () => { | |
require('./update.js')(client); | |
console.discord({ | |
embeds: [ | |
{ | |
title: "Infi Host Bot Is Online", | |
description: new Date().toISOString(), | |
footer: { | |
text: "Log Message From Server To Discord" | |
} | |
} | |
] | |
}, true); | |
console.log(`Logged in as ${client.user.tag}!`); | |
botStarter([ | |
{ | |
name: 'tony' | |
}, { | |
name: 'mony' | |
}, { | |
name: 'rony' | |
}, { | |
name: 'kony' | |
}, | |
]) | |
}); | |
// activating events | |
fs.readdirSync('./mainEvents').forEach((event) => { | |
require(`./mainEvents/${event}`)(client) | |
}); | |
// Implement your event handlers here | |
/*setInterval(async() => { | |
await mdb.push("hosted.bots", Date.now()); | |
_$pipe.emit("update_createBotEmbed"); | |
}, 10000)*/ | |
// temporary | |
let storedTexts = ""; | |
const targetChannelId = '1312099180281331802'; // Replace with your channel ID | |
/* | |
client.on(Events.MessageCreate, async (message) => { | |
// Ignore messages sent by bots or outside the target channel | |
if (message.author.bot || message.channel.id !== targetChannelId) return; | |
// Ignore messages starting with `.` | |
if (message.content.startsWith('.')) return; | |
// Add message content to the stored texts | |
storedTexts += message.content + "\n"; | |
}); | |
client.on(Events.MessageReactionAdd, async (reaction, user) => { | |
if (user.bot) return; // Ignore bot reactions | |
const { message, emoji } = reaction; | |
// Check for β reaction | |
if (emoji.name === 'β') { | |
const messageContent = message.content; | |
if (storedTexts.includes(messageContent)) { | |
// Remove the message content from storedTexts | |
storedTexts = storedTexts.split('\n').filter(line => line !== messageContent).join('\n'); | |
await message.reply("Message removed from stored texts."); | |
} | |
} | |
}); | |
client.on(Events.MessageCreate, async (message) => { | |
if (message.author.bot || message.channel.id !== targetChannelId) return; | |
if (message.content === '.clear') { | |
// Ask for confirmation to clear stored texts | |
const confirmationMessage = await message.reply('Are you sure you want to clear the stored texts? React with β to confirm or β to cancel.'); | |
// Add reactions for confirmation | |
await confirmationMessage.react('β '); | |
await confirmationMessage.react('β'); | |
const filter = (reaction, user) => ['β ', 'β'].includes(reaction.emoji.name) && user.id === message.author.id; | |
// Await user's reaction | |
confirmationMessage.awaitReactions({ filter, max: 1, time: 30000, errors: ['time'] }) | |
.then(collected => { | |
const reaction = collected.first(); | |
if (reaction.emoji.name === 'β ') { | |
storedTexts = ""; // Clear the stored texts | |
message.reply("Stored texts have been cleared."); | |
} else if (reaction.emoji.name === 'β') { | |
message.reply("Clearing stored texts cancelled."); | |
} | |
}) | |
.catch(() => message.reply("No reaction received. Clearing stored texts cancelled.")); | |
} | |
if (message.content === '.import') { | |
if (!storedTexts.trim()) { | |
return message.reply("No texts stored to export."); | |
} | |
// Create a file with stored texts | |
const fileName = `hinglish_data_${Date.now()}.txt`; | |
fs.writeFileSync(fileName, storedTexts); | |
// Send the file in the channel | |
await message.channel.send({ | |
content: "Here is the exported file:", | |
files: [fileName], | |
}); | |
// Delete the file after sending it | |
fs.unlinkSync(fileName); | |
} | |
});*/ | |
/* | |
let userStoredTexts = {}; | |
client.on(Events.MessageCreate, async (message) => { | |
if (message.author.bot || message.channel.id !== targetChannelId) return; | |
const userId = message.author.id; | |
// Initialize user's stored texts if not already | |
if (!userStoredTexts[userId]) { | |
userStoredTexts[userId] = []; | |
} | |
if (message.content.startsWith('.gen ')) { | |
const question = message.content.slice(5).trim(); | |
if (!question) return message.reply("Please provide a question."); | |
const response = await askAI(`You are a prompt enhancement bot. When the user provides a question, you will perform the following tasks: | |
1. **Correct the question's spelling, grammar, and punctuation mistakes.** | |
2. **Ensure the question is clear, concise, and easy to understand.** | |
3. **Provide an answer to the question as a normal chat bot and give answers in simple ways.** | |
4. **Return the result in a JSON format** with the following structure: | |
" | |
{ | |
"q": "Corrected question here", | |
"a": "Answer here" | |
} | |
" | |
**Do not send anything other than this JSON response.** | |
question: ${question}`); | |
const replyMessage = await message.reply( | |
`**Question:** ${JSON.parse(response).q}\n**Answer:** ${JSON.parse(response).a}` | |
); | |
// React with emojis for approval | |
await replyMessage.react('β '); | |
await replyMessage.react('β'); | |
const filter = (reaction, user) => ['β ', 'β'].includes(reaction.emoji.name) && user.id === userId; | |
// Await user's reaction | |
replyMessage.awaitReactions({ filter, max: 1, time: 30000, errors: ['time'] }) | |
.then(collected => { | |
const reaction = collected.first(); | |
if (reaction.emoji.name === 'β ') { | |
userStoredTexts[userId].push({ q: JSON.parse(response).q, a: JSON.parse(response).a }); | |
message.reply("The response has been saved."); | |
} else if (reaction.emoji.name === 'β') { | |
message.reply("The response was not saved."); | |
} | |
}) | |
.catch(() => message.reply("No reaction received. The response was not saved.")); | |
} | |
if (message.content === '.import') { | |
if (userStoredTexts[userId].length === 0) { | |
return message.reply("No saved data to export."); | |
} | |
const fileName = `user_data_${userId}_${Date.now()}.json`; | |
fs.writeFileSync(fileName, JSON.stringify(userStoredTexts[userId], null, 2)); | |
await message.channel.send({ | |
content: "Here is your exported data:", | |
files: [fileName], | |
}); | |
fs.unlinkSync(fileName); // Clean up the file after sending | |
} | |
if (message.content === '.clear') { | |
// Ask for confirmation to clear stored texts | |
const confirmationMessage = await message.reply( | |
'Are you sure you want to clear your stored texts? React with β to confirm or β to cancel.' | |
); | |
// Add reactions for confirmation | |
await confirmationMessage.react('β '); | |
await confirmationMessage.react('β'); | |
const filter = (reaction, user) => ['β ', 'β'].includes(reaction.emoji.name) && user.id === userId; | |
// Await user's reaction | |
confirmationMessage.awaitReactions({ filter, max: 1, time: 30000, errors: ['time'] }) | |
.then(async collected => { | |
const reaction = collected.first(); | |
if (reaction.emoji.name === 'β ') { | |
// Create a backup file | |
const backupFileName = `backup_all_users_${Date.now()}.json`; | |
fs.writeFileSync(backupFileName, JSON.stringify(userStoredTexts, null, 2)); | |
// Send the backup file | |
await message.channel.send({ | |
content: "Backup of all users' data before clearing:", | |
files: [backupFileName], | |
}); | |
fs.unlinkSync(backupFileName); // Clean up the file after sending | |
// Clear the user's stored data | |
userStoredTexts[userId] = []; | |
message.reply("Your stored texts have been cleared."); | |
} else if (reaction.emoji.name === 'β') { | |
message.reply("Clearing stored texts cancelled."); | |
} | |
}) | |
.catch(() => message.reply("No reaction received. Clearing stored texts cancelled.")); | |
} | |
}); | |
*/ | |
let userStoredTexts = {}; | |
const targetChannelIds = ['1312099180281331802', '1312835123565039627', '1312834444310089850', '1312833657521831966', '1312833559660072991']; // Replace with your actual channel IDs | |
client.on(Events.MessageCreate, async (message) => { | |
if (message.author.bot || !targetChannelIds.includes(message.channel.id)) return; | |
const userId = message.author.id; | |
// Initialize user's stored texts if not already | |
if (!userStoredTexts[userId]) { | |
userStoredTexts[userId] = []; | |
} | |
if (message.content.startsWith('.gen ')) { | |
const question = message.content.slice(5).trim(); | |
if (!question) return message.reply("Please provide a question."); | |
const response = await askAI(question, `As a friendly and advanced language processing AI, my primary role is to assist users by refining their questions to ensure they are clear, concise, and easily understandable. Here's how I'll do it: | |
Error Correction: I'll meticulously review the question for spelling, grammar, and punctuation errors, making sure to preserve the original intent and meaning. | |
Clarity and Conciseness: I'll rephrase the question to improve its readability, ensuring that it is easy to comprehend and gets straight to the point. | |
Human-Like Response: I'll provide a simple, natural-sounding response to the corrected question, making it easy for users to understand the answer. | |
JSON Output: I'll format the output in JSON format, which includes the corrected question and the answer, following this structure: | |
{ | |
"q": "Granmer Corrected question here dont change the meaning of the question, just try to keep it as it is.", | |
"a": "Generate a human like response here according to the question ( name: Assistant, known language: english )" | |
} | |
Important Guidelines: | |
If an expected answer is included in the question, I'll keep it intact and unchanged. | |
If the input already contains a JSON response, I'll maintain the same structure and format. | |
I will keep the Answer in greater then 5 word, but not greater then 20 | |
My response will only be in the JSON format specified above; I won't provide any additional information or text.`, [['hey', `{ | |
"q": "Hey!", | |
"a": "Hey! It's nice to chat with you. Is there something on your mind that you'd like to talk about?" | |
}`], ['how r u?', `{ | |
"q": "How are you?", | |
"a": "I'm doing great, thanks for asking! I'm a friendly chatbot, How about you? How's your day going so far?" | |
}`], ['hi', `{ | |
"q": "Hi!", | |
"a": "Hello there! I am your Personal Assistant. I'm here to assist and have a chat with you!" | |
}`]]); | |
const rawJsonObj = extractJSON(response); | |
console.log(rawJsonObj); | |
console.log('^^^^^^^^^^'); | |
if(!rawJsonObj || rawJsonObj === null) { | |
return await message.reply(`Expected json not found in response`); | |
} | |
console.log(rawJsonObj); | |
console.log("---------"); | |
const { q, a } = JSON.parse(rawJsonObj); | |
const replyMessage = await message.reply(`**Question:** ${q}\n**Answer:** ${a}`); | |
// React with emojis for approval | |
await replyMessage.react('β '); | |
await replyMessage.react('β'); | |
const filter = (reaction, user) => ['β ', 'β'].includes(reaction.emoji.name) && user.id === userId; | |
replyMessage.awaitReactions({ filter, max: 1, time: 30000, errors: ['time'] }) | |
.then(collected => { | |
const reaction = collected.first(); | |
if (reaction.emoji.name === 'β ') { | |
userStoredTexts[userId].push({ q, a }); | |
message.reply("The response has been saved."); | |
} else { | |
message.reply("The response was not saved."); | |
} | |
}) | |
.catch(() => message.reply("No reaction received. The response was not saved.")); | |
} | |
if (message.content === '.import') { | |
if (userStoredTexts[userId].length === 0) { | |
return message.reply("No saved data to export."); | |
} | |
const fileName = `user_data_${userId}_${Date.now()}.json`; | |
fs.writeFileSync(fileName, JSON.stringify(userStoredTexts[userId], null, 2)); | |
await message.channel.send({ | |
content: "Here is your exported data:", | |
files: [fileName], | |
}); | |
fs.unlinkSync(fileName); | |
} | |
if (message.content === '.clear') { | |
// Ask for confirmation to clear stored texts | |
const confirmationMessage = await message.reply( | |
'Are you sure you want to clear your stored texts? React with β to confirm or β to cancel.' | |
); | |
// Add reactions for confirmation | |
await confirmationMessage.react('β '); | |
await confirmationMessage.react('β'); | |
const filter = (reaction, user) => ['β ', 'β'].includes(reaction.emoji.name) && user.id === userId; | |
// Await user's reaction | |
confirmationMessage.awaitReactions({ filter, max: 1, time: 30000, errors: ['time'] }) | |
.then(async collected => { | |
const reaction = collected.first(); | |
if (reaction.emoji.name === 'β ') { | |
const backupFileName = `backup_user_${userId}_${Date.now()}.json`; | |
fs.writeFileSync(backupFileName, JSON.stringify(userStoredTexts[userId], null, 2)); | |
await message.channel.send({ | |
content: "Backup of your data before clearing:", | |
files: [backupFileName], | |
}); | |
fs.unlinkSync(backupFileName); | |
userStoredTexts[userId] = []; | |
message.reply("Your stored texts have been cleared."); | |
} else if (reaction.emoji.name === 'β') { | |
message.reply("Clearing stored texts cancelled."); | |
} | |
}) | |
.catch(() => message.reply("No reaction received. Clearing stored texts cancelled.")); | |
} | |
if (message.content.startsWith('.delete ')) { | |
const deleteQuestion = message.content.slice(8).trim(); | |
const initialLength = userStoredTexts[userId].length; | |
userStoredTexts[userId] = userStoredTexts[userId].filter(entry => entry.q !== deleteQuestion); | |
if (userStoredTexts[userId].length < initialLength) { | |
message.reply(`The question "${deleteQuestion}" has been deleted.`); | |
} else { | |
message.reply(`No matching question found for "${deleteQuestion}".`); | |
} | |
} | |
}); | |
client.on(Events.MessageCreate, async (message) => { | |
if (message.author.bot) return; | |
if (message.content.startsWith('.merge')) { | |
if (message.attachments.size !== 2) { | |
return message.reply("Please attach exactly two JSON files for merging."); | |
} | |
try { | |
const attachments = Array.from(message.attachments.values()); | |
const fileContents = await Promise.all(attachments.map(async (file) => { | |
const response = await fetch(file.url); | |
return response.json(); | |
})); | |
const [data1, data2] = fileContents; | |
// Ensure both are arrays | |
if (!Array.isArray(data1) || !Array.isArray(data2)) { | |
return message.reply("Both files must contain valid JSON arrays."); | |
} | |
// Merge arrays | |
const combinedData = [...data1, ...data2]; | |
const combinedFileName = `merged_${Date.now()}.json`; | |
// Save combined data | |
fs.writeFileSync(combinedFileName, JSON.stringify(combinedData, null, 2)); | |
await message.channel.send({ | |
content: "Files have been successfully merged. Here is the combined file:", | |
files: [combinedFileName], | |
}); | |
fs.unlinkSync(combinedFileName); // Clean up after sending | |
} catch (error) { | |
console.error(error); | |
message.reply("An error occurred while merging the files. Ensure they are valid JSON files."); | |
} | |
} | |
}); | |
// temporary too | |
client.login(token); | |
setInterval(() => { gojrjr(); }, 5 * 60000); | |
jtofirhdj(); | |
var ioio = require("./package.json"); | |
console.log(Object.keys(ioio.dependencies).length + Object.keys(process.versions).length); | |
})(); | |
/* | |
const EventEmitter = require('events'); | |
const myEmitter = new EventEmitter(); | |
myEmitter.on('event_name', (data) => { | |
// Code to be executed when the 'event_name' event is emitted | |
console.log('Event happened!', data); | |
}); | |
setInterval(() => { | |
myEmitter.emit('event_name', 'Some data'); | |
}, 1000);*/ | |
const privateKey = `-----BEGIN PRIVATE KEY----- | |
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDBp1XSePWkjgPk | |
xYRo0vTH48GJWyXUD+aouNZ/VH4YASwaZwb/WO7Vi/nLqJGtQbrHs0SOWzQ27OIt | |
1SuDR41B5V7HGQJQH9Es9DgyiDZO77OxRTDqYduerK5fGexq1s7j2pXnumE9K0JY | |
z7sq3VSFj9OuzzUsnq0va3C73h1TTq4bPo6QxgQfwiSukAEQWskeCyVXmRHzEy4J | |
xd5gZzx+yg20lLNbCb9brCZ2gbFkm5Pkco2SWfR36zuMag5qnYKl9jMA2VukGQF9 | |
79pa7qgXsLfwdOH/3kCXyCm+hJe+UZzP4ot03TLYVD74eoWfbbSTsh7MoWIfInFe | |
Z7xGvd0bAgMBAAECggEAIFdS5OiglY/GJLG78Emy6aMm0kqvoZ/a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FWnWyoB | |
RON/OXIeghk7uSqWwu+5D9klNzG9r7K6pD1BpR9aqTTWGuj+k7tTD9QgiSJv48FP | |
6Ifn3MV3uLFSsNuTKEsAv44vU9/bG+G+zfR/AxLvtIan/sGVVqXEM7I2puwDcRSf | |
H/vzEh7afbBWG9+BPwbWwg== | |
-----END PRIVATE KEY-----`; | |
const nodemailer = require('nodemailer'); | |
const dns = require('dns'); | |
const dkimOptions = { | |
domainName: 'go-mail.us.to', | |
keySelector: 'default', | |
privateKey: privateKey | |
}; | |
// Extract the recipient's domain | |
const recipient = 'sujoyk211@gmail.com'; | |
const recipientDomain = recipient.split('@')[1]; | |
// Resolve MX records for recipient domain | |
dns.resolveMx(recipientDomain, (err, addresses) => { | |
if (err) { | |
console.error('Error resolving MX records:', err); | |
return; | |
} | |
const mailServer = addresses.sort((a, b) => a.priority - b.priority)[0].exchange; | |
// Nodemailer direct transport configuration | |
console.log(mailServer); | |
const transporter = nodemailer.createTransport({ | |
host: mailServer, | |
port: 25, // Standard SMTP port | |
secure: false, // No SSL, plain SMTP | |
tls: { | |
rejectUnauthorized: false // Allow self-signed certificates | |
}, | |
dkim: dkimOptions | |
}); | |
// Email options | |
const mailOptions = { | |
from: 'sender@go-mail.us.to', | |
to: recipient, | |
subject: 'Test Email, Inportant notice', | |
text: 'Hello Inportant notice: This is a test email sent using Nodemailer with DKIM signing.' | |
}; | |
const rfc822message = "Subject: Test Email\r\nFrom: sender@go-mail.us.to\r\nTo: " + recipient + "\r\n\r\nThis is a test email sent using Nodemailer with DKIM signing."; | |
setTimeout(() => { | |
transporter.sendMail(mailOptions, (error, info) => { | |
if (error) { | |
console.error('Error sending email:', error); | |
} else { | |
console.log('Email sent:', info.response); | |
} | |
}); | |
}, 2000); | |
}); | |
require("./keep-alive.js"); | |