Compare commits
No commits in common. "8d1befcf25b4645472f70027414d8043c9b9c613" and "bc3c16bdcbb943d1e8b262f3adbd1c6a999fcf2b" have entirely different histories.
8d1befcf25
...
bc3c16bdcb
4 changed files with 3 additions and 112 deletions
|
@ -1,7 +1,5 @@
|
||||||
import {ChatInputCommandInteraction, CommandInteraction, EmbedBuilder, PermissionFlagsBits, SlashCommandBuilder} from "discord.js";
|
import {CommandInteraction, PermissionFlagsBits, SlashCommandBuilder} from "discord.js";
|
||||||
import {Command} from "../type/command";
|
import {Command} from "../type/command";
|
||||||
import TimeLengthInput from "../helpers/TimeLengthInput";
|
|
||||||
import AutoKickHelper from "../helpers/AutoKickHelper";
|
|
||||||
|
|
||||||
export default class Autokick extends Command {
|
export default class Autokick extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -48,66 +46,9 @@ export default class Autokick extends Command {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async set(interaction: ChatInputCommandInteraction) {
|
private async set(interaction: CommandInteraction) {
|
||||||
if (!interaction.guildId) return;
|
|
||||||
|
|
||||||
const roleOption = interaction.options.getRole("role", true);
|
|
||||||
const kickTimeOption = interaction.options.getString("kicktime", true);
|
|
||||||
const noticeTimeOption = interaction.options.getString("noticetime");
|
|
||||||
const noticeChannelOption = interaction.options.getChannel("noticechannel");
|
|
||||||
|
|
||||||
const roleId = roleOption.id;
|
|
||||||
const kickTimeInput = new TimeLengthInput(kickTimeOption);
|
|
||||||
const noticeTimeInput = noticeTimeOption ? new TimeLengthInput(noticeTimeOption) : undefined;
|
|
||||||
const noticeChannelId = noticeChannelOption?.id;
|
|
||||||
|
|
||||||
if ((noticeTimeInput && !noticeTimeOption) || (!noticeTimeInput && noticeChannelOption)) {
|
|
||||||
await interaction.reply("Both `noticetime` and `noticechannel` must be set if you want a notification embed");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await AutoKickHelper.SetSetting(interaction.guildId, roleId, kickTimeInput.GetMilliseconds(), noticeTimeInput?.GetMilliseconds(), noticeChannelId);
|
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
|
||||||
.setTitle("Auto Kick")
|
|
||||||
.setDescription("Configured auto kick for this server")
|
|
||||||
.addFields([
|
|
||||||
{
|
|
||||||
name: "Role",
|
|
||||||
value: roleOption.name,
|
|
||||||
inline: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Kick Time",
|
|
||||||
value: kickTimeInput.GetLengthShort(),
|
|
||||||
inline: true,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
if (noticeTimeInput) {
|
|
||||||
embed.addFields([
|
|
||||||
{
|
|
||||||
name: "Notice Time",
|
|
||||||
value: noticeTimeInput.GetLengthShort(),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Notice Channel",
|
|
||||||
value: noticeChannelOption!.name!,
|
|
||||||
inline: true,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
await interaction.reply({
|
|
||||||
embeds: [ embed ],
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async unset(interaction: ChatInputCommandInteraction) {
|
private async unset(interaction: CommandInteraction) {
|
||||||
if (!interaction.guildId) return;
|
|
||||||
|
|
||||||
await AutoKickHelper.UnsetSetting(interaction.guildId);
|
|
||||||
|
|
||||||
await interaction.reply("Unset the auto kick configuration for this server");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,15 +47,4 @@ export default class AutoKickConfig extends BaseEntity {
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async FetchAllByServerId(serverId: string): Promise<AutoKickConfig[]> {
|
|
||||||
const repository = AppDataSource.getRepository(AutoKickConfig);
|
|
||||||
|
|
||||||
const query = repository
|
|
||||||
.createQueryBuilder("config")
|
|
||||||
.where("config.serverId = :serverId", { serverId })
|
|
||||||
.getMany();
|
|
||||||
|
|
||||||
return query;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,37 +0,0 @@
|
||||||
import AutoKickConfig from "../database/entities/AutoKickConfig";
|
|
||||||
|
|
||||||
export default class AutoKickHelper {
|
|
||||||
public static async GetSetting(serverId: string): Promise<AutoKickConfig | null> {
|
|
||||||
const configs = await AutoKickConfig.FetchAllByServerId(serverId);
|
|
||||||
|
|
||||||
if (configs.length != 1) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return configs[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async SetSetting(serverId: string, roleId: string, kickTime: number, noticeTime?: number, noticeChannelId?: string) {
|
|
||||||
const configs = await AutoKickConfig.FetchAllByServerId(serverId);
|
|
||||||
|
|
||||||
if (configs.length == 0) {
|
|
||||||
const config = new AutoKickConfig(serverId, roleId, kickTime, noticeTime, noticeChannelId);
|
|
||||||
await config.Save(AutoKickConfig, config);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const config = configs[0];
|
|
||||||
|
|
||||||
config.UpdateBasicDetails(roleId, kickTime, noticeTime, noticeChannelId);
|
|
||||||
await config.Save(AutoKickConfig, config);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static async UnsetSetting(serverId: string) {
|
|
||||||
const configs = await AutoKickConfig.FetchAllByServerId(serverId);
|
|
||||||
|
|
||||||
for (let config of configs) {
|
|
||||||
await AutoKickConfig.Remove(AutoKickConfig, config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -4,7 +4,6 @@ import { EventType } from "./constants/EventType";
|
||||||
// Command Imports
|
// Command Imports
|
||||||
import About from "./commands/about";
|
import About from "./commands/about";
|
||||||
import Audits from "./commands/audits";
|
import Audits from "./commands/audits";
|
||||||
import Autokick from "./commands/autokick";
|
|
||||||
import Ban from "./commands/ban";
|
import Ban from "./commands/ban";
|
||||||
import Bunny from "./commands/bunny";
|
import Bunny from "./commands/bunny";
|
||||||
import Clear from "./commands/clear";
|
import Clear from "./commands/clear";
|
||||||
|
@ -46,7 +45,6 @@ export default class Registry {
|
||||||
public static RegisterCommands() {
|
public static RegisterCommands() {
|
||||||
CoreClient.RegisterCommand("about", new About());
|
CoreClient.RegisterCommand("about", new About());
|
||||||
CoreClient.RegisterCommand("audits", new Audits());
|
CoreClient.RegisterCommand("audits", new Audits());
|
||||||
CoreClient.RegisterCommand("autokick", new Autokick());
|
|
||||||
CoreClient.RegisterCommand("ban", new Ban());
|
CoreClient.RegisterCommand("ban", new Ban());
|
||||||
CoreClient.RegisterCommand("bunny", new Bunny());
|
CoreClient.RegisterCommand("bunny", new Bunny());
|
||||||
CoreClient.RegisterCommand("clear", new Clear());
|
CoreClient.RegisterCommand("clear", new Clear());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue