Skip to content

Commit

Permalink
Merge pull request #5 from binsarjr/refactor-mention-eligible
Browse files Browse the repository at this point in the history
feat: streamline mention logic in group actions by removing group sta…
  • Loading branch information
binsarjr authored Oct 4, 2024
2 parents abc7c93 + 90747fd commit 6ac16a1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 28 deletions.
12 changes: 3 additions & 9 deletions libs/whatsapp-action/src/group/mention-admin.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PrismaService } from '@app/prisma';
import { ReadMoreUnicode } from '@app/whatsapp/constants';
import { IsEligible } from '@app/whatsapp/decorators/is-eligible.decorator';
import { WhatsappMessage } from '@app/whatsapp/decorators/whatsapp-message.decorator';
import { WhatsappGroupAction } from '@app/whatsapp/interfaces/whatsapp.group.interface';
import { withSign, withSignRegex } from '@app/whatsapp/supports/flag.support';
import { getJid } from '@app/whatsapp/supports/message.support';
import { LIMITIED_QUEUE } from '@services/queue';
Expand All @@ -11,8 +12,7 @@ import type {
WAMessage,
WASocket,
} from '@whiskeysockets/baileys';
import { jidDecode, jidNormalizedUser } from '@whiskeysockets/baileys';
import { WhatsappGroupAction } from '@app/whatsapp/interfaces/whatsapp.group.interface';
import { jidDecode } from '@whiskeysockets/baileys';

@WhatsappMessage({
flags: [
Expand All @@ -29,13 +29,7 @@ export class MentionAdminAction extends WhatsappGroupAction {

@IsEligible()
async canMention(socket: WASocket, message: WAMessage) {
const groupStatus = await this.prisma.groupStatus.findFirst({
where: {
jid: jidNormalizedUser(getJid(message)),
},
});
// TODO: jika tidak ada settingan maka set default sebagai hanya saya
if (!groupStatus?.active) return !!message.key.fromMe;
if (message.key.fromMe) return true;

return await this.isAdmin(socket, message);
}
Expand Down
12 changes: 2 additions & 10 deletions libs/whatsapp-action/src/group/mention-all.action.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { PrismaService } from '@app/prisma/prisma.service';
import { ReadMoreUnicode } from '@app/whatsapp/constants';
import { IsEligible } from '@app/whatsapp/decorators/is-eligible.decorator';
import { WhatsappMessage } from '@app/whatsapp/decorators/whatsapp-message.decorator';
import { WhatsappGroupAction } from '@app/whatsapp/interfaces/whatsapp.group.interface';
import { withSign, withSignRegex } from '@app/whatsapp/supports/flag.support';
import { getJid } from '@app/whatsapp/supports/message.support';
import { LIMITIED_QUEUE } from '@services/queue';
import {
GroupMetadata,
jidDecode,
jidNormalizedUser,
MiscMessageGenerationOptions,
WAMessage,
WASocket,
} from '@whiskeysockets/baileys';
import { WhatsappGroupAction } from '@app/whatsapp/interfaces/whatsapp.group.interface';
import { IsEligible } from '@app/whatsapp/decorators/is-eligible.decorator';

@WhatsappMessage({
flags: [withSign('tagall'), withSignRegex('tagall .*')],
Expand All @@ -26,13 +25,6 @@ export class MentionAllAction extends WhatsappGroupAction {
@IsEligible()
async canMention(socket: WASocket, message: WAMessage) {
if (!!message.key.fromMe) return true;
const groupStatus = await this.prisma.groupStatus.findFirst({
where: {
jid: jidNormalizedUser(getJid(message)),
},
});
// TODO: jika tidak ada settingan maka set default sebagai hanya saya
if (!groupStatus?.active) return !!message.key.fromMe;

return await this.isAdmin(socket, message);
}
Expand Down
12 changes: 3 additions & 9 deletions libs/whatsapp-action/src/group/mention-member.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PrismaService } from '@app/prisma';
import { ReadMoreUnicode } from '@app/whatsapp/constants';
import { IsEligible } from '@app/whatsapp/decorators/is-eligible.decorator';
import { WhatsappMessage } from '@app/whatsapp/decorators/whatsapp-message.decorator';
import { WhatsappGroupAction } from '@app/whatsapp/interfaces/whatsapp.group.interface';
import { withSign, withSignRegex } from '@app/whatsapp/supports/flag.support';
import { getJid } from '@app/whatsapp/supports/message.support';
import { LIMITIED_QUEUE } from '@services/queue';
Expand All @@ -11,8 +12,7 @@ import type {
WAMessage,
WASocket,
} from '@whiskeysockets/baileys';
import { jidDecode, jidNormalizedUser } from '@whiskeysockets/baileys';
import { WhatsappGroupAction } from '@app/whatsapp/interfaces/whatsapp.group.interface';
import { jidDecode } from '@whiskeysockets/baileys';

@WhatsappMessage({
flags: [
Expand All @@ -29,13 +29,7 @@ export class MentionMemberAction extends WhatsappGroupAction {

@IsEligible()
async canMention(socket: WASocket, message: WAMessage) {
const groupStatus = await this.prisma.groupStatus.findFirst({
where: {
jid: jidNormalizedUser(getJid(message)),
},
});
// TODO: jika tidak ada settingan maka set default sebagai hanya saya
if (!groupStatus?.active) return !!message.key.fromMe;
if (!!message.key.fromMe) return true;

return await this.isAdmin(socket, message);
}
Expand Down

0 comments on commit 6ac16a1

Please sign in to comment.