1
0

♻️ Extract highlight message logic to server

This commit is contained in:
2022-01-05 20:05:18 +01:00
parent e3dfe80cc4
commit 5d20cce62f
3 changed files with 45 additions and 24 deletions

View File

@@ -0,0 +1,41 @@
import { LOG_PREFIX } from "..";
import { RedemptionMessage } from "../../../interfaces/RedemptionMessage";
import { broadcast } from "../../helpers/webServer";
import { getUsernameFromId } from "../../helpers/twitch";
import { timeout } from "../../chatClient/clientActions";
async function highlightMessage(msg: RedemptionMessage): Promise<void> {
if (!msg.message) {
console.log(`${LOG_PREFIX}Redemption has no message`);
return;
}
const urlRegex =
/(https?:\/\/)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&/=]*)/;
if (urlRegex.test(msg.message)) {
console.log(`${LOG_PREFIX}Message contains a url`);
const channel = await getUsernameFromId(parseInt(msg.channelId));
if (!channel) {
console.log(`${LOG_PREFIX}No channel found`);
return;
}
try {
const reason = "No se permite enviar enlaces en mensajes destacados";
await timeout(channel, msg.userDisplayName, 10, reason);
} catch (e) {
// user probably cannot be timed out
}
return;
}
broadcast(JSON.stringify(msg));
}
export { highlightMessage };

View File

@@ -7,6 +7,7 @@ import { broadcast } from "../helpers/webServer";
import { getApiClient } from "../helpers/twitch";
import { getVip } from "./actions/getVip";
import { hidrate } from "./actions/hidrate";
import { highlightMessage } from "./actions/highlightMessage";
import { russianRoulette } from "./actions/russianRoulette";
import { stealVip } from "./actions/stealVip";
import { timeoutFriend } from "./actions/timeoutFriend";
@@ -52,6 +53,9 @@ async function onRedemption(message: PubSubRedemptionMessage) {
case RedemptionIds.TimeoutFriend:
await timeoutFriend(msg);
break;
case RedemptionIds.HighlightMessage:
await highlightMessage(msg);
break;
case RedemptionIds.GetVip:
msg.message = `@${msg.userDisplayName} ha encontrado diamantes!`;