pull/8/head
pineafan 3 years ago
parent 4c7825abc0
commit 4e42594915
No known key found for this signature in database
GPG Key ID: 0AEF25BAA0FB1C74

@ -1,6 +1,7 @@
Role all Role all
Server rules Server rules
verificationRequired on welcome verificationRequired on welcome
// TODO !IMPORTANT! URL + image hash + file hash database
ROLE MENU SETTINGS ROLE MENU SETTINGS

@ -32,7 +32,7 @@
"force-dev": "rm -rf dist && eslint . --fix; tsc-suppress && node --experimental-json-modules --enable-source-maps dist/index.js", "force-dev": "rm -rf dist && eslint . --fix; tsc-suppress && node --experimental-json-modules --enable-source-maps dist/index.js",
"lint": "echo 'Style checking...'; prettier --check .; echo 'Linting...'; eslint .; echo 'To auto-fix everything possible, please run `yarn lint-fix`'; true", "lint": "echo 'Style checking...'; prettier --check .; echo 'Linting...'; eslint .; echo 'To auto-fix everything possible, please run `yarn lint-fix`'; true",
"lint-fix": "echo 'Fixing eslint issues...'; eslint . --fix; echo 'Reformatting...'; prettier --write --loglevel warn --cache .; true", "lint-fix": "echo 'Fixing eslint issues...'; eslint . --fix; echo 'Reformatting...'; prettier --write --loglevel warn --cache .; true",
"lint-list": "echo 'Style checking...'; prettier --check .; echo 'Linting...'; eslint .; echo 'To view errors in more detail, please run `yarn lint`; true", "lint-list": "echo 'Style checking...'; prettier --check .; echo 'Linting...'; eslint .; echo 'To view errors in more detail, please run `yarn lint`'; true",
"setup": "node Installer.js" "setup": "node Installer.js"
}, },
"repository": { "repository": {

@ -52,12 +52,13 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
interaction.options.getChannel("channel") || interaction.options.getChannel("channel") ||
interaction.options.getString("message") interaction.options.getString("message")
) { ) {
let role: Role; let role: Role | null;
let ping: Role; let ping: Role | null;
const message = interaction.options.getString("message"); let channel: Channel | null;
const message: string | null = interaction.options.getString("message");
try { try {
role = interaction.options.getRole("role") as Role; role = interaction.options.getRole("role") as Role | null;
ping = interaction.options.getRole("ping") as Role; ping = interaction.options.getRole("ping") as Role | null;
} catch { } catch {
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
@ -69,9 +70,8 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
] ]
}); });
} }
let channel: Channel;
try { try {
channel = interaction.options.getChannel("channel") as Channel; channel = interaction.options.getChannel("channel") as Channel | null;
} catch { } catch {
return await interaction.editReply({ return await interaction.editReply({
embeds: [ embeds: [
@ -83,7 +83,13 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
] ]
}); });
} }
const options = {}; const options: {
role?: string;
ping?: string;
channel?: string;
message?: string;
} = {};
if (role) options.role = renderRole(role); if (role) options.role = renderRole(role);
if (ping) options.ping = renderRole(ping); if (ping) options.ping = renderRole(ping);
if (channel) options.channel = renderChannel(channel); if (channel) options.channel = renderChannel(channel);
@ -98,13 +104,25 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
if (confirmation.cancelled) return; if (confirmation.cancelled) return;
if (confirmation.success) { if (confirmation.success) {
try { try {
const toChange = {}; const toChange: {
"welcome.role"?: string;
"welcome.ping"?: string;
"welcome.channel"?: string;
"welcome.message"?: string;
} = {};
if (role) toChange["welcome.role"] = role.id; if (role) toChange["welcome.role"] = role.id;
if (ping) toChange["welcome.ping"] = ping.id; if (ping) toChange["welcome.ping"] = ping.id;
if (channel) toChange["welcome.channel"] = channel.id; if (channel) toChange["welcome.channel"] = channel.id;
if (message) toChange["welcome.message"] = message; if (message) toChange["welcome.message"] = message;
await client.database.guilds.write(interaction.guild.id, toChange); await client.database.guilds.write(interaction.guild!.id, toChange);
const list = { const list: {
memberId: ReturnType<typeof entry>;
changedBy: ReturnType<typeof entry>;
role?: ReturnType<typeof entry>;
ping?: ReturnType<typeof entry>;
channel?: ReturnType<typeof entry>;
message?: ReturnType<typeof entry>;
} = {
memberId: entry(interaction.user.id, `\`${interaction.user.id}\``), memberId: entry(interaction.user.id, `\`${interaction.user.id}\``),
changedBy: entry(interaction.user.id, renderUser(interaction.user)) changedBy: entry(interaction.user.id, renderUser(interaction.user))
}; };
@ -123,7 +141,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
}, },
list: list, list: list,
hidden: { hidden: {
guild: interaction.guild.id guild: interaction.guild!.id
} }
}; };
log(data); log(data);
@ -155,7 +173,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
} }
let lastClicked = null; let lastClicked = null;
while (true) { while (true) {
const config = await client.database.guilds.read(interaction.guild.id); const config = await client.database.guilds.read(interaction.guild!.id);
m = (await interaction.editReply({ m = (await interaction.editReply({
embeds: [ embeds: [
new EmojiEmbed() new EmojiEmbed()
@ -164,19 +182,19 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
`**Message:** ${config.welcome.message ? `\n> ${config.welcome.message}` : "*None set*"}\n` + `**Message:** ${config.welcome.message ? `\n> ${config.welcome.message}` : "*None set*"}\n` +
`**Role:** ${ `**Role:** ${
config.welcome.role config.welcome.role
? renderRole(await interaction.guild.roles.fetch(config.welcome.role)) ? renderRole(await interaction.guild!.roles.fetch(config.welcome.role))
: "*None set*" : "*None set*"
}\n` + }\n` +
`**Ping:** ${ `**Ping:** ${
config.welcome.ping config.welcome.ping
? renderRole(await interaction.guild.roles.fetch(config.welcome.ping)) ? renderRole(await interaction.guild!.roles.fetch(config.welcome.ping))
: "*None set*" : "*None set*"
}\n` + }\n` +
`**Channel:** ${ `**Channel:** ${
config.welcome.channel config.welcome.channel
? config.welcome.channel == "dm" ? config.welcome.channel == "dm"
? "DM" ? "DM"
: renderChannel(await interaction.guild.channels.fetch(config.welcome.channel)) : renderChannel(await interaction.guild!.channels.fetch(config.welcome.channel))
: "*None set*" : "*None set*"
}` }`
) )
@ -226,7 +244,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
i.deferUpdate(); i.deferUpdate();
if (i.customId == "clear-message") { if (i.customId == "clear-message") {
if (lastClicked == "clear-message") { if (lastClicked == "clear-message") {
await client.database.guilds.write(interaction.guild.id, { await client.database.guilds.write(interaction.guild!.id, {
"welcome.message": null "welcome.message": null
}); });
lastClicked = null; lastClicked = null;
@ -235,7 +253,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
} }
} else if (i.customId == "clear-role") { } else if (i.customId == "clear-role") {
if (lastClicked == "clear-role") { if (lastClicked == "clear-role") {
await client.database.guilds.write(interaction.guild.id, { await client.database.guilds.write(interaction.guild!.id, {
"welcome.role": null "welcome.role": null
}); });
lastClicked = null; lastClicked = null;
@ -244,7 +262,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
} }
} else if (i.customId == "clear-ping") { } else if (i.customId == "clear-ping") {
if (lastClicked == "clear-ping") { if (lastClicked == "clear-ping") {
await client.database.guilds.write(interaction.guild.id, { await client.database.guilds.write(interaction.guild!.id, {
"welcome.ping": null "welcome.ping": null
}); });
lastClicked = null; lastClicked = null;
@ -253,7 +271,7 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
} }
} else if (i.customId == "clear-channel") { } else if (i.customId == "clear-channel") {
if (lastClicked == "clear-channel") { if (lastClicked == "clear-channel") {
await client.database.guilds.write(interaction.guild.id, { await client.database.guilds.write(interaction.guild!.id, {
"welcome.channel": null "welcome.channel": null
}); });
lastClicked = null; lastClicked = null;
@ -261,14 +279,14 @@ const callback = async (interaction: CommandInteraction): Promise<unknown> => {
lastClicked = "clear-channel"; lastClicked = "clear-channel";
} }
} else if (i.customId == "set-channel-dm") { } else if (i.customId == "set-channel-dm") {
await client.database.guilds.write(interaction.guild.id, { await client.database.guilds.write(interaction.guild!.id, {
"welcome.channel": "dm" "welcome.channel": "dm"
}); });
lastClicked = null; lastClicked = null;
} }
} }
await interaction.editReply({ await interaction.editReply({
embeds: [m.embeds[0].setFooter({ text: "Message closed" })], embeds: [m.embeds[0]!.setFooter({ text: "Message closed" })],
components: [] components: []
}); });
}; };

@ -1,9 +1,13 @@
import type { GuildAuditLogsEntry } from "discord.js";
import type { GuildBasedChannel } from "discord.js";
// @ts-expect-error
import { HaikuClient } from "jshaiku";
export const event = "channelCreate"; export const event = "channelCreate";
export async function callback(client, channel) { export async function callback(client: HaikuClient, channel: GuildBasedChannel) {
const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = channel.client.logger; const { getAuditLog, log, NucleusColors, entry, renderUser, renderDelta, renderChannel } = client.logger;
const auditLog = await getAuditLog(channel.guild, "CHANNEL_CREATE"); const auditLog = await getAuditLog(channel.guild, "CHANNEL_CREATE");
const audit = auditLog.entries.filter((entry) => entry.target.id === channel.id).first(); const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === channel.id).first();
if (audit.executor.id === client.user.id) return; if (audit.executor.id === client.user.id) return;
let emoji; let emoji;
let readableType; let readableType;
@ -27,7 +31,7 @@ export async function callback(client, channel) {
displayName = "Voice Channel"; displayName = "Voice Channel";
break; break;
} }
case "GUILD_STAGE": { case "GUILD_STAGE_VOICE": {
emoji = "CHANNEL.VOICE.CREATE"; emoji = "CHANNEL.VOICE.CREATE";
readableType = "Stage"; readableType = "Stage";
displayName = "Stage Channel"; displayName = "Stage Channel";

@ -1,7 +1,7 @@
import { import {
BaseGuildTextChannel, BaseGuildTextChannel,
BaseGuildVoiceChannel, GuildAuditLogsEntry,
GuildChannel, GuildBasedChannel,
StageChannel, StageChannel,
ThreadChannel, ThreadChannel,
VoiceChannel VoiceChannel
@ -11,10 +11,12 @@ import type { HaikuClient } from "jshaiku";
import getEmojiByName from "../utils/getEmojiByName.js"; import getEmojiByName from "../utils/getEmojiByName.js";
export const event = "channelDelete"; export const event = "channelDelete";
export async function callback(client: HaikuClient, channel: GuildBasedChannel) {
const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } = client.logger; const { getAuditLog, log, NucleusColors, entry, renderDelta, renderUser } = client.logger;
const auditLog = await getAuditLog(channel.guild, "CHANNEL_DELETE"); const auditLog = await getAuditLog(channel.guild, "CHANNEL_DELETE");
const audit = auditLog.entries.filter((entry) => entry.target.id === channel.id).first(); const audit = auditLog.entries.filter((entry: GuildAuditLogsEntry) => entry.target!.id === channel.id).first();
if (audit.executor.id === client.user.id) return; if (audit.executor.id === client.user.id) return;
let emoji; let emoji;
@ -46,15 +48,15 @@ export const event = "channelDelete";
} }
} }
const list: { const list: {
channelId: string; channelId: { value: string; displayValue: string };
name: string; name: { value: string; displayValue: string };
topic?: string | null; topic?: { value: string; displayValue: string } | null;
type: any; type: { value: string; displayValue: string };
category: any; category: { value: string; displayValue: string };
nsfw?: boolean | null; nsfw?: { value: string; displayValue: string } | null;
created: any; created: { value: string; displayValue: string };
deleted: any; deleted: { value: string; displayValue: string };
deletedBy: any; deletedBy: { value: string; displayValue: string };
} = { } = {
channelId: entry(channel.id, `\`${channel.id}\``), channelId: entry(channel.id, `\`${channel.id}\``),
name: entry(channel.id, `${channel.name}`), name: entry(channel.id, `${channel.name}`),

@ -4,7 +4,6 @@ import {
Message, Message,
MessageActionRow, MessageActionRow,
MessageButton, MessageButton,
PartialGroupDMChannel,
TextChannel TextChannel
} from "discord.js"; } from "discord.js";
import EmojiEmbed from "../utils/generateEmojiEmbed.js"; import EmojiEmbed from "../utils/generateEmojiEmbed.js";
@ -17,7 +16,7 @@ const pbClient = new PasteClient(config.pastebinApiKey);
export default async function (interaction: CommandInteraction) { export default async function (interaction: CommandInteraction) {
if (interaction.channel === null) return; if (interaction.channel === null) return;
if (interaction.channel instanceof DMChannel) return; if (!(interaction.channel instanceof TextChannel)) return;
const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger; const { log, NucleusColors, entry, renderUser, renderDelta } = client.logger;
let messages: Message[] = []; let messages: Message[] = [];
@ -44,18 +43,19 @@ export default async function (interaction: CommandInteraction) {
out += "\n\n"; out += "\n\n";
} }
}); });
const member = interaction.channel.guild.members.cache.get(interaction.channel.topic.split(" ")[0]); const member = interaction.guild!.members.cache.get(interaction.channel.topic.split(" ")[0]);
let m; let m;
if (out !== "") { if (out !== "") {
const url = await pbClient.createPaste({ const url = await pbClient.createPaste({
code: out, code: out,
expireDate: ExpireDate.Never, expireDate: ExpireDate.Never,
name: `Ticket Transcript for ${member.user.username}#${member.user.discriminator} (Created at ${new Date( name: `Ticket Transcript ${member ? ("for " + member.user.username + "#" + member.user.discriminator + " ") : ""}` +
`(Created at ${new Date(
interaction.channel.createdTimestamp interaction.channel.createdTimestamp
).toDateString()})`, ).toDateString()})`,
publicity: Publicity.Unlisted publicity: Publicity.Unlisted
}); });
const guildConfig = await client.database.guilds.read(interaction.guild.id); const guildConfig = await client.database.guilds.read(interaction.guild!.id);
m = await interaction.reply({ m = await interaction.reply({
embeds: [ embeds: [
new EmojiEmbed() new EmojiEmbed()
@ -121,15 +121,15 @@ export default async function (interaction: CommandInteraction) {
timestamp: new Date().getTime() timestamp: new Date().getTime()
}, },
list: { list: {
ticketFor: entry( ticketFor: member ? entry(
interaction.channel.topic.split(" ")[0], member.id,
renderUser((await interaction.guild.members.fetch(interaction.channel.topic.split(" ")[0])).user) renderUser(member.user)
), ) : entry(null, "*Unknown*"),
deletedBy: entry(interaction.member.user.id, renderUser(interaction.member.user)), deletedBy: entry(interaction.member!.user.id, renderUser(interaction.member!.user)),
deleted: entry(new Date().getTime(), renderDelta(new Date().getTime())) deleted: entry(new Date().getTime(), renderDelta(new Date().getTime()))
}, },
hidden: { hidden: {
guild: interaction.guild.id guild: interaction.guild!.id
} }
}; };
log(data); log(data);

@ -24,7 +24,7 @@ export class Logger {
const delta = num2 - num1; const delta = num2 - num1;
return `${num1} -> ${num2} (${delta > 0 ? "+" : ""}${delta})`; return `${num1} -> ${num2} (${delta > 0 ? "+" : ""}${delta})`;
} }
entry(value: string, displayValue: string) { entry(value: string, displayValue: string): { value: string; displayValue: string } {
return { value: value, displayValue: displayValue }; return { value: value, displayValue: displayValue };
} }
renderChannel(channel: Discord.GuildChannel | Discord.ThreadChannel) { renderChannel(channel: Discord.GuildChannel | Discord.ThreadChannel) {

Loading…
Cancel
Save