Skip to content

Commit

Permalink
Refactoring, moved/removed some files
Browse files Browse the repository at this point in the history
  • Loading branch information
BluDood committed Nov 3, 2022
1 parent 044b5ab commit 41f1876
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 130 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ package-lock.json
old/
databases/*
config.json

.vscode/
11 changes: 4 additions & 7 deletions autocomplete/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ const fs = require('fs')
module.exports = {
id: 'tag',
async execute(interaction) {
// Auto complete the tag command
if (interaction.options.getSubcommand() === 'remove' || interaction.options.getSubcommand() === 'get') {
const tags = JSON.parse(fs.readFileSync('./databases/tags.json'))
let tagNames = Object.keys(tags)
tagNames = tagNames.filter(name => name.startsWith(interaction.options.getFocused()))
return interaction.respond(tagNames.map(tag => ({ name: tag, value: tag })))
}
if (interaction.options.getSubcommand() !== 'remove' || interaction.options.getSubcommand() !== 'get') return
const tags = JSON.parse(fs.readFileSync('./databases/tags.json'))
const tagNames = Object.keys(tags).filter(name => name.startsWith(interaction.options.getFocused()))
return interaction.respond(tagNames.map(tag => ({ name: tag, value: tag })))
}
}
2 changes: 1 addition & 1 deletion commands/avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = {
data: new SlashCommandBuilder()
.setName('avatar')
.setDescription("Get your or another user's avatar")
.addUserOption(option => option.setName('target').setDescription('User to show avatar for')),
.addUserOption(option => option.setName('target').setDescription('User to get avatar for')),
async execute(interaction) {
const user = interaction.options.getUser('target') || interaction.user
const avatar = format => user.avatarURL({ format })
Expand Down
26 changes: 0 additions & 26 deletions commands/checkPerms.js

This file was deleted.

4 changes: 2 additions & 2 deletions commands/define.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const { SlashCommandBuilder } = require('discord.js')
const config = require('../utils/config')
const axios = require('axios').default
const { default: axios } = require('axios')

module.exports = {
data: new SlashCommandBuilder()
.setName('define')
.setDescription('Define a word with Urban Dictionary!')
.addStringOption(option => option.setName('query').setDescription('Word to search for').setRequired(true)),
async execute(interaction) {
// my api ;)
// https://guides.bludood.com/apis/urban-dictionary-api
const api = 'https://urbanapi.up.railway.app'
const query = interaction.options.getString('query')
interaction.deferReply()
Expand Down
2 changes: 1 addition & 1 deletion commands/yourmom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const { SlashCommandBuilder } = require('discord.js')
const axios = require('axios').default
const { default: axios } = require('axios')
const config = require('../utils/config')

module.exports = {
Expand Down
10 changes: 4 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { Client, Collection, GatewayIntentBits, Events } = require('discord.js')
const fs = require('fs')
const deploy = require('./utils/deploy')
const bconsole = require('./console')
const con = require('./utils/console')
const { cacheAll } = require('./utils/reactionroles')
const config = require('./utils/config')
const { token } = config.get()
Expand Down Expand Up @@ -40,16 +40,14 @@ for (const eventFile of fs.readdirSync('./events').filter(file => file.endsWith(
client.on(event.event, event.listener)
}

bconsole.init(process.argv[2])
con.init()
client.once(Events.ClientReady, async c => {
bconsole.motd(c.user.tag)
con.motd(c.user.tag)
deploy(c.user.id)
cacheAll(client)
})

client.on(Events.Error, error => {
console.log(error)
})
client.on(Events.Error, err => console.error(err))

client.on(Events.InteractionCreate, async interaction => {
if (interaction.isCommand()) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"start": "node index.js",
"setup": "node setup.js"
"setup": "node utils/setup.js"
},
"author": "BluDood",
"license": "ISC",
Expand Down
2 changes: 1 addition & 1 deletion utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function checkConfig() {
process.exit()
}
try {
JSON.parse(fs.readFileSync('./databases/reactionroles.json'))
JSON.parse(fs.readFileSync('./config.json'))
} catch {
console.log("Looks like your config file has been corrupted. Please regenerate it with 'npm run setup' and try again.")
process.exit()
Expand Down
7 changes: 4 additions & 3 deletions console.js → utils/console.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const chalk = require('chalk')
const sleep = require('./utils/sleep')
const sleep = require('./sleep')

let minimal = false

Expand All @@ -19,6 +19,7 @@ async function motd(tag) {
}
tag && console.log(`Welcome to BluBot! Your bot (${tag}) is now running.`)
console.log(minimal ? 'Press h and hit Enter for help.' : 'Press h for help.')
console.log(process.argv)
}

const commands = {
Expand Down Expand Up @@ -46,8 +47,8 @@ const commands = {
}

module.exports = {
init: arg => {
if (arg === '--minimal') minimal = true
init: () => {
if (process.argv[2] === '--minimal') minimal = true
!minimal && console.clear()
console.log(chalk.yellow('Starting BluBot...'))
if (!minimal) {
Expand Down
5 changes: 1 addition & 4 deletions utils/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ module.exports = id => {

rest
.put(Routes.applicationGuildCommands(id, guildId), { body: commands })
.then(() =>
// so it doesn't interfere with the console animation
sleep(1000).then(() => console.log('Successfully updated guild commands.'))
)
.then(() => sleep(1000).then(() => console.log('Successfully updated guild commands.')))
.catch(console.error)
}
76 changes: 0 additions & 76 deletions utils/moderation.js

This file was deleted.

3 changes: 2 additions & 1 deletion utils/reactionroles.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ function ensureDatabase() {
try {
JSON.parse(fs.readFileSync('./databases/reactionroles.json'))
} catch {
// show a warning first?
fs.writeFileSync('./databases/reactionroles.bak.json', fs.readFileSync('./databases/reactionroles.json'))
console.log('Your reaction role database was corrupted, so we had to reset it. You can find a backup in ./databases/reactionroles.bak.json')
fs.writeFileSync('./databases/reactionroles.json', '[]')
}
}
Expand Down
File renamed without changes.

0 comments on commit 41f1876

Please sign in to comment.