useless utils update

This commit is contained in:
Histmy 2022-12-02 17:45:36 +01:00
parent 2e89310d2b
commit 433b7e19bb
3 changed files with 39 additions and 48 deletions

View File

@ -1,14 +1,16 @@
import { ActionRowBuilder, ButtonBuilder, ButtonStyle, ChannelType, Client, ComponentType, GatewayIntentBits, Message, Partials } from "discord.js";
import { readdirSync } from "fs";
import { CUser, EventSOn, KomandNaExport, Komand, ListenerFunkce, Modul, SRecord, SuperListenerFunkce, CustomKomandy } from "./utils/types";
import { adminLog, getFirstArg, formatCas, loadEnv, oddiakritikovat, sortArr, log } from "./utils/utils.js";
import { CUser, EventSOn, KomandNaExport, Komand, ListenerFunkce, Modul, SRecord, SuperListenerFunkce, CustomKomandy, RunFunkce } from "./utils/types";
import { adminLog, formatCas, oddiakritikovat, log } from "./utils/utils.js";
import levenshtein from "js-levenshtein";
import { emouty } from "./utils/emotes";
import { existsSync } from "fs";
const helpServer = require("./utils/helpServer");
const custom: CustomKomandy = require("./utils/customCommands");
loadEnv();
if (!existsSync("config.json")) throw new Error("config.json neexistuje");
process.env = { ...process.env, ...require("../../config.json") };
const ints = GatewayIntentBits;
const client = new Client({
@ -40,7 +42,15 @@ function zpracovatAliasyAKomandy(aliasi: SRecord<string>, naPoslani: KomandNaExp
if (arr && !arr.includes(a)) arr.push(a);
if (!arr) komandyNaPoslani[i].als = [a];
});
helpServer.cmds = sortArr([...komandyNaPoslani, ...naPoslani]);
helpServer.cmds = [...komandyNaPoslani, ...naPoslani].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
}
function getFirstArg(fn: RunFunkce | string) {
if (typeof fn != "function") return;
return fn.toString()
.match(/(?:function\s.*?)?\(([^)]*)\)|\w+ =>/)![1]
?.split(",")[1]
?.trim();
}
const runEvent = (name: string, args: unknown[]) => {

View File

@ -2,7 +2,7 @@
import { Client, Guild, Presence, User } from "discord.js";
import fetch from "node-fetch";
import { FakePresence, Modul, SRecord, StatusyINaFounu, UserChange, ZmenovejObjekt } from "../utils/types";
import { adminLog, log, statusOnFoun } from "../utils/utils";
import { adminLog, log } from "../utils/utils";
const statusy = { Offline: "0", Online: "1", Idle: "2", DND: "3", OnlinePhone: "11", IdlePhone: "12", DNDPhone: "13" };
const prepSend = (zmeny: UserChange[]) => {
@ -44,6 +44,29 @@ if (!process.env.ignorePresence) ziju();
const getRole = (status: StatusyINaFounu, server: Guild) =>
server.roles.cache.find(role => role.name === `Status${status}`);
function statusOnFoun(bef: FakePresence | null, aft: FakePresence) {
const role = { online: "Online", idle: "Idle", dnd: "DND", offline: "Offline" };
if (!bef) bef = { status: 'offline', clientStatus: {} };
const predAPo: StatusyINaFounu[] = [];
[bef, aft].forEach((s, i) => {
const mobile = s.clientStatus?.mobile;
const deskotopy = s.clientStatus?.web
? s.clientStatus.desktop == "online" ? s.clientStatus.desktop : s.clientStatus.web
: s.clientStatus?.desktop;
if (mobile && mobile != deskotopy && (!deskotopy || deskotopy == "idle")) {
predAPo[i] = `${role[mobile]}Phone` as StatusyINaFounu;
} else {
predAPo[i] = role[s.status] as StatusyINaFounu;
}
});
return predAPo;
};
const exp: Modul = {
// Změna rolí podle statusu a odeslání statusu

View File

@ -1,8 +1,7 @@
import { AudioPlayerStatus, AudioResource, createAudioPlayer, createAudioResource, entersState, getVoiceConnection, joinVoiceChannel, PlayerSubscription, StreamType, VoiceConnection, VoiceConnectionStatus } from "@discordjs/voice";
import { ChannelType, Client, Guild, StageChannel, User, VoiceChannel } from "discord.js";
import { once } from "events";
import { FakePresence, JoinHovna, KomandNaExport, MuzikaFace, RunFunkce, SRecord, StatusyINaFounu } from "./types";
import { existsSync } from "fs";
import { JoinHovna, MuzikaFace, SRecord } from "./types";
import { Readable } from "node:stream";
const pripojeni: SRecord<PlayerSubscription> = {};
@ -168,11 +167,6 @@ export const handlePrevVoice = (guild: Guild, prev: boolean | string) => {
joinVoice(prev, guild); // Byl jsem jinde
};
export function loadEnv() {
if (!existsSync("config.json")) throw new Error("config.json neexistuje");
process.env = { ...process.env, ...require("../../config.json") };
}
/**
* Returns absolute date in format `d. m. h:mm:ss`
* @param date Date object to convert
@ -193,18 +187,6 @@ export function adminLog(client: Client, text: string) {
}
}
export function sortArr(arr: KomandNaExport[]) {
return arr.sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
}
export function getFirstArg(fn: RunFunkce | string) {
if (typeof fn != "function") return;
return fn.toString()
.match(/(?:function\s.*?)?\(([^)]*)\)|\w+ =>/)![1]
?.split(",")[1]
?.trim();
}
export const getCurrentPlayer = (guildId: string) => pripojeni[guildId]?.player;
export const configureTimeAnouncment = (guild: string, state: boolean) => { timeAnouncability[guild] = state; };
@ -221,30 +203,6 @@ export function log(...content: (string | Error)[]) {
console.log(`[${d.getDate()}.${d.getMonth() + 1}. ${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}]:`, ...jo);
}
export const statusOnFoun = (bef: FakePresence | null, aft: FakePresence) => {
const role = { online: "Online", idle: "Idle", dnd: "DND", offline: "Offline" };
if (!bef) bef = { status: 'offline', clientStatus: {} };
const predAPo: StatusyINaFounu[] = [];
[bef, aft].forEach((s, i) => {
const mobile = s.clientStatus?.mobile;
const deskotopy = s.clientStatus?.web
? s.clientStatus.desktop == "online" ? s.clientStatus.desktop : s.clientStatus.web
: s.clientStatus?.desktop;
if (mobile && mobile != deskotopy && (!deskotopy || deskotopy == "idle")) {
predAPo[i] = `${role[mobile]}Phone` as StatusyINaFounu;
} else {
predAPo[i] = role[s.status] as StatusyINaFounu;
}
});
return predAPo;
};
export const getGuildConnection = (guildId: string) => pripojeni[guildId]?.connection;
export async function sendDM(user: User, txt: string) {
user.send(txt).catch(() => console.log(`dementovi ${user} nejde poslat DM`));
}