+ Move function dmSlice from functions to get_members
This commit is contained in:
kdh8219 2023-05-21 22:05:48 +09:00
parent 2c4556906f
commit 958756a9d4
No known key found for this signature in database
GPG key ID: 2B5B609E12BB4C19
2 changed files with 27 additions and 33 deletions

View file

@ -2,7 +2,7 @@ import { ChatInputCommandInteraction, SlashCommandBuilder } from "discord.js";
import firebase from "../../wrapper/firebase.js";
import mojangAPI from "../../wrapper/mojang-api.js";
import { TUser, dmSlice } from "../../functions.js";
import { TUser } from "../../functions.js";
export default {
data: new SlashCommandBuilder()
@ -49,6 +49,7 @@ export default {
} catch (e) {
tag = `Deleted User#0000`;
}
text += "- ";
text += `\`${nickname}\``;
text += `\`${tag}\``;
text += `[${member[0]}]`;
@ -70,3 +71,28 @@ export default {
await interaction.editReply("dm을 확인해주세요.");
},
};
function dmSlice(raw: string): string[] {
function slasher(txt: string): { front: string; end: string } {
let front = txt.slice(0, 2000);
let end = txt.slice(2000);
if (end) {
const IndexOfLastBlock = front.lastIndexOf("\n\n");
end = "" /* 공백문자 */ + front.slice(IndexOfLastBlock + 1) + end;
front = front.slice(0, IndexOfLastBlock);
}
return { front, end };
}
const output: string[] = [];
let slashed = slasher(raw);
while (true) {
output.push(slashed.front);
if (slashed.end) {
slashed = slasher(slashed.end);
} else {
return output;
}
}
}

View file

@ -13,38 +13,6 @@ export type TUser = {
discord_id: string; // id
minecraft_uuid: string; //uuid
};
export function dmSlice(raw: string): string[] {
const output: string[] = [];
function slasher(txt: string): { front: string; end: string } {
if (txt.length <= 2000) {
return {
front: txt,
end: null,
};
}
let front = txt.slice(0, 2000);
let end = txt.slice(2000, txt.length);
if (end) {
let toLastNextLine = front.slice(front.lastIndexOf("\n"), front.length);
front = front.slice(0, front.lastIndexOf("\n"));
end = toLastNextLine + end;
if (end.slice(0, 3) == "\n\n") {
end = "" /* 공백문자 */ + end;
}
}
return { front, end };
}
let slashed = slasher(raw);
while (true) {
output.push(slashed.front);
if (slashed.end) {
slashed = slasher(slashed.end);
} else {
return output;
}
}
}
export async function add_user(
interaction: ChatInputCommandInteraction,