Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
falcao-g committed Feb 1, 2023
2 parents 9645fdd + a404217 commit c8e7446
Show file tree
Hide file tree
Showing 41 changed files with 753 additions and 618 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ config.json file:
- "owners": put here your discord id and other people that will be involved in development, this will be important to manage slash commands
- "someServers": the server or servers id that will be used to test the bot
- "language": the default language of the bot
- "poupanca": this defines some things about the bank's interest of the bot
- "last_interest": don't touch this, the code uses this to know when was the last interest increase
- "interest_time": how much time between interests in milisseconds, default is 24h
- "interest_rate": how much % the interest increases, default is 10%
- "testOnly": when you are only testing the slash commands put this as true this way you don't have to wait 1 hour for the command to register, it register instantly in the servers you put earlier

## 🏃‍♂️ Running
Expand Down
74 changes: 72 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,75 @@
const builder = require("./src/index")
const path = require("path")
const { owners, someServers, language } = require("./src/config.json")
const WOKCommands = require("wokcommands")
const mongoose = require("mongoose")
const { Intents, Client } = require("discord.js")
require("dotenv").config()
const client = new Client({
intents: new Intents(["GUILDS", "GUILD_MESSAGES", "GUILD_MESSAGE_REACTIONS"]),
})

Falbot = new builder.Falbot()
client.on("ready", () => {
client.on("error", console.error)

module.exports = { Falbot }
try {
mongoose.set("strictQuery", false)
mongoose.connect(process.env.MONGODB_URI)
} catch {
console.log("A conexão caiu")
mongoose.connect(process.env.MONGODB_URI)
}

mongoose.connection.on("error", (err) => {
console.log(`Erro na conexão: ${err}`)
mongoose.connect(process.env.MONGODB_URI)
})

mongoose.connection.on("disconnected", () => {
console.log("A conexão caiu")
mongoose.connect(process.env.MONGODB_URI)
})

mongoose.connection.on("disconnecting", () => {
console.log("A conexão caiu")
mongoose.connect(process.env.MONGODB_URI)
})

mongoose.connection.on("MongoNetworkError", () => {
console.log("A conexão caiu")
mongoose.connect(process.env.MONGODB_URI)
})

mongoose.connection.on("MongooseServerSelectionError", () => {
console.log("A conexão caiu")
mongoose.connect(process.env.MONGODB_URI)
})

const wok = new WOKCommands(client, {
commandsDir: path.join(__dirname, "/src/commands"),
featuresDir: path.join(__dirname, "/src/events"),
ignoreBots: true,
ephemeral: false,
botOwners: owners,
testServers: someServers,
defaultLanguage: language,
messagesPath: path.join(__dirname, "/src/utils/json/messages.json"),
disabledDefaultCommands: [
"language",
"help",
"command",
"requiredrole",
"channelonly",
"prefix",
],
showWarns: false,
})

wok._mongoConnection = mongoose.connection

Falbot = new builder.Falbot(wok, client)

module.exports = { Falbot }
})

client.login(process.env.TOKEN)
6 changes: 5 additions & 1 deletion src/commands/8ball.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ module.exports = {
},
],
callback: async ({ guild, text, interaction }) => {
await interaction.deferReply()
try {
await interaction.deferReply()
let answers = Falbot.getMessage(guild, "8BALL")
let answer = `${answers[randint(0, answers.length - 1)]}`
const embed = new MessageEmbed()
Expand All @@ -42,6 +42,10 @@ module.exports = {
await interaction.editReply({ embeds: [embed] })
} catch (error) {
console.error(`8ball: ${error}`)
interaction.editReply({
content: Falbot.getMessage(guild, "EXCEPTION"),
embeds: [],
})
}
},
}
7 changes: 6 additions & 1 deletion src/commands/balance.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ module.exports = {
},
],
callback: async ({ guild, member, args, interaction }) => {
await interaction.deferReply()
try {
await interaction.deferReply()
const realMember = args[0] ? await getMember(guild, args[0]) : member
const userFile = await readFile(realMember.user.id)

Expand Down Expand Up @@ -94,6 +94,11 @@ module.exports = {
await interaction.editReply({ embeds: [embed], components: [row] })
} catch (error) {
console.error(`balance: ${error}`)
interaction.editReply({
content: Falbot.getMessage(guild, "EXCEPTION"),
embeds: [],
components: [],
})
}
},
}
6 changes: 5 additions & 1 deletion src/commands/bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ module.exports = {
},
],
callback: async ({ guild, user, interaction }) => {
await interaction.deferReply()
try {
metodo = interaction.options.getSubcommand()
falcoins = interaction.options.getString("falcoins")
var rank_number = await readFile(user.id, "rank")
var limit = Falbot.levels[rank_number - 1].bankLimit
await interaction.deferReply()

if (metodo === "view") {
const embed = new MessageEmbed()
Expand Down Expand Up @@ -178,6 +178,10 @@ module.exports = {
}
} catch (error) {
console.error(`bank: ${error}`)
interaction.editReply({
content: Falbot.getMessage(guild, "EXCEPTION"),
embeds: [],
})
}
},
}
6 changes: 5 additions & 1 deletion src/commands/botinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ module.exports = {
guildOnly: true,
testOnly,
callback: async ({ guild, client, interaction }) => {
await interaction.deferReply()
try {
await interaction.deferReply()
const embed = new MessageEmbed()
.setColor("NAVY")
.addFields({
Expand All @@ -30,6 +30,10 @@ module.exports = {
await interaction.editReply({ embeds: [embed] })
} catch (error) {
console.error(`botinfo: ${error}`)
interaction.editReply({
content: Falbot.getMessage(guild, "EXCEPTION"),
embeds: [],
})
}
},
}
5 changes: 4 additions & 1 deletion src/commands/coinflip.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ module.exports = {
},
],
callback: async ({ guild, args, interaction }) => {
await interaction.deferReply()
try {
await interaction.deferReply()
times = args[0] > 0 ? args[0] : -args[0]
let caras = randint(0, times)
let coroas = times - caras
Expand All @@ -30,6 +30,9 @@ module.exports = {
})
} catch (error) {
console.error(`Coinflip: ${error}`)
interaction.editReply({
content: Falbot.getMessage(guild, "EXCEPTION"),
})
}
},
}
14 changes: 8 additions & 6 deletions src/commands/cooldowns.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ module.exports = {
init: () => {
const { Falbot } = require("../../index.js")
},
callback: async ({ instance, guild, user, interaction }) => {
callback: async ({ guild, user, interaction }) => {
await interaction.deferReply()
try {
await interaction.deferReply()
voteCooldown = Date.now() - (await readFile(user.id, "lastVote"))
cooldownsSchema =
instance._mongoConnection.models["wokcommands-cooldowns"]
scratchCooldown = await cooldownsSchema.findById(`scratch-${user.id}`)
workCooldown = await cooldownsSchema.findById(`work-${user.id}`)
scratchCooldown = await Falbot.coolSchema.findById(`scratch-${user.id}`)
workCooldown = await Falbot.coolSchema.findById(`work-${user.id}`)
lotto = await Falbot.lottoSchema.findById("semanal")
const embed = new MessageEmbed()
.setColor(await getRoleColor(guild, user.id))
Expand Down Expand Up @@ -85,6 +83,10 @@ module.exports = {
interaction.editReply({ embeds: [embed], components: [row] })
} catch (error) {
console.error(`cooldowns: ${error}`)
interaction.editReply({
content: Falbot.getMessage(guild, "EXCEPTION"),
embeds: [],
})
}
},
}
Loading

0 comments on commit c8e7446

Please sign in to comment.