decord/alpha/source/stores/SlowmodeStore.tsx
github-actions 97fd043558 chore: update source for alpha 347.5
Skipped 1 file(s) >100MB (GitHub limit): source/__polyfill/04xxx/module_4941.js (118.4 MB)
2026-09-19 06:52:51 +00:00

155 lines
5.3 KiB
TypeScript

// Module ID: 7921
// Function ID: 7922
// Name: SlowmodeStore
// Dependencies: [2041, 4395, 7922, 2036, 573, 1091, 504, 2]
// Module 7921 (SlowmodeStore)
import initializeDefault from "initialize" /* 504 */;
import DispatcherDefault from "Dispatcher" /* 573 */;
import DurationsDefault from "Durations" /* 1091 */;
import ChannelStore from "ChannelStore" /* 2041 */;
import PermissionStore from "PermissionStore" /* 4395 */;
const require = fn;
function setCooldown(channel, SendMessage, cooldownMs) {
_require = channel;
const slowmodeType = SendMessage;
if (null != dependencyMap[SendMessage][channel.id]) {
const timer = tmp3[SendMessage][channel.id].timer;
timer.stop();
const id = channel.id;
delete tmp2[tmp];
}
if (!obj.canBypassSlowmode(channel)) {
if (cooldownMs > 0) {
const _Date = Date;
const sum = cooldownMs + Date.now();
dependencyMap = sum;
const obj2 = { rateLimitPerUser: channel.rateLimitPerUser, cooldownMs, cooldownEndTimestamp: sum, timer: null };
const timeout = new require("Timers").Timeout();
obj2.timer = timeout;
tmp3[SendMessage][channel.id] = obj2;
const timer2 = tmp3[SendMessage][channel.id].timer;
timer2.start(1000, () => {
const obj = DispatcherDefault;
obj.dispatch({ type: "SLOWMODE_SET_COOLDOWN", channelId: id.id, slowmodeType, cooldownMs: Math.max(sum - Date.now(), 0) });
}, true);
}
}
}
function handleUploadCancel(channelId) {
const channel = ChannelStore.getChannel(channelId.channelId);
if (null != channel) {
setCooldown(channel, obj.SendMessage, 0);
}
return null != channel;
}
const SlowmodeType = { SendMessage: 0, [0]: "SendMessage", CreateThread: 1, [1]: "CreateThread" };
let dependencyMap = { [SlowmodeType.SendMessage]: {}, [SlowmodeType.CreateThread]: {} };
const Store = initializeDefault.Store;
class SlowmodeStore extends Store {
}
const prototype = SlowmodeStore.prototype;
prototype["initialize"] = function initialize() {
this.waitFor(ChannelStore, PermissionStore);
};
prototype["getSlowmodeCooldownGuess"] = function getSlowmodeCooldownGuess(id, CreateThread) {
let SendMessage = CreateThread;
if (CreateThread == null) {
SendMessage = obj.SendMessage;
}
let num = 0;
if (null != dependencyMap[SendMessage][id]) {
num = tmp3.cooldownMs;
}
return num;
};
prototype["isChannelOnCooldown"] = function isChannelOnCooldown(channel, CreateThread) {
return this.getSlowmodeCooldownGuess(channel.id, CreateThread) > 0 && channel.rateLimitPerUser > 0;
};
SlowmodeStore.displayName = "SlowmodeStore";
const slowmodeStore = new SlowmodeStore(DispatcherDefault, {
SLOWMODE_RESET_COOLDOWN: function handleSlowmodeResetCooldown(channelId) {
const channel = ChannelStore.getChannel(channelId.channelId);
if (null != channel) {
let num2 = 0;
if (0 !== channel.rateLimitPerUser) {
num2 = channel.rateLimitPerUser * DurationsDefault.Millis.SECOND + 100;
}
setCooldown(channel, channelId.slowmodeType, num2);
}
return false;
},
SLOWMODE_SET_COOLDOWN: function handleSlowmodeSetCooldown(cooldownMs) {
cooldownMs = cooldownMs.cooldownMs;
const channel = ChannelStore.getChannel(cooldownMs.channelId);
if (null == channel) {
return false;
} else {
let num2 = 0;
if (0 !== cooldownMs) {
num2 = cooldownMs + 100;
}
setCooldown(channel, cooldownMs.slowmodeType, num2);
}
},
UPLOAD_START: function handleUploadStart(channelId) {
const channel = ChannelStore.getChannel(channelId.channelId);
if (null != channel) {
let num2 = 0;
if (0 !== channel.rateLimitPerUser) {
num2 = channel.rateLimitPerUser * DurationsDefault.Millis.SECOND + 100;
}
setCooldown(channel, obj.SendMessage, num2);
}
return false;
},
UPLOAD_FAIL: handleUploadCancel,
UPLOAD_CANCEL_REQUEST: handleUploadCancel,
CHANNEL_UPDATES: function handleUpdateCooldown(channels) {
channels = channels.channels;
const items = [, ];
({ SendMessage: arr[0], CreateThread: arr[1] } = obj);
const item = items.forEach((item) => {
const iter = channels[Symbol.iterator]();
const nextResult = iter.next();
while (iter !== undefined) {
let tmp5 = closure_6[item][nextResult.id];
let tmp6 = tmp5;
let rateLimitPerUser = nextResult.rateLimitPerUser;
if (null != tmp5) {
if (tmp6.rateLimitPerUser !== rateLimitPerUser) {
let num;
let tmp9 = setCooldown;
if (tmp6 != null) {
num = tmp6.cooldownMs;
}
if (num == null) {
num = 0;
}
let tmp9Result = tmp9(tmp3, item, Math.min(num, rateLimitPerUser * DurationsDefault.Millis.SECOND));
}
}
continue;
}
});
},
LOGOUT: function clear() {
const items = [, ];
({ SendMessage: arr[0], CreateThread: arr[1] } = obj);
let item = items.forEach((item) => {
closure_0 = item;
const keys = Object.keys(dependencyMap[item]);
item = keys.forEach((item) => {
const timer = dependencyMap[closure_0][item].timer;
return timer.stop();
});
dependencyMap[item] = {};
});
}
});
const size = fn(2);
const result = size.fileFinishedImporting("stores/SlowmodeStore.tsx");
export default slowmodeStore;
export { SlowmodeType };