@ -8,7 +8,8 @@ import {
TextChannel ,
TextChannel ,
ButtonStyle ,
ButtonStyle ,
User ,
User ,
ComponentType
ComponentType ,
ThreadChannel
} from "discord.js" ;
} from "discord.js" ;
import EmojiEmbed from "../utils/generateEmojiEmbed.js" ;
import EmojiEmbed from "../utils/generateEmojiEmbed.js" ;
import getEmojiByName from "../utils/getEmojiByName.js" ;
import getEmojiByName from "../utils/getEmojiByName.js" ;
@ -78,14 +79,21 @@ interface Transcript {
type : "ticket" | "purge"
type : "ticket" | "purge"
guild : string ;
guild : string ;
channel : string ;
channel : string ;
for : TranscriptAuthor
messages : TranscriptMessage [ ] ;
messages : TranscriptMessage [ ] ;
createdTimestamp : number ;
createdTimestamp : number ;
createdBy : TranscriptAuthor ;
createdBy : TranscriptAuthor ;
}
}
const noTopic = new EmojiEmbed ( )
. setTitle ( "User not found" )
. setDescription ( "There is no user associated with this ticket." )
. setStatus ( "Danger" )
. setEmoji ( "CONTROL.BLOCKCROSS" )
export default async function ( interaction : CommandInteraction | MessageComponentInteraction ) {
export default async function ( interaction : CommandInteraction | MessageComponentInteraction ) {
if ( interaction . channel === null ) return ;
if ( interaction . channel === null ) return ;
if ( ! ( interaction . channel instanceof TextChannel ) ) return ;
if ( ! ( interaction . channel instanceof TextChannel || interaction . channel instanceof ThreadChannel ) ) return ;
const { log , NucleusColors , entry , renderUser , renderDelta } = client . logger ;
const { log , NucleusColors , entry , renderUser , renderDelta } = client . logger ;
let messages : Message [ ] = [ ] ;
let messages : Message [ ] = [ ] ;
@ -98,6 +106,13 @@ export default async function (interaction: CommandInteraction | MessageComponen
messages = messages . concat ( Array . from ( deleted . values ( ) as Iterable < Message > ) ) ;
messages = messages . concat ( Array . from ( deleted . values ( ) as Iterable < Message > ) ) ;
if ( messages . length === 1 ) messageException ( interaction . guild ! . id , interaction . channel . id , messages [ 0 ] ! . id )
if ( messages . length === 1 ) messageException ( interaction . guild ! . id , interaction . channel . id , messages [ 0 ] ! . id )
} while ( deletedCount === 100 ) ;
} while ( deletedCount === 100 ) ;
messages = messages . filter ( message = > ! (
message . components . some (
component = > component . components . some (
child = > child . customId ? . includes ( "transcript" ) ? ? false
)
)
) ) ;
let out = "" ;
let out = "" ;
messages . reverse ( ) . forEach ( ( message ) = > {
messages . reverse ( ) . forEach ( ( message ) = > {
@ -116,8 +131,30 @@ export default async function (interaction: CommandInteraction | MessageComponen
const interactionMember = await interaction . guild ? . members . fetch ( interaction . user . id )
const interactionMember = await interaction . guild ? . members . fetch ( interaction . user . id )
let topic
let member : GuildMember | null = null ;
if ( interaction . channel instanceof TextChannel ) {
topic = interaction . channel . topic ;
if ( topic === null ) return await interaction . reply ( { embeds : [ noTopic ] } ) ;
member = interaction . guild ! . members . cache . get ( topic . split ( " " ) [ 1 ] ! ) ? ? null ;
} else {
topic = interaction . channel . name ;
const split = topic . split ( "-" ) . map ( p = > p . trim ( ) ) as [ string , string , string ] ;
member = interaction . guild ! . members . cache . get ( split [ 1 ] ) ? ? null ;
if ( member === null ) return await interaction . reply ( { embeds : [ noTopic ] } ) ;
}
const newOut : Transcript = {
const newOut : Transcript = {
type : "ticket" ,
type : "ticket" ,
for : {
username : member ! . user . username ,
discriminator : parseInt ( member ! . user . discriminator ) ,
id : member ! . user . id ,
topRole : {
color : member ! . roles . highest . color
}
} ,
guild : interaction.guild ! . id ,
guild : interaction.guild ! . id ,
channel : interaction.channel ! . id ,
channel : interaction.channel ! . id ,
messages : [ ] ,
messages : [ ] ,
@ -184,14 +221,8 @@ export default async function (interaction: CommandInteraction | MessageComponen
newOut . messages . push ( msg ) ;
newOut . messages . push ( msg ) ;
} ) ;
} ) ;
console . log ( newOut ) ;
const code = await client . database . transcripts . create ( newOut ) ;
if ( ! code ) return await interaction . reply ( { embeds : [ new EmojiEmbed ( ) . setTitle ( "Error" ) . setDescription ( "An error occurred while creating the transcript." ) . setStatus ( "Danger" ) . setEmoji ( "CONTROL.BLOCKCROSS" ) ] } )
const topic = interaction . channel . topic ;
let member : GuildMember | null = null ;
if ( topic !== null ) {
const part = topic . split ( " " ) [ 0 ] ? ? null ;
if ( part !== null ) member = interaction . guild ! . members . cache . get ( part ) ? ? null ;
}
let m : Message ;
let m : Message ;
if ( out !== "" ) {
if ( out !== "" ) {
const url = await pbClient . createPaste ( {
const url = await pbClient . createPaste ( {
@ -200,7 +231,7 @@ export default async function (interaction: CommandInteraction | MessageComponen
name :
name :
` Ticket Transcript ${
` Ticket Transcript ${
member ? "for " + member . user . username + "#" + member . user . discriminator + " " : ""
member ? "for " + member . user . username + "#" + member . user . discriminator + " " : ""
} ` + ` ( Created at $ { new Date ( interaction . channel . createdTimestamp ) . toDateString ( ) } ) ` ,
} ` + ` ( Created at $ { new Date ( interaction . channel . createdTimestamp ! ) . 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 ) ;