♻️ Extract highlight message logic to server
This commit is contained in:
@@ -56,10 +56,6 @@ async function checkEvent(e) {
|
|||||||
case "a73247ee-e33e-4e9b-9105-bd9d11e111fc":
|
case "a73247ee-e33e-4e9b-9105-bd9d11e111fc":
|
||||||
await russianRoulette(data);
|
await russianRoulette(data);
|
||||||
break;
|
break;
|
||||||
// highlight message
|
|
||||||
case "a26c0d9e-fd2c-4943-bc94-c5c2f2c974e4":
|
|
||||||
await highlightMessage(data);
|
|
||||||
break;
|
|
||||||
// robar el vip
|
// robar el vip
|
||||||
case "ac750bd6-fb4c-4259-b06d-56953601243b":
|
case "ac750bd6-fb4c-4259-b06d-56953601243b":
|
||||||
await createCard(data.rewardName, data.message, data.backgroundColor, data.rewardImage);
|
await createCard(data.rewardName, data.message, data.backgroundColor, data.rewardImage);
|
||||||
@@ -175,26 +171,6 @@ function russianRoulette({ userDisplayName, message }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function highlightMessage(data) {
|
|
||||||
const urlRegex = /(https?:\/\/)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
|
|
||||||
|
|
||||||
if (urlRegex.test(data.message)) {
|
|
||||||
sendWsActions({
|
|
||||||
type: "timeout",
|
|
||||||
userId: data.userId,
|
|
||||||
channelId: data.channelId,
|
|
||||||
data: {
|
|
||||||
username: data.userDisplayName,
|
|
||||||
time: "10",
|
|
||||||
reason: "No esta permitido enviar enlaces en mensajes destacados."
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await createCard(data.rewardName, data.message, data.backgroundColor, data.rewardImage);
|
|
||||||
}
|
|
||||||
|
|
||||||
// send actions to be performed by the server
|
// send actions to be performed by the server
|
||||||
function sendWsActions(actions) {
|
function sendWsActions(actions) {
|
||||||
if (!Array.isArray(actions)) {
|
if (!Array.isArray(actions)) {
|
||||||
|
41
src/backend/pubSubClient/actions/highlightMessage.ts
Normal file
41
src/backend/pubSubClient/actions/highlightMessage.ts
Normal 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 };
|
@@ -7,6 +7,7 @@ import { broadcast } from "../helpers/webServer";
|
|||||||
import { getApiClient } from "../helpers/twitch";
|
import { getApiClient } from "../helpers/twitch";
|
||||||
import { getVip } from "./actions/getVip";
|
import { getVip } from "./actions/getVip";
|
||||||
import { hidrate } from "./actions/hidrate";
|
import { hidrate } from "./actions/hidrate";
|
||||||
|
import { highlightMessage } from "./actions/highlightMessage";
|
||||||
import { russianRoulette } from "./actions/russianRoulette";
|
import { russianRoulette } from "./actions/russianRoulette";
|
||||||
import { stealVip } from "./actions/stealVip";
|
import { stealVip } from "./actions/stealVip";
|
||||||
import { timeoutFriend } from "./actions/timeoutFriend";
|
import { timeoutFriend } from "./actions/timeoutFriend";
|
||||||
@@ -52,6 +53,9 @@ async function onRedemption(message: PubSubRedemptionMessage) {
|
|||||||
case RedemptionIds.TimeoutFriend:
|
case RedemptionIds.TimeoutFriend:
|
||||||
await timeoutFriend(msg);
|
await timeoutFriend(msg);
|
||||||
break;
|
break;
|
||||||
|
case RedemptionIds.HighlightMessage:
|
||||||
|
await highlightMessage(msg);
|
||||||
|
break;
|
||||||
case RedemptionIds.GetVip:
|
case RedemptionIds.GetVip:
|
||||||
msg.message = `@${msg.userDisplayName} ha encontrado diamantes!`;
|
msg.message = `@${msg.userDisplayName} ha encontrado diamantes!`;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user