Skip to content

Commit

Permalink
auto reveal view once
Browse files Browse the repository at this point in the history
  • Loading branch information
binsarjr committed Feb 21, 2024
1 parent 9c55f12 commit 38b2f68
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Facades/WhatsappClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ export class WhatsappClient {
*/
const text = getMessageCaption(message.message);
if (handler.patterns) validatePatternMatch(text, handler.patterns);
if (!text) break;

if (handler instanceof MessageUpsertWithGemini) {
if (!text) break;

try {
const prompts = await createPrompt(text);
console.log("\n\n\n\n\n\n\n\n");
Expand Down
66 changes: 66 additions & 0 deletions src/Handler/AutoRevealOnceView.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import {
MessageUpsertType,
downloadMediaMessage,
proto,
} from "@whiskeysockets/baileys";
import type { ChatType } from "../Contracts/ChatType";
import { HandlerArgs } from "../Contracts/IEventListener";
import { MessageUpsert } from "../Facades/Events/Message/MessageUpsert";
import Queue from "../Facades/Queue";
import { sendMessageWTyping } from "../utils";

export class AutoRevealOnceView extends MessageUpsert {
chat: ChatType = "all";
type: MessageUpsertType | "all" = "all";
async handler({
socket,
props,
}: HandlerArgs<{
message: proto.IWebMessageInfo;
type: MessageUpsertType;
}>): Promise<void> {
const jid = props.message.key.remoteJid || "";

const isViewOnce = !!props.message.message?.viewOnceMessage;
if (isViewOnce) {
const image =
props.message.message?.viewOnceMessage?.message?.imageMessage;
const video =
props.message.message?.viewOnceMessage?.message?.videoMessage;
const caption = image?.caption || video?.caption;

let text = `👀 View Once Message Revealed 👀\n`;
if (caption) {
text += `Caption: ${caption}\n`;
}
const media = await downloadMediaMessage(props.message, "buffer", {});

text = text.trim();
if (image) {
Queue(() =>
sendMessageWTyping(
{
image: media as Buffer,
caption: text,
},
jid,
socket,
{ quoted: props.message }
)
);
} else if (video) {
Queue(() =>
sendMessageWTyping(
{
video: media as Buffer,
caption: text,
},
jid,
socket,
{ quoted: props.message }
)
);
}
}
}
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dotenv from "dotenv";
import { gracefulShutdown } from "node-schedule";
import { WhatsappClient } from "./Facades/WhatsappClient";
import { AutoRevealOnceView } from "./Handler/AutoRevealOnceView";
import { ClearDataStore } from "./Handler/ClearDataStore";
import { CobaButton } from "./Handler/CobaButton";
import { BalasanTerimaKasih } from "./Handler/Command/BalasanTerimaKasih";
Expand Down Expand Up @@ -46,6 +47,7 @@ client.addHandler(
client.addHandler(new SetKesibukkan(), new LagiFree(), new LagiDiChatHandler());
// client.addHandler(new JanganManggilDoang());
client.addHandler(new BalasanTerimaKasih());
client.addHandler(new AutoRevealOnceView());
client.addHandler(
new AddMember(),
new KickMember(),
Expand Down

0 comments on commit 38b2f68

Please sign in to comment.