• If you need help or want to discuss things, you now can also join us on our Discord Server!
  • A first preview of the unlimited version of SinusBot can be found in the Upcoming Changes thread. A version for Windows will follow, but we don't have a release date, yet.

EN Help to save a output command in .txt file

Toca

Member
Hello,

I'm building a script that lists the names of people in specific rooms, followed by a number and the current date. Currently, the script is working perfectly, but the output is coming through TS3, and I would like it to save this output to a .txt file on the server. The server where I host the bot is Linux, and I have full access to it.

I've already tried using the 'fs' module, and the script stopped working. Does anyone have any ideas? Here's the script below.


registerPlugin({
name: 'ListaClientesSalaEspecifica',
version: '1.0',
engine: '>= 1.0.0',
backends: ['ts3'],
description: 'Lista clientes em uma sala específica do TeamSpeak',
author: 'Seu Nome',
vars: [
{
name: 'salaEspecifica',
title: 'Sala Específica',
type: 'string',
placeholder: 'Nome da sala a ser listada',
},
{
name: 'salaEspecifica02',
title: 'Sala Específica02',
type: 'string',
placeholder: 'Nome da sala a ser listada',
},
{
name: 'salaEspecifica03',
title: 'Sala Específica03',
type: 'string',
placeholder: 'Nome da sala a ser listada',
},
{
name: 'salaEspecifica04',
title: 'Sala Específica04',
type: 'string',
placeholder: 'Nome da sala a ser listada',
},
{
name: 'salaEspecifica05',
title: 'Sala Específica05',
type: 'string',
placeholder: 'Nome da sala a ser listada',
},
],
}, (_, config) => {
const command = require('command');
const backend = require('backend');

// Função para formatar a data como "dd-mm-aaaa"
function formatDate(date) {
const day = String(date.getDate()).padStart(2, '0');
const month = String(date.getMonth() + 1).padStart(2, '0'); // Mês começa em 0
const year = date.getFullYear();
return `${day}-${month}-${year}`;
}

// Cria o comando !listclients
command.createCommand('listclients')
.help('Lista clientes em uma sala específica do TeamSpeak')
.manual('Execute !listclients para obter a lista de clientes na sala configurada.')
.exec((client, args, reply) => {
const clients = backend.getClients();
const salaEspecifica = config.salaEspecifica;
const salaEspecifica02 = config.salaEspecifica02;
const salaEspecifica03 = config.salaEspecifica03;
const salaEspecifica04 = config.salaEspecifica04;
const salaEspecifica05 = config.salaEspecifica05;
if (clients.length === 0) {
reply('Não há clientes conectados.');
return;
}

const listaClientes = [];

const currentDate = new Date();
const formattedDate = formatDate(currentDate);

clients.forEach(cliente => {
const clientName = cliente.name();
const clientChannel = cliente.getChannels()[0]; // Pega a primeira sala do cliente

if (clientChannel && (clientChannel.name() === salaEspecifica || clientChannel.name() === salaEspecifica02 || clientChannel.name() === salaEspecifica03 || clientChannel.name() === salaEspecifica04 || clientChannel.name() === salaEspecifica05)) {
listaClientes.push(`${clientName}, 1, ${formattedDate}`);
}
});

if (listaClientes.length === 0) {
reply(`Nenhum cliente encontrado nas salas especificadas.`);
} else {
const listaCompleta = listaClientes.join('\n');
reply(listaCompleta);
}
});
});
 

Toca

Member
The issue has been resolved; the fs module needs to be added to the plugin's header as it is a protected module. After this addition, I was able to use some of its functions.
 
Top