mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-17 19:26:20 +00:00
[+] Join groups by invite code
This commit is contained in:
@@ -64,6 +64,15 @@ client.on('message', async msg => {
|
||||
} else {
|
||||
msg.reply('This command can only be used in a group!');
|
||||
}
|
||||
} else if(msg.body.startsWith('!join ')) {
|
||||
const inviteCode = msg.body.split(' ')[1];
|
||||
|
||||
try {
|
||||
const chat = await client.acceptInvite(inviteCode);
|
||||
msg.reply(`Joined *${chat.name}*!`);
|
||||
} catch(e) {
|
||||
msg.reply('That invite code seems to be invalid.');
|
||||
}
|
||||
} else if(msg.body == '!groupinfo') {
|
||||
let chat = await msg.getChat();
|
||||
if(chat.isGroup) {
|
||||
|
||||
@@ -175,6 +175,19 @@ class Client extends EventEmitter {
|
||||
return ChatFactory.create(this, chat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Accepts an invite by code
|
||||
* @param {string} inviteCode
|
||||
*/
|
||||
async acceptInvite(inviteCode) {
|
||||
const chat = await this.pupPage.evaluate(async inviteCode => {
|
||||
const chatId = await Store.Invite.sendJoinGroupViaInvite(inviteCode);
|
||||
return WWebJS.getChat(chatId._serialized);
|
||||
}, inviteCode);
|
||||
|
||||
return ChatFactory.create(this.client, chat);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Client;
|
||||
|
||||
@@ -13,6 +13,7 @@ exports.ExposeStore = (moduleRaidStr) => {
|
||||
window.Store.genId = window.mR.findModule((module) => module.default && typeof module.default === 'function' && module.default.toString().match(/crypto/))[0].default;
|
||||
window.Store.SendMessage = window.mR.findModule("addAndSendMsgToChat")[0];
|
||||
window.Store.MsgKey = window.mR.findModule((module) => module.default && module.default.fromString)[0].default;
|
||||
window.Store.Invite = window.mR.findModule("sendJoinGroupViaInvite")[0];
|
||||
}
|
||||
|
||||
exports.LoadUtils = () => {
|
||||
|
||||
Reference in New Issue
Block a user