♻️ Extract roussian roulette logic to server
This commit is contained in:
@@ -64,11 +64,6 @@ async function checkEvent(e) {
|
||||
case "a26c0d9e-fd2c-4943-bc94-c5c2f2c974e4":
|
||||
await highlightMessage(data);
|
||||
break;
|
||||
case "a215d6a0-2c11-4503-bb29-1ca98ef046ac":
|
||||
await giveTempVip(data);
|
||||
data.message = `@${data.userDisplayName} ha encontrado diamantes!`;
|
||||
await createCard(data.rewardName, data.message, data.backgroundColor, data.rewardImage);
|
||||
break;
|
||||
// robar el vip
|
||||
case "ac750bd6-fb4c-4259-b06d-56953601243b":
|
||||
await createCard(data.rewardName, data.message, data.backgroundColor, data.rewardImage);
|
||||
@@ -151,10 +146,9 @@ function karaokeTime(username, message) {
|
||||
|
||||
}
|
||||
|
||||
let rrAttemps = 0;
|
||||
function russianRoulette({ channelId, userId, userDisplayName }) {
|
||||
function russianRoulette({ userDisplayName, message }) {
|
||||
return new Promise(res => {
|
||||
const win = rando(5 - rrAttemps) !== 0;
|
||||
const gotShot = Boolean(message);
|
||||
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("alert");
|
||||
@@ -164,59 +158,22 @@ function russianRoulette({ channelId, userId, userDisplayName }) {
|
||||
|
||||
const p = createText();
|
||||
|
||||
if (win) {
|
||||
p.innerText = `${userDisplayName} ha sido afortunado y aún sigue entre nosotros`;
|
||||
rrAttemps = 0;
|
||||
} else {
|
||||
if (gotShot) {
|
||||
p.innerText = `${userDisplayName} se ha ido a un mundo mejor, siempre te recordaremos`;
|
||||
rrAttemps++;
|
||||
} else {
|
||||
p.innerText = `${userDisplayName} ha sido afortunado y aún sigue entre nosotros`;
|
||||
}
|
||||
|
||||
div.appendChild(img);
|
||||
div.appendChild(p);
|
||||
|
||||
img.onload = () => {
|
||||
const audio = createAudio(`/sfx/toy-gun/${win ? 'stuck' : 'shot'}.mp3`);
|
||||
const audio = createAudio(`/sfx/toy-gun/${gotShot ? 'shot' : 'stuck'}.mp3`);
|
||||
|
||||
document.body.appendChild(div);
|
||||
|
||||
const actions = [];
|
||||
if (!win) {
|
||||
if (gotShot) {
|
||||
img.classList.add("shoot");
|
||||
|
||||
actions.push({
|
||||
type: "timeout",
|
||||
userId,
|
||||
channelId,
|
||||
data: {
|
||||
username: userDisplayName,
|
||||
time: "60",
|
||||
reason: "F en la ruleta."
|
||||
}
|
||||
});
|
||||
|
||||
actions.push({
|
||||
type: "say",
|
||||
userId,
|
||||
channelId,
|
||||
data: {
|
||||
message: `PepeHands ${userDisplayName} no ha sobrevivido para contarlo.`
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
actions.push({
|
||||
type: "say",
|
||||
userId,
|
||||
channelId,
|
||||
data: {
|
||||
message: `rdCool Clap ${userDisplayName}`
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (actions.length > 0) {
|
||||
sendWsActions(actions);
|
||||
}
|
||||
|
||||
audio.onended = () => {
|
||||
@@ -270,19 +227,6 @@ async function highlightMessage(data) {
|
||||
await createCard(data.rewardName, data.message, data.backgroundColor, data.rewardImage);
|
||||
}
|
||||
|
||||
async function giveTempVip(data) {
|
||||
sendWsActions([{
|
||||
type: "addVip",
|
||||
userId: data.userId,
|
||||
channelId: data.channelId
|
||||
}, {
|
||||
scheduledAt: Date.now() + 1000 * 60 * 60 * 24 * 7,
|
||||
type: "removeVip",
|
||||
userId: data.userId,
|
||||
channelId: data.channelId
|
||||
}]);
|
||||
}
|
||||
|
||||
// send actions to be performed by the server
|
||||
function sendWsActions(actions) {
|
||||
if (!Array.isArray(actions)) {
|
||||
|
@@ -1,5 +0,0 @@
|
||||
function rando(a,b,e){var g=function(f){return"undefined"===typeof f},k=function(f){return"number"===typeof f&&!isNaN(f)},d=function(f){return!g(f)&&null!==f&&f.constructor===Array},c=function(){try{for(var f,q=[],r;30>(r="."+q.join("")).length;){f=(window.crypto||window.msCrypto).getRandomValues(new Uint32Array(5));for(var p=0;p<f.length;p++){var t=4E9>f[p]?f[p].toString().slice(1):"";0<t.length&&(q[q.length]=t)}}return Number(r)}catch(v){return Math.random()}};try{if(null!==a&&null!==b&&null!==
|
||||
e){if(g(a))return c();if(window.jQuery&&a instanceof jQuery&&g(b)){if(0==a.length)return!1;var n=rando(0,a.length-1);return{index:n,value:a.eq(n)}}if(k(a)&&k(b)&&"string"===typeof e&&"float"==e.toLowerCase().trim()){if(a>b){var m=b;b=a;a=m}return c()*(b-a)+a}if(d(a)&&0<a.length&&g(b)){var l=c()*a.length<<0;return{index:l,value:a[l]}}if("object"===typeof a&&g(b)){l=a;var h=Object.keys(l);if(0<h.length){var u=h[h.length*c()<<0];return{key:u,value:l[u]}}}if((!0===a&&!1===b||!1===a&&!0===b)&&g(e))return.5>
|
||||
rando();if(k(a)&&g(b))return 0<=a?rando(0,a):rando(a,0);if(k(a)&&"string"===typeof b&&"float"==b.toLowerCase().trim()&&g(e))return 0<=a?rando(0,a,"float"):rando(a,0,"float");if(k(a)&&k(b)&&g(e))return a>b&&(m=b,b=a,a=m),a=Math.floor(a),b=Math.floor(b),Math.floor(c()*(b-a+1)+a);if("string"===typeof a&&0<a.length&&g(b))return a.charAt(rando(0,a.length-1))}return!1}catch(f){return!1}}
|
||||
function randoSequence(a,b){var e=function(h){return"undefined"===typeof h},g=function(h){return"number"===typeof h&&!isNaN(h)},k=function(h){return!e(h)&&null!==h&&h.constructor===Array};try{if(e(a)||null===a||null===b)return!1;var d=[];if(window.jQuery&&a instanceof jQuery&&e(b)){if(0<a.length){d=randoSequence(0,a.length-1);for(var c=0;c<d.length;c++)d[c]={index:d[c],value:a.eq(d[c])}}return d}if(e(b))if(k(a)&&e(b))for(c=0;c<a.length;c++)d[d.length]={index:c,value:a[c]};else if("object"===typeof a&&
|
||||
e(b))for(var n in a)Object.prototype.hasOwnProperty.call(a,n)&&(d[d.length]={key:n,value:a[n]});else if("string"===typeof a&&e(b))for(c=0;c<a.length;c++)d[d.length]=a.charAt(c);else return g(a)&&e(b)?0<=a?randoSequence(0,a):randoSequence(a,0):!1;else{if(!g(a)||!g(b)||0<a%1||0<b%1)return!1;if(a>b){var m=b;b=a;a=m}for(c=a;c<=b;c++)d[d.length]=c}for(c=d.length-1;0<c;c--){var l=rando(c);m=d[c];d[c]=d[l];d[l]=m}return d}catch(h){return!1}};
|
Reference in New Issue
Block a user