Skip to content

Commit

Permalink
Merge pull request #240 from MoC-OSS/feature/UABOT-88_hide_join_and_l…
Browse files Browse the repository at this point in the history
…eave

[Feature] [UABOT-88] Hide join and leave messages
  • Loading branch information
DrSmile444 authored Dec 2, 2022
2 parents 44af97c + bcf3b2e commit 0f88366
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
getBeforeAnyComposer,
getCreatorCommandsComposer,
getHealthCheckComposer,
getJoinLeaveComposer,
getMessagesComposer,
getPrivateCommandsComposer,
getPublicCommandsComposer,
Expand Down Expand Up @@ -134,6 +135,9 @@ const rootMenu = new Menu<GrammyMenuContext>('root');
updateMethod: swindlersGoogleService.appendTrainingPositives.bind(swindlersGoogleService),
});

// Join and leave composer
const { joinLeaveComposer } = getJoinLeaveComposer();

// Tensor testing old logic
const { tensorTrainingComposer } = getTensorTrainingComposer({
tensorListener,
Expand Down Expand Up @@ -204,6 +208,9 @@ const rootMenu = new Menu<GrammyMenuContext>('root');
bot.use(swindlerBotsSaveToSheetComposer);
bot.use(swindlerHelpSaveToSheetComposer);

// Join and leave composer
bot.use(joinLeaveComposer);

// Tensor testing old logic
bot.use(tensorTrainingComposer);

Expand Down
2 changes: 2 additions & 0 deletions src/bot/commands/public/settings.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
deleteForwardedButton,
deleteMentionButton,
deleteMessageButton,
deleteServiceMessageButton,
deleteSwindlerButton,
deleteTensorButton,
deleteUrlsButton,
Expand Down Expand Up @@ -90,6 +91,7 @@ export class SettingsCommand {
.row()
.text(deleteMentionButton, (context) => toggleSetting(context, 'enableDeleteMentions'))
.text(deleteForwardedButton, (context) => toggleSetting(context, 'enableDeleteForwards'))
.text(deleteServiceMessageButton, (context) => toggleSetting(context, 'disableDeleteServiceMessage'))
.row()
.text(airAlarmAlertButton, isAlarmNow, async (context) => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down
1 change: 1 addition & 0 deletions src/bot/composers/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './before-any.composer';
export * from './creator-command.composer';
export * from './health-check.composer';
export * from './join-leave.composer';
export * from './messages.composer';
export * from './private-command.composer';
export * from './public-command.composer';
Expand Down
26 changes: 26 additions & 0 deletions src/bot/composers/join-leave.composer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Composer } from 'grammy';

import type { GrammyContext } from '../../types';
import { onlyNotDeletedFilter } from '../filters';

/**
* @description Remove join and leave messages from chat
* */
export const getJoinLeaveComposer = () => {
const joinLeaveComposer = new Composer<GrammyContext>();

joinLeaveComposer
// Filter that feature is enabled
.filter((context) => !context.chatSession.chatSettings.disableDeleteServiceMessage)
// Filter if the message is already deleted
.filter((context) => onlyNotDeletedFilter(context))
// Queries to filter
.on([':new_chat_members', ':left_chat_member'])
// Delete message
.use(async (context, next) => {
await context.deleteMessage();
return next();
});

return { joinLeaveComposer };
};
9 changes: 8 additions & 1 deletion src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ export const getSettingsMenuMessage = (settings: ChatSessionData['chatSettings']
${settings.enableDeleteMentions ? '✅ Бот видаляє повідомлення зі @ згадуваннями.' : '⛔ Бот не видаляє повідомлення зі @ згадуваннями.'}
↩️ ${settings.enableDeleteForwards ? '✅ Бот видаляє повідомлення з пересиланнями.' : '⛔ Бот не видаляє повідомлення з пересиланнями.'}
${
settings.disableDeleteServiceMessage
? '⛔ Бот не видаляє повідомлення приєдання та прощання.'
: '✅ Бот видаляє повідомлення приєдання та прощання.'
}
<b>Налаштування повітряної тривоги.</b>
🏰 ${
Expand Down Expand Up @@ -231,6 +236,7 @@ export const deleteUrlsButton = '🔗 Посилання';

export const deleteMentionButton = '⚓ Згадування';
export const deleteForwardedButton = '↩️ Пересилання';
export const deleteServiceMessageButton = '✋ Приєднання';

export const airAlarmAlertButton = '🏰 Регіон';
export const airAlarmNotificationMessage = '📢 Тривога';
Expand All @@ -244,10 +250,11 @@ export const englishDeleteMessageButton = '❗ Reason';
export const englishDeleteSwindlerButton = '💰 Scam';

export const englishDeleteCardsButton = '💳 Cards';

export const englishDeleteUrlsButton = '🔗 Link';

export const englishDeleteMentionButton = '⚓ Mention';
export const englishDeleteForwardedButton = '↩️ Forward';
export const englishDeleteServiceMessageButton = '✋ Join';

export const englishAirAlarmAlertButton = '🏰 Region';
export const englishAirAlarmNotificationMessage = '📢 Alarm';
Expand Down
1 change: 1 addition & 0 deletions src/types/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface DefaultChatSettings {
disableStrategicInfo?: boolean;
disableDeleteMessage?: boolean;
disableSwindlerMessage?: boolean;
disableDeleteServiceMessage?: boolean;
}

export interface OptionalChatSettings {
Expand Down

0 comments on commit 0f88366

Please sign in to comment.