Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions bot/database/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,14 @@ export async function GetVerifiedUser(guild_id: string, user_id: string): Promis
}
}

export async function AddUserWarning(guild_id: string, target_user_id: string, issuer_user_id: string, reason: string, strike: boolean): Promise<Warning> {
export async function AddUserWarning(guild_id: string, target_user_id: string, issuer_user_id: string, reason: string, url: string | undefined, strike: boolean): Promise<Warning> {
const pb = await getPb();
const data = {
guild_id,
target_user_id,
issuer_user_id,
reason,
url,
strike
}
return await pb.collection("warnings").create(data);
Expand Down Expand Up @@ -295,38 +296,41 @@ export async function GetStrikeCount(guild_id: string, target_user_id: string):
return warnings.length;
}

export async function AddUserBan(guild_id: string, target_user_id: string, issuer_user_id: string, reason: string, automatic: boolean): Promise<Ban> {
export async function AddUserBan(guild_id: string, target_user_id: string, issuer_user_id: string, reason: string, url: string | undefined, automatic: boolean): Promise<Ban> {
const pb = await getPb();
const data = {
guild_id,
target_user_id,
issuer_user_id,
reason,
url,
automatic
}
return await pb.collection("bans").create(data);
}

export async function AddUserKick(guild_id: string, target_user_id: string, issuer_user_id: string, reason: string, automatic: boolean): Promise<Kick> {
export async function AddUserKick(guild_id: string, target_user_id: string, issuer_user_id: string, reason: string, url: string | undefined, automatic: boolean): Promise<Kick> {
const pb = await getPb();
const data = {
guild_id,
target_user_id,
issuer_user_id,
reason,
url,
automatic
}
return await pb.collection("kicks").create(data);
}

export async function AddUserTimeout(guild_id: string, target_user_id: string, issuer_user_id: string, duration: number, reason: string, automatic: boolean): Promise<Timeout> {
export async function AddUserTimeout(guild_id: string, target_user_id: string, issuer_user_id: string, duration: number, reason: string, url: string | undefined, automatic: boolean): Promise<Timeout> {
const pb = await getPb();
const data = {
guild_id,
target_user_id,
issuer_user_id,
duration,
reason,
url,
automatic
}
return await pb.collection("timeouts").create(data);
Expand Down
9 changes: 8 additions & 1 deletion bot/discord/commands/moderator/Ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export const command = new SlashCommandBuilder()
.setDescription("Reason for ban. This will be displayed to the user.")
.setRequired(true)
)
.addStringOption((option) =>
option
.setName("url")
.setDescription("URL to the message (optional)")
.setRequired(false)
)
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers);

export async function execute(interaction: CommandInteraction) {
Expand All @@ -31,6 +37,7 @@ export async function execute(interaction: CommandInteraction) {
const issuer = interaction.member! as GuildMember;
const target = interaction.options.get("user")!.member as GuildMember;
const reason = interaction.options.get("reason")!.value as string;
const url = interaction.options.get("url")?.value as string | undefined;
const dm = await target.createDM().catch(error => {
console.log(error);
return null;
Expand All @@ -40,7 +47,7 @@ export async function execute(interaction: CommandInteraction) {
console.error(`Failed to send message to <@${target.id}>.`);
}

const ban = await AddUserBan(guild.id, target.id, issuer.id, reason, false);
const ban = await AddUserBan(guild.id, target.id, issuer.id, reason, url, false);
await LogBan(interaction, ban);
target.ban({ reason: reason });
let message = `
Expand Down
9 changes: 8 additions & 1 deletion bot/discord/commands/moderator/Kick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export const command = new SlashCommandBuilder()
.setDescription("Reason for kick. This will be displayed to the user.")
.setRequired(true)
)
.addStringOption((option) =>
option
.setName("url")
.setDescription("URL to the message (optional)")
.setRequired(false)
)
.setDefaultMemberPermissions(PermissionFlagsBits.KickMembers);

export async function execute(interaction: CommandInteraction) {
Expand All @@ -31,6 +37,7 @@ export async function execute(interaction: CommandInteraction) {
const issuer = interaction.member! as GuildMember;
const target = interaction.options.get("user")!.member as GuildMember;
const reason = interaction.options.get("reason")!.value as string;
const url = interaction.options.get("url")?.value as string | undefined;
const dm = await target.createDM().catch(error => {
console.log(error);
return null;
Expand All @@ -40,7 +47,7 @@ export async function execute(interaction: CommandInteraction) {
console.error(`Failed to send message to <@${target.id}>.`);
}

const ban = await AddUserKick(guild.id, target.id, issuer.id, reason, false);
const ban = await AddUserKick(guild.id, target.id, issuer.id, reason, url, false);
await LogKick(interaction, ban);
target.kick(reason);
let message = `
Expand Down
9 changes: 8 additions & 1 deletion bot/discord/commands/moderator/Timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export const command = new SlashCommandBuilder()
.setDescription("Reason for timeout. This will be displayed to the user.")
.setRequired(true)
)
.addStringOption((option) =>
option
.setName("url")
.setDescription("URL to the message (optional)")
.setRequired(false)
)
.setDefaultMemberPermissions(PermissionFlagsBits.KickMembers);

export async function execute(interaction: CommandInteraction) {
Expand All @@ -32,11 +38,12 @@ export async function execute(interaction: CommandInteraction) {
const issuer = interaction.member! as GuildMember;
const target = interaction.options.get("user")!.member as GuildMember;
const reason = interaction.options.get("reason")!.value as string;
const url = interaction.options.get("url")?.value as string | undefined;
const duration = interaction.options.get("duration")!.value as number;
const durationMilliseconds = duration * 1000 * 60;
const dm = await target.createDM();

const ban = await AddUserTimeout(guild.id, target.id, issuer.id, duration, reason, false);
const ban = await AddUserTimeout(guild.id, target.id, issuer.id, duration, reason, url, false);
await LogTimeout(interaction, ban);
target.timeout(durationMilliseconds, reason);
let message = `
Expand Down
9 changes: 8 additions & 1 deletion bot/discord/commands/moderator/Warn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ export const command = new SlashCommandBuilder()
.addBooleanOption((option) =>
option.setName("strike").setDescription("Record this warning as a formal strike").setRequired(true)
)
.addStringOption((option) =>
option
.setName("url")
.setDescription("URL to the message (optional)")
.setRequired(false)
)
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages);

export async function execute(interaction: CommandInteraction) {
Expand All @@ -34,9 +40,10 @@ export async function execute(interaction: CommandInteraction) {
const issuer = interaction.member! as GuildMember;
const target = interaction.options.get("user")!.member as GuildMember;
const reason = interaction.options.get("reason")!.value as string;
const url = interaction.options.get("url")?.value as string | undefined;
const strike = interaction.options.get("strike")!.value as boolean;

const warn = await AddUserWarning(interaction.guild.id, target.id, issuer.id, reason, strike);
const warn = await AddUserWarning(interaction.guild.id, target.id, issuer.id, reason, url, strike);
LogWarning(interaction, warn);

if (strike) {
Expand Down
1 change: 1 addition & 0 deletions bot/models/Ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export interface Ban {
target_user_id: string
issuer_user_id: string
reason: string
url?: string
automatic: boolean
}
1 change: 1 addition & 0 deletions bot/models/Kick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export interface Kick {
target_user_id: string
issuer_user_id: string
reason: string
url?: string
automatic: boolean
}
1 change: 1 addition & 0 deletions bot/models/Timeout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export interface Timeout {
issuer_user_id: string
duration: number
reason: string
url?: string
automatic: boolean
}
1 change: 1 addition & 0 deletions bot/models/Warning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export interface Warning {
target_user_id: string
issuer_user_id: string
reason: string
url?: string
strike: boolean
}
1 change: 1 addition & 0 deletions bot/templates/embeds/BanLogEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default async function BanLogEmbed(client: Client, ban: Ban) {
{ name: "Name", value: targetInfo?.name ?? "<not found>", inline: true },
{ name: "Handle", value: `<@${target.id}>`, inline: true },
{ name: "Reason", value: ban.reason, inline: false },
{ name: "URL", value: ban.url ? ban.url : "None", inline: false },
{ name: "Automatically issued", value: ban.automatic ? "Yes" : "No", inline: true },
{ name: "Issued by", value: `<@${issuer.id}>`, inline: true }
);
Expand Down
1 change: 1 addition & 0 deletions bot/templates/embeds/KickLogEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default async function BanLogEmbed(client: Client, kick: Kick) {
{ name: "Name", value: targetInfo?.name ?? "<not found>", inline: true },
{ name: "Handle", value: `<@${target.id}>`, inline: true },
{ name: "Reason", value: kick.reason, inline: false },
{ name: "URL", value: kick.url ? kick.url : "None", inline: false },
{ name: "Automatically issued", value: kick.automatic ? "Yes" : "No", inline: true },
{ name: "Issued by", value: `<@${issuer.id}>`, inline: true }
);
Expand Down
1 change: 1 addition & 0 deletions bot/templates/embeds/TimeoutLogEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default async function timeoutLogEmbed(client: Client, timeout: Timeout)
{ name: "Name", value: targetInfo?.name ?? "<not found>", inline: true },
{ name: "Handle", value: `<@${target.id}>`, inline: true },
{ name: "Reason", value: timeout.reason, inline: false },
{ name: "URL", value: timeout.url ? timeout.url : "None", inline: false },
{ name: "Duration", value: timeout.duration.toString(), inline: true},
{ name: "Automatically issued", value: timeout.automatic ? "Yes" : "No", inline: true },
{ name: "Issued by", value: `<@${issuer.id}>`, inline: true }
Expand Down
1 change: 1 addition & 0 deletions bot/templates/embeds/WarnLogEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default async function WarningLogEmbed(client: Client, warning: Warning)
{ name: "Name", value: targetInfo?.name ?? "<not found>", inline: true },
{ name: "Handle", value: `<@${target.id}>`, inline: true },
{ name: "Reason", value: warning.reason, inline: false },
{ name: "URL", value: warning.url ? warning.url : "None", inline: false },
{ name: "Strike", value: warning.strike ? "Yes" : "No", inline: true },
{ name: "Issued by", value: `<@${issuer.id}>`, inline: true }
);
Expand Down