forked from itsreimau/ckptw-wabot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.js
49 lines (45 loc) · 1.33 KB
/
handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const smpl = require('./lib/simple.js');
/**
* Handles requests based on the given options.
* @param {Object} ctx The context of the request.
* @param {Object} options The given options.
* @returns {Object} Object containing status and message if applicable, otherwise null.
*/
exports.handler = async (ctx, options) => {
const checkOptions = {
admin: {
function: async () => await smpl.isAdmin(ctx) === 0,
msg: global.msg.admin
},
botAdmin: {
function: async () => await smpl.isAdminOf(ctx) === 0,
msg: global.msg.botAdmin
},
group: {
function: async () => await smpl.isGroup(ctx) === 0,
msg: global.msg.group
},
owner: {
function: async () => await smpl.isOwner(ctx) === 0,
msg: global.msg.owner
},
private: {
function: async () => await smpl.isPrivate(ctx) === 0,
msg: global.msg.private
}
};
let status = false;
let message = null;
for (const option of Object.keys(options)) {
const checkOption = checkOptions[option];
if (await checkOption.function()) {
status = true;
message = checkOption.msg;
break;
}
}
return {
status,
message
};
}