AutoCallManu/index.js

33 lines
763 B
JavaScript
Raw Normal View History

import { launchWeb } from './web.js';
import { EventEmitter } from 'events';
import { loadDatabase } from './utils/database.js';
import dotenv from 'dotenv';
dotenv.config();
2023-12-06 08:46:58 +01:00
loadDatabase();
2023-12-06 08:46:58 +01:00
const submitEvent = new EventEmitter();
await launchWeb(submitEvent);
2023-12-06 08:46:58 +01:00
submitEvent.on("contacts/call", async (call) => {
2023-12-06 08:46:58 +01:00
let vote;
if (call.vote) {
2023-12-06 08:46:58 +01:00
console.log(`${call.phone} va voter`);
vote = 1;
} else {
console.log(`${call.phone} ne va pas voter`);
vote = 0;
}
await global.database.contacts.update(
{ vote: vote, called: 1 },
{ where: { phone: call.phone } },
);
2023-12-06 08:46:58 +01:00
});
submitEvent.on("contacts/add", (request) => {
2023-12-06 08:46:58 +01:00
console.log(request);
});
global.events = {
submitEvent: submitEvent,
}