Skip to content

Commit f89e663

Browse files
committed
feat: improve reaction by sending it as a message, reply or just simply react
1 parent 731d735 commit f89e663

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

src/components/events/message.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,29 @@ export default async function (msg: Message, type: string) {
5959
if (!commandPrefixLess && prefix) return;
6060
if (msg.fromMe && prefix) return;
6161

62+
/*
63+
*
64+
* Override the default function
65+
* react(reaction: string) Promise<void>
66+
*/
67+
const originalReact = msg.react.bind(msg);
68+
msg.react = async (reaction: string): Promise<void> => {
69+
// add delay for more
70+
// humanly like interaction
71+
const min = 2000;
72+
const max = 6000;
73+
const randomMs = Math.floor(Math.random() * (max - min + 1)) + min;
74+
75+
await sleep(randomMs);
76+
const isEmoji = /.*[A-Za-z0-9].*/.test(reaction);
77+
78+
if (Math.random() < 0.5 && !isEmoji)
79+
if (Math.random() < 0.5)
80+
await client.sendMessage(msg.id.remote, reaction);
81+
else await msg.reply(reaction);
82+
else await originalReact(reaction);
83+
};
84+
6285
/*
6386
*
6487
* Process msg reaction
@@ -119,6 +142,13 @@ export default async function (msg: Message, type: string) {
119142
log.info("Message", lid, msg.body.slice(0, 150));
120143
msg.body = !bodyHasPrefix ? msg.body : msg.body.slice(commandPrefix.length);
121144

145+
/*
146+
*
147+
* Override the default function
148+
* reply(content: MessageContent,
149+
* chatId?: string,
150+
* options?: MessageSendOptions) Promise<Message>
151+
*/
122152
const originalReply = msg.reply.bind(msg);
123153
msg.reply = async (
124154
content: MessageContent,

0 commit comments

Comments
 (0)