Skip to content

Commit 144bf28

Browse files
committed
V1 Done, ggez
1 parent 276afb9 commit 144bf28

File tree

2 files changed

+57
-13
lines changed

2 files changed

+57
-13
lines changed

src/commands/GitHub_Code_Commenting/createThread.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const {
22
SlashCommandBuilder
33
} = require('@discordjs/builders');
44
const { spawn } = require('child_process');
5+
const { MessageEmbed } = require('discord.js');
56

67
module.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
}

src/commands/GitHub_Code_Commenting/scrape.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,35 @@ def scrape(url, line, margin):
1515
for i in range((line-1)-margin, (line-1)+margin+1):
1616
snippet.append(lines[i])
1717

18-
print(snippet)
18+
formattedSnippet = "```"
19+
# formattedSnippet += file_type + "\n"
20+
21+
for line in snippet:
22+
formattedSnippet += line + '\n'
23+
24+
formattedSnippet += "```"
25+
26+
print(formattedSnippet)
27+
# [print(line) for line in snippet]
1928

2029

2130
# input = str(sys.argv[1]).split(" ")
2231
# input = input[0]
2332

24-
print(dict(sys.argv[1]))
25-
input = json.load(sys.argv[1])
33+
jsonstring = sys.argv[1]
34+
# print(type(input))
35+
# print(input)
36+
input = json.loads(jsonstring)
2637

2738
url = input["file_link"]
2839
line = input["line_number"]
2940
margin = input["margin"]
41+
# file_type = input["file_type"]
42+
43+
# print(input)
3044

31-
print(input)
32-
print(url)
33-
print(line)
34-
print(margin)
45+
# print(url)
46+
# print(line)
47+
# print(margin)
3548

3649
scrape(url, line, margin)

0 commit comments

Comments
 (0)