[+] Join groups by invite code

This commit is contained in:
Pedro Lopez
2020-02-02 00:52:51 -04:00
parent a6cc5e5bf2
commit caa8598ec1
3 changed files with 23 additions and 0 deletions

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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 = () => {