Skip to content

Commit

Permalink
Handle batch upsert events
Browse files Browse the repository at this point in the history
Signed-off-by: Prince Mendiratta <[email protected]>
  • Loading branch information
Prince-Mendiratta committed Jul 27, 2022
1 parent 746fded commit d53723a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
18 changes: 18 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/BotsApp.ts",
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
}
]
}
62 changes: 32 additions & 30 deletions BotsApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,42 +162,44 @@ setInterval(() => {
if (upsert.type !== 'notify') {
return;
}
let chat: proto.IWebMessageInfo = upsert.messages[0];
let BotsApp: BotsApp = await resolve(chat, sock);
// console.log(BotsApp);
if (BotsApp.isCmd) {
let isBlacklist: boolean = await Blacklist.getBlacklistUser(BotsApp.sender, BotsApp.chatId);
const cleared: boolean = await clearance(BotsApp, client, isBlacklist);
if (!cleared) {
return;
}
const reactionMessage = {
react: {
text: "🪄",
key: chat.key,
for(const msg of upsert.messages){
let chat: proto.IWebMessageInfo = msg;
let BotsApp: BotsApp = await resolve(chat, sock);
// console.log(BotsApp);
if (BotsApp.isCmd) {
let isBlacklist: boolean = await Blacklist.getBlacklistUser(BotsApp.sender, BotsApp.chatId);
const cleared: boolean = await clearance(BotsApp, client, isBlacklist);
if (!cleared) {
return;
}
}
await sock.sendMessage(chat.key.remoteJid, reactionMessage);
console.log(chalk.redBright.bold(`[INFO] ${BotsApp.commandName} command executed.`));
const command = commandHandler.get(BotsApp.commandName);
var args = BotsApp.body.trim().split(/\s+/).slice(1);
if (!command) {
client.sendMessage(BotsApp.chatId, "```Woops, invalid command! Use``` *.help* ```to display the command list.```", MessageType.text);
return;
} else if (command && BotsApp.commandName == "help") {
try {
command.handle(client, chat, BotsApp, args, commandHandler);
const reactionMessage = {
react: {
text: "🪄",
key: chat.key,
}
}
await sock.sendMessage(chat.key.remoteJid, reactionMessage);
console.log(chalk.redBright.bold(`[INFO] ${BotsApp.commandName} command executed.`));
const command = commandHandler.get(BotsApp.commandName);
var args = BotsApp.body.trim().split(/\s+/).slice(1);
if (!command) {
client.sendMessage(BotsApp.chatId, "```Woops, invalid command! Use``` *.help* ```to display the command list.```", MessageType.text);
return;
} else if (command && BotsApp.commandName == "help") {
try {
command.handle(client, chat, BotsApp, args, commandHandler);
return;
} catch (err) {
console.log(chalk.red("[ERROR] ", err));
return;
}
}
try {
await command.handle(client, chat, BotsApp, args).catch(err => console.log("[ERROR] " + err));
} catch (err) {
console.log(chalk.red("[ERROR] ", err));
return;
}
}
try {
await command.handle(client, chat, BotsApp, args).catch(err => console.log("[ERROR] " + err));
} catch (err) {
console.log(chalk.red("[ERROR] ", err));
}
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"outDir": "./dist", /* Redirect output structure to the directory. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
"allowSyntheticDefaultImports": true,
"allowJs": true
"allowJs": true,
"sourceMap": true
},
"exclude": ["**/*.test.ts", "./dist/**/*"],

Expand Down

0 comments on commit d53723a

Please sign in to comment.