♻️ Extract timeout friend 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;
|
||||||
// timeout a un amigo
|
|
||||||
case "638c642d-23d8-4264-9702-e77eeba134de":
|
|
||||||
await timeoutFriend(data);
|
|
||||||
break;
|
|
||||||
// highlight message
|
// highlight message
|
||||||
case "a26c0d9e-fd2c-4943-bc94-c5c2f2c974e4":
|
case "a26c0d9e-fd2c-4943-bc94-c5c2f2c974e4":
|
||||||
await highlightMessage(data);
|
await highlightMessage(data);
|
||||||
@@ -192,25 +188,6 @@ function russianRoulette({ userDisplayName, message }) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function timeoutFriend(data) {
|
|
||||||
const senderUser = data.userDisplayName;
|
|
||||||
const receptorUser = data.message.split(" ")[0];
|
|
||||||
|
|
||||||
sendWsActions({
|
|
||||||
type: "timeout",
|
|
||||||
userId: data.userId,
|
|
||||||
channelId: data.channelId,
|
|
||||||
data: {
|
|
||||||
username: receptorUser,
|
|
||||||
time: "60",
|
|
||||||
reason: `Timeout dado por @${senderUser} con puntos del canal.`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const cardMessage = `@${senderUser} ha expulsado a @${receptorUser} por 60 segundos.`;
|
|
||||||
await createCard(data.rewardName, cardMessage, data.backgroundColor, data.rewardImage);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function highlightMessage(data) {
|
async function highlightMessage(data) {
|
||||||
const urlRegex = /(https?:\/\/)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
|
const urlRegex = /(https?:\/\/)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/;
|
||||||
|
|
||||||
|
44
src/backend/pubSubClient/actions/timeoutFriend.ts
Normal file
44
src/backend/pubSubClient/actions/timeoutFriend.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
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 timeoutFriend(msg: RedemptionMessage): Promise<boolean> {
|
||||||
|
const { message, channelId, userDisplayName } = msg;
|
||||||
|
if (!msg.message) {
|
||||||
|
console.log(`${LOG_PREFIX}Redemption has no message`);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const channel = await getUsernameFromId(parseInt(channelId));
|
||||||
|
|
||||||
|
if (!channel) {
|
||||||
|
console.log(`${LOG_PREFIX}No channel found`);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const time = 60;
|
||||||
|
const reason = `Timeout dado por @${userDisplayName} con puntos del canal`;
|
||||||
|
|
||||||
|
try {
|
||||||
|
await timeout(channel, msg.message, time, reason);
|
||||||
|
|
||||||
|
msg.message = `@${userDisplayName} ha expulsado a @${message} por ${time} segundos`;
|
||||||
|
|
||||||
|
broadcast(JSON.stringify(msg));
|
||||||
|
} catch (e) {
|
||||||
|
// user can not be timed out
|
||||||
|
if (e instanceof Error) {
|
||||||
|
console.error(`${LOG_PREFIX} ${e.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { timeoutFriend };
|
@@ -8,6 +8,7 @@ import { getApiClient } from "../helpers/twitch";
|
|||||||
import { getVip } from "./actions/getVip";
|
import { getVip } from "./actions/getVip";
|
||||||
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";
|
||||||
|
|
||||||
const LOG_PREFIX = "[PubSub] ";
|
const LOG_PREFIX = "[PubSub] ";
|
||||||
|
|
||||||
@@ -48,6 +49,7 @@ async function onRedemption(message: PubSubRedemptionMessage) {
|
|||||||
await russianRoulette(msg);
|
await russianRoulette(msg);
|
||||||
break;
|
break;
|
||||||
case RedemptionIds.TimeoutFriend:
|
case RedemptionIds.TimeoutFriend:
|
||||||
|
await timeoutFriend(msg);
|
||||||
break;
|
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