♻️ Cleaned lots of code and change getvip implementation
getVip is no longer time limited, it will remove it once a limit of vip users is reached (to be implemented)
This commit is contained in:
@@ -1,18 +1,22 @@
|
||||
import { chatClient } from "../..";
|
||||
import { say } from "..";
|
||||
|
||||
// adds a user to vips
|
||||
async function addVip(
|
||||
channel: string,
|
||||
username: string,
|
||||
message?: string
|
||||
): Promise<void> {
|
||||
if (!message) {
|
||||
message = `Otorgado VIP a @${username}.`;
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
await chatClient.addVip(channel, username);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
await chatClient.addVip(channel, username);
|
||||
say(channel, message);
|
||||
if (message) {
|
||||
await say(channel, message);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export { addVip };
|
||||
|
27
src/backend/chatClient/clientActions/hasVip/index.ts
Normal file
27
src/backend/chatClient/clientActions/hasVip/index.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { chatClient } from "../..";
|
||||
|
||||
type CacheType = Record<string, Array<string>>;
|
||||
const cache: CacheType = {};
|
||||
|
||||
async function hasVip(channel: string, username: string): Promise<boolean> {
|
||||
if (!username) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!cache[channel]) {
|
||||
const vips = await chatClient.getVips(channel);
|
||||
|
||||
// * last VIP has a "." at the end of the username (bug on library?)
|
||||
cache[channel] = vips.map(vip => vip.replace(/\.$/, ""));
|
||||
|
||||
setTimeout(() => {
|
||||
delete cache[channel];
|
||||
}, 2500);
|
||||
}
|
||||
|
||||
const vips = cache[channel];
|
||||
|
||||
return vips.includes(username);
|
||||
}
|
||||
|
||||
export { hasVip };
|
@@ -1,6 +1,7 @@
|
||||
import { addVip } from "./addVip";
|
||||
import { hasVip } from "./hasVip";
|
||||
import { removeVip } from "./removeVip";
|
||||
import { say } from "./say";
|
||||
import { timeout } from "./timeout";
|
||||
|
||||
export { say, timeout, addVip, removeVip };
|
||||
export { say, timeout, addVip, removeVip, hasVip };
|
||||
|
@@ -1,18 +1,22 @@
|
||||
import { chatClient } from "../..";
|
||||
import { say } from "..";
|
||||
|
||||
// removes a user from vips
|
||||
async function removeVip(
|
||||
channel: string,
|
||||
username: string,
|
||||
message?: string
|
||||
): Promise<void> {
|
||||
if (!message) {
|
||||
message = `VIP de @${username} eliminado.`;
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
await chatClient.removeVip(channel, username);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
await chatClient.removeVip(channel, username);
|
||||
say(channel, message);
|
||||
if (message) {
|
||||
await say(channel, message);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export { removeVip };
|
||||
|
Reference in New Issue
Block a user