decord/alpha/source/stores/SlowmodeStore.tsx

175 lines
5.7 KiB
TypeScript
Raw Normal View History

2026-10-03 08:58:59 +00:00
// Module ID: 7171
// Function ID: 7172
// Name: SlowmodeStore
2026-10-03 08:58:59 +00:00
// Dependencies: [2051, 4509, 7172, 2046, 584, 1102, 504, 2]
2026-07-20 16:05:17 +00:00
2026-10-03 08:58:59 +00:00
// Module 7171 (SlowmodeStore)
import get_initializedDefault from "get initialized" /* 504 */;
import DispatcherDefault from "Dispatcher" /* 584 */;
import DurationsDefault from "Durations" /* 1102 */;
import ChannelStore from "ChannelStore" /* 2051 */;
import PermissionStore from "PermissionStore" /* 4509 */;
import size from "module_2" /* 2 */;
const require = globalThis.__r;
let _require, dependencyMap;
2026-07-23 10:11:24 +00:00
function setCooldown(channel, SendMessage, cooldownMs) {
2026-10-03 08:58:59 +00:00
let timeout;
_require = channel;
const slowmodeType = SendMessage;
2026-10-03 08:58:59 +00:00
let tmp = closure_6;
if (null != closure_6[SendMessage][channel.id]) {
const timer = tmp[SendMessage][channel.id].timer;
2026-07-20 16:05:17 +00:00
timer.stop();
2026-10-03 08:58:59 +00:00
delete tmp[SendMessage][channel.id];
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
let obj = require("SlowmodeUtils");
const tmp3 = _require;
2026-07-28 08:39:19 +00:00
if (!obj.canBypassSlowmode(channel)) {
if (cooldownMs > 0) {
2026-07-20 16:05:17 +00:00
const _Date = Date;
const sum = cooldownMs + Date.now();
2026-08-24 06:08:38 +00:00
dependencyMap = sum;
2026-10-03 08:58:59 +00:00
const id = channel.id;
const self = this;
const self2 = this;
const obj2 = { rateLimitPerUser: channel.rateLimitPerUser, cooldownMs, cooldownEndTimestamp: sum, timer: timeout };
const tmp8 = tmp[SendMessage];
timeout = new tmp3(2046).Timeout();
tmp8[id] = obj2;
const timer2 = tmp[SendMessage][channel.id].timer;
2026-07-20 16:05:17 +00:00
timer2.start(1000, () => {
2026-10-03 08:58:59 +00:00
const dispatch = DispatcherDefault.dispatch;
const obj = { type: "SLOWMODE_SET_COOLDOWN", channelId: channel.id, slowmodeType, cooldownMs: Math.max(dependencyMap - Date.now(), 0) };
dispatch(obj);
2026-07-20 16:05:17 +00:00
}, true);
}
}
}
function handleUploadCancel(channelId) {
const channel = ChannelStore.getChannel(channelId.channelId);
2026-07-20 16:05:17 +00:00
if (null != channel) {
setCooldown(channel, obj.SendMessage, 0);
}
return null != channel;
}
const SlowmodeType = { SendMessage: 0, [0]: "SendMessage", CreateThread: 1, [1]: "CreateThread" };
2026-10-03 08:58:59 +00:00
let closure_6 = { [SlowmodeType.SendMessage]: {}, [SlowmodeType.CreateThread]: {} };
const Store = get_initializedDefault.Store;
2026-07-29 08:29:29 +00:00
class SlowmodeStore extends Store {
2026-10-03 08:58:59 +00:00
initialize() {
this.waitFor(ChannelStore, PermissionStore);
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
getSlowmodeCooldownGuess(id, CreateThread) {
let SendMessage = CreateThread;
const tmp = closure_6;
if (CreateThread == null) {
SendMessage = obj.SendMessage;
}
let num = 0;
if (null != tmp[SendMessage][id]) {
num = tmp3.cooldownMs;
}
return num;
2026-07-29 08:29:29 +00:00
}
2026-10-03 08:58:59 +00:00
isChannelOnCooldown(channel, CreateThread) {
const tmp = this.getSlowmodeCooldownGuess(channel.id, CreateThread) > 0 && channel.rateLimitPerUser > 0;
return tmp;
}
}
const prototype = SlowmodeStore.prototype;
2026-07-29 08:29:29 +00:00
SlowmodeStore.displayName = "SlowmodeStore";
2026-10-03 08:58:59 +00:00
let obj2 = {
SLOWMODE_RESET_COOLDOWN: function handleSlowmodeResetCooldown(slowmodeType) {
slowmodeType = slowmodeType.slowmodeType;
const channel = ChannelStore.getChannel(slowmodeType.channelId);
2026-07-29 08:29:29 +00:00
if (null != channel) {
let num2 = 0;
2026-10-03 08:58:59 +00:00
const tmp2 = setCooldown;
2026-07-29 08:29:29 +00:00
if (0 !== channel.rateLimitPerUser) {
num2 = channel.rateLimitPerUser * DurationsDefault.Millis.SECOND + 100;
2026-07-29 08:29:29 +00:00
}
2026-10-03 08:58:59 +00:00
tmp2(channel, slowmodeType, num2);
2026-07-29 08:29:29 +00:00
}
return false;
2026-07-20 16:05:17 +00:00
},
SLOWMODE_SET_COOLDOWN: function handleSlowmodeSetCooldown(cooldownMs) {
cooldownMs = cooldownMs.cooldownMs;
2026-10-03 08:58:59 +00:00
const slowmodeType = cooldownMs.slowmodeType;
const channel = ChannelStore.getChannel(cooldownMs.channelId);
2026-07-20 16:05:17 +00:00
if (null == channel) {
return false;
} else {
2026-07-29 08:29:29 +00:00
let num2 = 0;
2026-10-03 08:58:59 +00:00
const tmp2 = setCooldown;
2026-07-20 16:05:17 +00:00
if (0 !== cooldownMs) {
2026-07-29 08:29:29 +00:00
num2 = cooldownMs + 100;
2026-07-20 16:05:17 +00:00
}
2026-10-03 08:58:59 +00:00
tmp2(channel, slowmodeType, num2);
2026-07-20 16:05:17 +00:00
}
},
UPLOAD_START: function handleUploadStart(channelId) {
2026-10-03 08:58:59 +00:00
const SendMessage = obj.SendMessage;
const channel = ChannelStore.getChannel(channelId.channelId);
2026-07-29 08:29:29 +00:00
if (null != channel) {
let num2 = 0;
2026-10-03 08:58:59 +00:00
const tmp2 = setCooldown;
2026-07-29 08:29:29 +00:00
if (0 !== channel.rateLimitPerUser) {
num2 = channel.rateLimitPerUser * DurationsDefault.Millis.SECOND + 100;
2026-07-29 08:29:29 +00:00
}
2026-10-03 08:58:59 +00:00
tmp2(channel, SendMessage, num2);
2026-07-29 08:29:29 +00:00
}
return false;
2026-07-20 16:05:17 +00:00
},
UPLOAD_FAIL: handleUploadCancel,
UPLOAD_CANCEL_REQUEST: handleUploadCancel,
CHANNEL_UPDATES: function handleUpdateCooldown(channels) {
2026-07-23 10:11:24 +00:00
channels = channels.channels;
2026-07-29 08:29:29 +00:00
const items = [, ];
({ SendMessage: arr[0], CreateThread: arr[1] } = obj);
const item = items.forEach((item) => {
2026-07-29 08:29:29 +00:00
const iter = channels[Symbol.iterator]();
const nextResult = iter.next();
while (iter !== undefined) {
let tmp5 = closure_6[item][nextResult.id];
2026-07-29 08:29:29 +00:00
let tmp6 = tmp5;
let rateLimitPerUser = nextResult.rateLimitPerUser;
if (null != tmp5) {
if (tmp6.rateLimitPerUser !== rateLimitPerUser) {
let num;
let tmp9 = setCooldown;
2026-10-03 08:58:59 +00:00
let _Math = Math;
2026-07-29 08:29:29 +00:00
if (tmp6 != null) {
num = tmp6.cooldownMs;
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
if (num == null) {
num = 0;
}
2026-10-03 08:58:59 +00:00
let tmp9Result = tmp9(tmp3, item, min(num, rateLimitPerUser * DurationsDefault.Millis.SECOND));
2026-07-20 16:05:17 +00:00
}
2026-07-29 08:29:29 +00:00
}
continue;
2026-07-20 16:05:17 +00:00
}
});
},
LOGOUT: function clear() {
2026-07-29 08:29:29 +00:00
const items = [, ];
({ SendMessage: arr[0], CreateThread: arr[1] } = obj);
let item = items.forEach((item) => {
2026-10-03 08:58:59 +00:00
let closure_0 = item;
const keys = Object.keys(closure_6[item]);
item = keys.forEach((item) => {
2026-10-03 08:58:59 +00:00
const timer = closure_2_6[item][item].timer;
2026-07-20 16:05:17 +00:00
return timer.stop();
});
2026-10-03 08:58:59 +00:00
closure_6[item] = {};
2026-07-20 16:05:17 +00:00
});
}
2026-10-03 08:58:59 +00:00
};
const slowmodeStore = new SlowmodeStore(DispatcherDefault, obj2);
const result = size.fileFinishedImporting("stores/SlowmodeStore.tsx");
2026-07-20 16:05:17 +00:00
2026-07-29 08:29:29 +00:00
export default slowmodeStore;
export { SlowmodeType };