22 SlashCommandBuilder
33} = require ( '@discordjs/builders' ) ;
44const { spawn } = require ( 'child_process' ) ;
5+ const { MessageEmbed } = require ( 'discord.js' ) ;
56
67module . exports = {
78 data : new SlashCommandBuilder ( )
@@ -32,13 +33,23 @@ module.exports = {
3233 . setDescription ( 'The comment to add to the thread' )
3334 . setRequired ( true )
3435 ) ,
36+ // .addStringOption(option =>
37+ // option.setName('file_type')
38+ // .setDescription('Optional field, required for syntax highlighting')
39+ // .setRequired(true)
40+ // .addChoices(
41+ // { name: 'js', value: 'js' },
42+ // { name: 'python', value: 'py'},
43+ // )
44+ // ),
3545
3646 async execute ( interaction ) {
3747 const fileLink = interaction . options . getString ( 'file_link' ) ;
3848 const threadName = interaction . options . getString ( 'name' ) ;
3949 const lineNumber = interaction . options . getInteger ( 'line_number' ) ;
4050 const margin = interaction . options . getInteger ( 'margin' ) ;
4151 const comment = interaction . options . getString ( 'comment' ) ;
52+ // const fileType = interaction.options.getString('file_type');
4253
4354 const thread = await interaction . channel . threads . create ( {
4455 name : threadName ,
@@ -51,13 +62,36 @@ module.exports = {
5162 'file_link' : fileLink ,
5263 'line_number' : lineNumber ,
5364 'margin' : margin ,
65+ // 'file_type': fileType,
5466 }
5567
5668 const pyfile = spawn ( 'python' , [ `./src/commands/GitHub_Code_Commenting/scrape.py` , JSON . stringify ( input ) ] ) ;
57-
69+
5870 pyfile . stdout . on ( 'data' , ( data ) => {
59- console . log ( 'e' )
60- console . log ( `stdout: ${ data } ` ) ;
71+ const snippet = data . toString ( ) . split ( ',' ) ;
72+ // const snippet = [];
73+ // for (i = 0; i < snippet1.length; i++) {
74+ // console.log(snippet1[i].substr(1, -1))
75+ // snippet.push(snippet1[i].substr(1, -1));
76+ // }
77+
78+ // const snippet = snippet1.map(s => s.slice(-1));
79+
80+ console . log ( snippet )
81+
82+ thread . send ( `${ snippet } ` ) ;
83+
84+ const commentEmbed = new MessageEmbed ( )
85+ . setColor ( '#152023' )
86+ . addFields (
87+ { name : 'Comment' , value : `${ comment } ` } ,
88+ )
89+
90+ // thread.send(comment);
91+ thread . send ( { embeds : [ commentEmbed ] } ) ;
92+ interaction . reply ( 'Succesfully created a thread with code snippet and comment!' ) ;
93+ // console.log(`${data}`)
94+ // snippet.push(`${data}`);
6195 } ) ;
6296
6397 pyfile . stderr . on ( 'data' , ( data ) => {
@@ -67,8 +101,5 @@ module.exports = {
67101 pyfile . on ( 'close' , ( code ) => {
68102 console . log ( `child process exited with code ${ code } ` ) ;
69103 } ) ;
70-
71- await thread . send ( comment ) ;
72- await interaction . reply ( 'Succesfully created a thread!' ) ;
73104 } ,
74105}
0 commit comments