forked from yusufusta/WhatsAsena
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.js
140 lines (116 loc) · 7.26 KB
/
admin.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* Copyright (C) 2020 Yusuf Usta.
Licensed under the GPL-3.0 License;
you may not use this file except in compliance with the License.
WhatsAsena - Yusuf Usta
*/
const {MessageType, GroupSettingChange} = require('@adiwajshing/baileys');
const Asena = require('../events');
const Language = require('../language');
const Lang = Language.getString('admin');
async function checkImAdmin(message, user = message.client.user.jid) {
var grup = await message.client.groupMetadata(message.jid);
var sonuc = grup['participants'].map((member) => {
if (member.id.split('@')[0] === user.split('@')[0] && member.isAdmin) return true; else; return false;
});
return sonuc.includes(true);
}
Asena.addCommand({pattern: 'ban ?(.*)', fromMe: true, onlyGroup: true, desc: Lang.BAN_DESC}, (async (message, match) => {
var im = await checkImAdmin(message);
if (!im) return await message.client.sendMessage(message.jid,Lang.IM_NOT_ADMIN,MessageType.text);
if (message.reply_message !== false) {
await message.client.sendMessage(message.jid,'@' + message.reply_message.data.participant.split('@')[0] + '```, ' + Lang.BANNED + '```', MessageType.text, {contextInfo: {mentionedJid: [message.reply_message.data.participant]}});
await message.client.groupRemove(message.jid, [message.reply_message.data.participant]);
} else if (message.reply_message === false && message.mention !== false) {
var etiketler = '';
message.mention.map(async (user) => {
etiketler += '@' + user.split('@')[0] + ',';
});
await message.client.sendMessage(message.jid,etiketler + '```, ' + Lang.BANNED + '```', MessageType.text, {contextInfo: {mentionedJid: message.mention}});
await message.client.groupRemove(message.jid, message.mention);
} else {
return await message.client.sendMessage(message.jid,Lang.GIVE_ME_USER,MessageType.text);
}
}));
Asena.addCommand({pattern: 'add(?: |$)(.*)', fromMe: true, onlyGroup: true, desc: Lang.ADD_DESC, usage: '.add 905xxxxxxxxx'}, (async (message, match) => {
var im = await checkImAdmin(message);
if (!im) return await message.client.sendMessage(message.jid,Lang.IM_NOT_ADMIN,MessageType.text);
if (match[1] !== '') {
match[1].split(' ').map(async (user) => {
await message.client.groupAdd(message.jid, [user + "@s.whatsapp.net"]);
await message.client.sendMessage(message.jid,'```' + user + ' ' + Lang.ADDED +'```');
});
} else {
return await message.client.sendMessage(message.jid,Lang.GIVE_ME_USER,MessageType.text);
}
}));
Asena.addCommand({pattern: 'promote ?(.*)', fromMe: true, onlyGroup: true, desc: Lang.PROMOTE_DESC}, (async (message, match) => {
var im = await checkImAdmin(message);
if (!im) return await message.client.sendMessage(message.jid,Lang.IM_NOT_ADMIN,MessageType.text);
if (message.reply_message !== false) {
var checkAlready = await checkImAdmin(message, message.reply_message.data.participant);
if (checkAlready) {
return await message.client.sendMessage(message.jid,Lang.ALREADY_PROMOTED, MessageType.text);
}
await message.client.sendMessage(message.jid,'@' + message.reply_message.data.participant.split('@')[0] + Lang.PROMOTED, MessageType.text, {contextInfo: {mentionedJid: [message.reply_message.data.participant]}});
await message.client.groupMakeAdmin(message.jid, [message.reply_message.data.participant]);
} else if (message.reply_message === false && message.mention !== false) {
var etiketler = '';
message.mention.map(async (user) => {
var checkAlready = await checkImAdmin(message, user);
if (checkAlready) {
return await message.client.sendMessage(message.jid,Lang.ALREADY_PROMOTED, MessageType.text);
}
etiketler += '@' + user.split('@')[0] + ',';
});
await message.client.sendMessage(message.jid,etiketler + Lang.PROMOTED, MessageType.text, {contextInfo: {mentionedJid: message.mention}});
await message.client.groupMakeAdmin(message.jid, message.mention);
} else {
return await message.client.sendMessage(message.jid,Lang.GIVE_ME_USER,MessageType.text);
}
}));
Asena.addCommand({pattern: 'demote ?(.*)', fromMe: true, onlyGroup: true, desc: Lang.DEMOTE_DESC}, (async (message, match) => {
var im = await checkImAdmin(message);
if (!im) return await message.client.sendMessage(message.jid,Lang.IM_NOT_ADMIN);
if (message.reply_message !== false) {
var checkAlready = await checkImAdmin(message, message.reply_message.data.participant.split('@')[0]);
if (!checkAlready) {
return await message.client.sendMessage(message.jid,Lang.ALREADY_NOT_ADMIN, MessageType.text);
}
await message.client.sendMessage(message.jid,'@' + message.reply_message.data.participant.split('@')[0] + Lang.DEMOTED, MessageType.text, {contextInfo: {mentionedJid: [message.reply_message.data.participant]}});
await message.client.groupDemoteAdmin(message.jid, [message.reply_message.data.participant]);
} else if (message.reply_message === false && message.mention !== false) {
var etiketler = '';
message.mention.map(async (user) => {
var checkAlready = await checkImAdmin(message, user);
if (!checkAlready) {
return await message.client.sendMessage(message.jid,Lang.ALREADY_NOT_ADMIN, MessageType.text);
}
etiketler += '@' + user.split('@')[0] + ',';
});
await message.client.sendMessage(message.jid,etiketler + Lang.DEMOTED, MessageType.text, {contextInfo: {mentionedJid: message.mention}});
await message.client.groupDemoteAdmin(message.jid, message.mention);
} else {
return await message.client.sendMessage(message.jid,Lang.GIVE_ME_USER,MessageType.text);
}
}));
Asena.addCommand({pattern: 'mute ?(.*)', fromMe: true, onlyGroup: true, desc: Lang.MUTE_DESC}, (async (message, match) => {
var im = await checkImAdmin(message);
if (!im) return await message.client.sendMessage(message.jid,Lang.IM_NOT_ADMIN,MessageType.text);
await message.client.groupSettingChange(message.jid, GroupSettingChange.messageSend, true);
await message.client.sendMessage(message.jid,Lang.MUTED,MessageType.text);
}));
Asena.addCommand({pattern: 'unmute ?(.*)', fromMe: true, onlyGroup: true, desc: Lang.UNMUTE_DESC}, (async (message, match) => {
var im = await checkImAdmin(message);
if (!im) return await message.client.sendMessage(message.jid,Lang.IM_NOT_ADMIN,MessageType.text);
await message.client.groupSettingChange(message.jid, GroupSettingChange.messageSend, false);
await message.client.sendMessage(message.jid,Lang.UNMUTED,MessageType.text);
}));
Asena.addCommand({pattern: 'invite ?(.*)', fromMe: true, onlyGroup: true, desc: Lang.INVITE_DESC}, (async (message, match) => {
var im = await checkImAdmin(message);
if (!im) return await message.client.sendMessage(message.jid,Lang.IM_NOT_ADMIN, MessageType.text);
var invite = await message.client.groupInviteCode(message.jid);
await message.client.sendMessage(message.jid,Lang.INVITE + ' https://chat.whatsapp.com/' + invite, MessageType.text);
}));
module.exports = {
checkImAdmin: checkImAdmin
};