Skip to content

Commit 1b20b88

Browse files
committed
utmbot changes
1 parent 1c22ee6 commit 1b20b88

File tree

6 files changed

+223
-9
lines changed

6 files changed

+223
-9
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# BluBot
1+
# UTMbot
22

3-
A self-hosted Discord bot with various moderation features and fun commands. Features a simple CLI and setup script for easy management.
3+
Fork of [BluBot](https://github.com/BluDood/BluBot) with some extra features specified for the UTM Discord Server.
44

55
## Features
66

commands/addmessage.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const { ContextMenuCommandBuilder, ModalBuilder, TextInputBuilder, ActionRowBuilder } = require('@discordjs/builders')
2+
const { ApplicationCommandType, TextInputStyle } = require('discord-api-types/payloads/v10')
3+
const checkUserPerms = require('../utils/checkUserPerms')
4+
5+
module.exports = {
6+
data: new ContextMenuCommandBuilder().setName('Add to GitHub Issue').setType(ApplicationCommandType.Message),
7+
async execute(interaction) {
8+
if (!checkUserPerms(interaction))
9+
return interaction.reply({
10+
content: 'You do not have permission to do that!',
11+
ephemeral: true
12+
})
13+
const modal = new ModalBuilder().setCustomId('addmessage').setTitle('Add message to GitHub Issue')
14+
const id = new TextInputBuilder().setCustomId('id').setLabel('Issue ID').setStyle(TextInputStyle.Short)
15+
const extra = new TextInputBuilder().setCustomId('extrainfo').setLabel('Extra information').setStyle(TextInputStyle.Paragraph).setRequired(false)
16+
const messageId = new TextInputBuilder()
17+
.setCustomId('messageId')
18+
.setLabel('Message ID (do not change)')
19+
.setStyle(TextInputStyle.Short)
20+
.setMinLength(17)
21+
.setMaxLength(20)
22+
.setValue(interaction.targetMessage.id)
23+
.setRequired(true)
24+
modal.addComponents(new ActionRowBuilder().addComponents(id), new ActionRowBuilder().addComponents(extra), new ActionRowBuilder().addComponents(messageId))
25+
interaction.showModal(modal)
26+
}
27+
}

commands/issue.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const { ContextMenuCommandBuilder, ModalBuilder, TextInputBuilder, ActionRowBuilder } = require('@discordjs/builders')
2+
const { ApplicationCommandType, TextInputStyle } = require('discord-api-types/payloads/v10')
3+
const checkUserPerms = require('../utils/checkUserPerms')
4+
5+
module.exports = {
6+
data: new ContextMenuCommandBuilder().setName('Create GitHub Issue').setType(ApplicationCommandType.Message),
7+
async execute(interaction) {
8+
if (!checkUserPerms(interaction))
9+
return interaction.reply({
10+
content: 'You do not have permission to do that!',
11+
ephemeral: true
12+
})
13+
const modal = new ModalBuilder().setCustomId('newissue').setTitle('New GitHub Issue')
14+
const title = new TextInputBuilder().setCustomId('title').setLabel('Issue title').setStyle(TextInputStyle.Short)
15+
const extra = new TextInputBuilder().setCustomId('extrainfo').setLabel('Extra information').setStyle(TextInputStyle.Paragraph).setRequired(false)
16+
const messageId = new TextInputBuilder()
17+
.setCustomId('messageId')
18+
.setLabel('Message ID (do not change)')
19+
.setStyle(TextInputStyle.Short)
20+
.setMinLength(17)
21+
.setMaxLength(20)
22+
.setValue(interaction.targetMessage.id)
23+
.setRequired(true)
24+
modal.addComponents(new ActionRowBuilder().addComponents(title), new ActionRowBuilder().addComponents(extra), new ActionRowBuilder().addComponents(messageId))
25+
interaction.showModal(modal)
26+
}
27+
}

index.js

+26-7
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,21 @@ const client = new Client({
1515
})
1616

1717
client.commands = new Collection()
18+
client.modals = new Collection()
19+
1820
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'))
21+
const modalFiles = fs.readdirSync('./modals').filter(file => file.endsWith('.js'))
22+
1923
for (const file of commandFiles) {
2024
const command = require(`./commands/${file}`)
2125
client.commands.set(command.data.name, command)
2226
}
2327

28+
for (const file of modalFiles) {
29+
const modal = require(`./modals/${file}`)
30+
client.modals.set(modal.id, modal)
31+
}
32+
2433
bconsole.init()
2534
client.once('ready', async c => {
2635
bconsole.motd(c.user.tag)
@@ -41,13 +50,23 @@ client.on('error', error => {
4150
})
4251

4352
client.on('interactionCreate', async interaction => {
44-
if (interaction.isButton()) return
45-
const command = client.commands.get(interaction.commandName)
46-
if (command) {
47-
try {
48-
await command.execute(interaction)
49-
} catch (error) {
50-
console.error(error)
53+
if (interaction.isCommand()) {
54+
const command = client.commands.get(interaction.commandName)
55+
if (command) {
56+
try {
57+
await command.execute(interaction)
58+
} catch (error) {
59+
console.error(error)
60+
}
61+
}
62+
} else if (interaction.isModalSubmit()) {
63+
const modal = client.modals.get(interaction.customId)
64+
if (modal) {
65+
try {
66+
await modal.execute(interaction)
67+
} catch (error) {
68+
console.error(error)
69+
}
5170
}
5271
}
5372
})

modals/addmessage.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
const axios = require('axios').default
2+
const { resolveColor } = require('discord.js')
3+
const {
4+
customization: { accent }
5+
} = require('../config.json')
6+
7+
module.exports = {
8+
id: 'addmessage',
9+
async execute(interaction) {
10+
if (!checkUserPerms(interaction))
11+
return interaction.reply({
12+
content: 'You do not have permission to do that!',
13+
ephemeral: true
14+
})
15+
const messageId = interaction.fields.fields.find(f => f.customId === 'messageId').value
16+
const issueMessage = await interaction.channel.messages.fetch(messageId).catch(() => null)
17+
if (!issueMessage)
18+
return interaction.reply({
19+
content: 'I could not find that message!',
20+
ephemeral: true
21+
})
22+
23+
const id = interaction.fields.fields.find(f => f.customId === 'id').value
24+
const extraInfo = interaction.fields.fields.find(f => f.customId === 'extrainfo').value
25+
const attachments = issueMessage.attachments.map(a => `[${a.name}](${a.url})`)
26+
const imageTypes = ['png', 'jpg', 'jpeg', 'webp', 'gif']
27+
const thumbnail = issueMessage.attachments.filter(f => imageTypes.includes(f.name.split('.')[0]))[0]
28+
const res = await axios(`https://api.github.com/repos/UTMDiscordBot/testing/issues/${id}/comments`, {
29+
method: 'POST',
30+
headers: {
31+
Accept: 'application/vnd.github+json',
32+
Authorization: 'token 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'
33+
},
34+
data: {
35+
body: `${issueMessage.content}${attachments.length !== 0 ? `<br><h2>Attachments:</h2>${attachments.join('<br>')}` : ''}${
36+
extraInfo.length !== 0 ? `<br><h2>Extra Information:</h2>${extraInfo}` : ''
37+
}<br><details><summary><h2>Issuer and moderator</h2></summary>Issuer: ${issueMessage.author.tag}<br>Moderator: ${interaction.user.tag}</details>`
38+
}
39+
})
40+
const embed = {
41+
color: resolveColor(accent),
42+
title: 'Added this message as a comment!',
43+
thumbnail: {
44+
url: thumbnail
45+
},
46+
fields: [
47+
{
48+
name: 'Body',
49+
value: `${issueMessage.content}${extraInfo.length !== 0 ? `\n\n**Extra Information:**\n${extraInfo}` : ''}`
50+
},
51+
{
52+
name: 'Attachments',
53+
value: attachments.length !== 0 ? attachments.join('\n') : 'None'
54+
},
55+
{
56+
name: 'Link',
57+
value: res.data.html_url || 'Unknown'
58+
}
59+
],
60+
footer: {
61+
text: 'Report any bugs or issues to BluDood#0001'
62+
}
63+
}
64+
await interaction.reply({
65+
embeds: [embed]
66+
})
67+
}
68+
}

modals/newissue.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
const axios = require('axios').default
2+
const { resolveColor } = require('discord.js')
3+
const {
4+
customization: { accent }
5+
} = require('../config.json')
6+
7+
module.exports = {
8+
id: 'newissue',
9+
async execute(interaction) {
10+
if (!checkUserPerms(interaction))
11+
return interaction.reply({
12+
content: 'You do not have permission to do that!',
13+
ephemeral: true
14+
})
15+
const messageId = interaction.fields.fields.find(f => f.customId === 'messageId').value
16+
const issueMessage = await interaction.channel.messages.fetch(messageId).catch(() => null)
17+
if (!issueMessage)
18+
return interaction.reply({
19+
content: 'I could not find that message!',
20+
ephemeral: true
21+
})
22+
23+
const title = interaction.fields.fields.find(f => f.customId === 'title').value
24+
const extraInfo = interaction.fields.fields.find(f => f.customId === 'extrainfo').value
25+
const attachments = issueMessage.attachments.map(a => `[${a.name}](${a.url})`)
26+
const imageTypes = ['png', 'jpg', 'jpeg', 'webp', 'gif']
27+
const thumbnail = issueMessage.attachments.filter(f => imageTypes.includes(f.name.split('.')[0]))[0]
28+
const res = await axios(`https://api.github.com/repos/UTMDiscordBot/testing/issues`, {
29+
method: 'POST',
30+
headers: {
31+
Accept: 'application/vnd.github+json',
32+
Authorization: 'token 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'
33+
},
34+
data: {
35+
title: title,
36+
body: `${issueMessage.content}${attachments.length !== 0 ? `<br><h2>Attachments:</h2>${attachments.join('<br>')}` : ''}${
37+
extraInfo.length !== 0 ? `<br><h2>Extra Information:</h2>${extraInfo}` : ''
38+
}<br><details><summary><h2>Issuer and moderator</h2></summary>Issuer: ${issueMessage.author.tag}<br>Moderator: ${interaction.user.tag}</details>`
39+
}
40+
})
41+
const embed = {
42+
color: resolveColor(accent),
43+
title: 'Created a new issue!',
44+
thumbnail: {
45+
url: thumbnail
46+
},
47+
fields: [
48+
{
49+
name: 'Title',
50+
value: title
51+
},
52+
{
53+
name: 'Body',
54+
value: `${issueMessage.content}${extraInfo.length !== 0 ? `\n\n**Extra Information:**\n${extraInfo}` : ''}`
55+
},
56+
{
57+
name: 'Attachments',
58+
value: attachments.length !== 0 ? attachments.join('\n') : 'None'
59+
},
60+
{
61+
name: 'Link',
62+
value: res.data.html_url || 'Unknown'
63+
}
64+
],
65+
footer: {
66+
text: 'Report any bugs or issues to BluDood#0001'
67+
}
68+
}
69+
await interaction.reply({
70+
embeds: [embed]
71+
})
72+
}
73+
}

0 commit comments

Comments
 (0)