initial commit

This commit is contained in:
SowinskiBraeden committed 2022-07-02 20:21:50 -07:00
commit 154831b2d4
14 files changed
+3067

No files matched your search

+10
View File
@@ -0,0 +1,10 @@
# Node modules
node_modules/*
# Testing/dev related
*_test.js
dev-*.js
# Logs
logs/*
Logs.log
+87
View File
@@ -0,0 +1,87 @@
const { MessageEmbed } = require("discord.js");
module.exports = {
name: "help",
description: "Get information on a specific command",
usage: "[command]",
permissions: {
channel: ["VIEW_CHANNEL", "SEND_MESSAGES", "EMBED_LINKS"],
member: [],
},
aliases: ["command", "commands", "cmd"],
/**
*
* @param {require("../structures/LinesPoliceCadBot")} client
* @param {import("discord.js").Message} message
* @param {string[]} args
* @param {*} param3
*/
SlashCommand: {
options: [
{
name: "command",
description: "Get information on a specific command",
value: "command",
type: 3,
required: false,
},
],
/**
*
* @param {require("../structures/LinesPoliceCadBot")} client
* @param {import("discord.js").Message} message
* @param {string[]} args
* @param {*} param3
*/
run: async (client, interaction, args, { GuildDB }) => {
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(interaction.channel_id)) {
return interaction.send(`You are not allowed to use the bot in this channel.`);
}
let Commands = client.commands.map((cmd) =>
`\`/${cmd.name}${cmd.usage ? " " + cmd.usage : ""}\` - ${cmd.description}`
);
let Embed = new MessageEmbed()
.setColor(client.config.EmbedColor)
.setDescription(`${Commands.join("\n")}
QuarksBot Version: v${client.config.Version}`);
if (!args) return interaction.send(Embed);
else {
let cmd =
client.commands.get(args[0].value) ||
client.commands.find(
(x) => x.aliases && x.aliases.includes(args[0].value)
);
if (!cmd)
return client.sendTime(
interaction,
`❌ | Unable to find that command.`
);
let embed = new MessageEmbed()
.setDescription(cmd.description)
.setColor("GREEN")
//.addField("Name", cmd.name, true)
.addField("Aliases", cmd.aliases.join(", "), true)
.addField(
"Usage",
`\`/${cmd.name}\`${cmd.usage ? " " + cmd.usage : ""}`,
true
)
.addField(
"Permissions",
"Member: " +
cmd.permissions.member.join(", ") +
"\nBot: " +
cmd.permissions.channel.join(", "),
true
);
interaction.send(embed);
}
},
},
};
+20
View File
@@ -0,0 +1,20 @@
module.exports = {
Dev: "PRODUCTION",
Version: "0.1.0",
Admins: ["362791661274660874"], // Admins of the bot
DefaultPrefix: "?",
SupportServer: "https://discord.gg/UnxZtEZ2", //Support Server Link
Token: process.env.token || "", //Discord Bot Token
Scopes: ["identify", "guilds", "applications.commands"], //Discord OAuth2 Scopes
IconURL: "",
EmbedColor: "#6e5145",
Permissions: 2205281600,
mongoURI: process.env.mongoURI || "mongodb://localhost:27017",
dbo: process.env.dbo || "knoldus",
Presence: {
status: "online", // You can show online, idle, and dnd
name: "Grand Theft Auto V", // The message shown
type: "PLAYING", // PLAYING, WATCHING, LISTENING, STREAMING
},
}
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

+3
View File
@@ -0,0 +1,3 @@
module.exports = (client, guild) => {
require("../util/RegisterSlashCommands")(client, guild.id);
};
+55
View File
@@ -0,0 +1,55 @@
/**
*
* @param {require("../structures/QuarksBot")} client
* @param {require("discord.js").message} message
* @returns {void} or nothing if you didn't know
*/
module.exports = async (client, message) => {
if (message.author.bot || message.channel.type === "dm") return;
let GuildDB = await client.GetGuild(message.guild.id);
//Prefixes also have mention match
const prefixMention = new RegExp(`^<@!?${client.user.id}> `);
prefix = message.content.match(prefixMention);
if (message.content.indexOf(prefix) !== 0) return;
if (GuildDB.customChannelStatus==true&&!GuildDB.allowedChannels.includes(message.channel.id)) {
return message.channel.send(`You are not allowed to use the bot in this channel.`);
}
const args = message.content.slice(prefix.length).trim().split(/ +/g);
//Making the command lowerCase because our file name will be in lowerCase
const command = args.shift().toLowerCase();
//Searching a command
const cmd =
client.commands.get(command) ||
client.commands.find((x) => x.aliases && x.aliases.includes(command));
//Executing the codes when we get the command or aliases
if (cmd) {
if (
(cmd.permissions &&
cmd.permissions.channel &&
!message.channel
.permissionsFor(client.user)
.has(cmd.permissions.channel)) ||
(cmd.permissions &&
cmd.permissions.member &&
!message.channel
.permissionsFor(message.member)
.has(cmd.permissions.member))
)
return client.sendError(
message.channel,
"Missing Permissions!" + GuildDB.DJ
? " You need the correct role to access this command."
: ""
);
cmd.run(client, message, args, { GuildDB });
client.CommandsRan++;
} else return;
};
+12
View File
@@ -0,0 +1,12 @@
module.exports = async (client) => {
(client.Ready = true),
client.user.setActivity(client.config.Presence.name, {
type: client.config.Presence.type,
})
client.user.setPresence({
status: client.config.Presence.status, // You can show online, idle, and dnd
});
client.log(`Successfully Logged in as ${client.user.tag}`); // You can change the text if you want, but DO NOT REMOVE "client.user.tag"
client.log(`Ready to serve in ${client.channels.cache.size} channels on ${client.guilds.cache.size} servers, for a total of ${client.users.cache.size} users.`)
client.RegisterSlashCommands();
};
+6
View File
@@ -0,0 +1,6 @@
const QuarksBot = require('./structures/QuarksBot');
const config = require('./config/config');
const { Intents } = require('discord.js');
let client = new QuarksBot({ intents:[Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]}, config);
client.build()
+2602
View File
File diff suppressed because it is too large. Load diff
+20
View File
@@ -0,0 +1,20 @@
{
"name": "quarksbot",
"version": "1.0.0",
"description": "Grand Theft Auto V Roleplay Bot",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "node dev-index.js"
},
"keywords": [
"Roleplay",
"GTAV"
],
"author": "Braeden Sowinski",
"license": "ISC",
"dependencies": {
"discord.js": "^13.8.1",
"mongodb": "^4.7.0"
}
}
+184
View File
@@ -0,0 +1,184 @@
const { Collection, Client, MessageEmbed } = require('discord.js');
const MongoClient = require('mongodb').MongoClient;
const Logger = require("../util/Logger");
const path = require("path");
const fs = require('fs');
class QuarksBot extends Client {
constructor(options, config) {
super(options)
this.config = config;
this.commands = new Collection();
this.logger = new Logger(path.join(__dirname, "..", "logs/Logs.log"));
if (this.config.Token === "")
return new TypeError(
"The config.js is not filled out. Please make sure nothing is blank, otherwise the bot will not work properly."
);
this.db;
this.dbo;
this.connectMongo(this.config.mongoURI, this.config.dbo);
this.LoadCommands();
this.LoadEvents();
this.Ready = false;
this.ws.on("INTERACTION_CREATE", async (interaction) => {
client.log("Interaction")
let GuildDB = await this.GetGuild(interaction.guild_id);
if (interaction.type==3) return;
const command = interaction.data.name.toLowerCase();
const args = interaction.data.options;
//Easy to send respnose so ;)
interaction.guild = await this.guilds.fetch(interaction.guild_id);
interaction.send = async (message) => {
return await this.api
.interactions(interaction.id, interaction.token)
.callback.post({
data: {
type: 4,
data:
typeof message == "string"
? { content: message }
: message.type && message.type === "rich"
? { embeds: [message] }
: message,
},
});
};
let cmd = client.commands.get(command);
if (cmd.SlashCommand && cmd.SlashCommand.run)
cmd.SlashCommand.run(this, interaction, args, { GuildDB });
});
const client = this;
}
async connectMongo(mongoURI, dbo) {
this.db = await MongoClient.connect(mongoURI);
this.dbo = this.db.db(dbo);
this.log('Successfully connected to mongoDB');
}
exists(n) {return null != n && undefined != n && "" != n}
LoadCommands() {
let CommandsDir = path.join(__dirname, '..', 'commands');
fs.readdir(CommandsDir, (err, files) => {
if (err) this.log(err);
else
files.forEach((file) => {
let cmd = require(CommandsDir + "/" + file);
if (!cmd.name || !cmd.description)
return this.log(
"Unable to load Command: " +
file.split(".")[0] +
", Reason: File doesn't had run/name/desciption"
);
this.commands.set(file.split(".")[0].toLowerCase(), cmd);
this.log("Command Loaded: " + file.split(".")[0]);
});
});
}
LoadEvents() {
let EventsDir = path.join(__dirname, '..', 'events');
fs.readdir(EventsDir, (err, files) => {
if (err) this.log(err);
else
files.forEach((file) => {
const event = require(EventsDir + "/" + file);
this.on(file.split(".")[0], event.bind(null, this));
this.logger.log("Event Loaded: " + file.split(".")[0]);
});
});
}
sendTime(Channel, Error) {
let embed = new MessageEmbed()
.setColor(this.config.EmbedColor)
.setDescription(Error);
Channel.send(embed);
}
RegisterSlashCommands() {
this.guilds.cache.forEach((guild) => {
require("../util/RegisterSlashCommands")(this, guild.id);
});
}
async GetGuild(GuildId) {
let customChannelStatus;
let allowedChannels;
let guild = await this.dbo.collection("guilds").findOne({"server.serverID":GuildId}).then(guild => guild);
// If guild not found, generate guild default
if (!guild) {
let newGuild = {
server: {
serverID: GuildId,
hasCustomChannels: false,
}
}
this.dbo.collection("guilds").insertOne(newGuild, function(err, res) {
if (err) throw err;
});
customChannelStatus = newGuild.server.hasCustomChannels;
allowedChannels = null;
} else {
customChannelStatus = guild.server.hasCustomChannels;
if (guild.server.allowedChannels!=undefined||guild.server.allowedChannels!=null&&guild.server.allowedChannels.length>0) {
allowedChannels = guild.server.allowedChannels;
} else allowedChannels = null;
}
let guildData = {
allowedChannels: allowedChannels,
customChannelStatus: customChannelStatus,
serverID: GuildId
}
return guildData;
}
/*
This command is to verify a user
has the correct role to use a
command ie. has cop role to use
name-search
*/
async verifyUseCommand(serverID, rolesCache, isList) {
let { customRoleStatus } = await this.GetGuild(serverID)
if (customRoleStatus) {
let hasRole = await this.checkRoleStatus(rolesCache, serverID, isList);
if (hasRole) {
return true // User has role, can use command
} else return false // User does not have role, can't use command
} else return true // There is no role limits
}
log(Text) {
this.logger.log(Text);
}
sendError(Channel, Error) {
let embed = new MessageEmbed()
.setTitle("An error occured")
.setColor("RED")
.setDescription(Error)
Channel.send(embed);
}
build() {
this.login(this.config.Token);
}
}
module.exports = QuarksBot;
+28
View File
@@ -0,0 +1,28 @@
const winston = require("winston");
const colors = require("colors");
class Logger {
constructor(LoggingFile) {
this.logger = winston.createLogger({
transports: [new winston.transports.File({ filename: LoggingFile })],
});
}
log(Text) {
let d = new Date();
this.logger.log({
level: "info",
message:
`${d.getHours()}:${
d.getMinutes
} - ${d.getDate()}:${d.getMonth()}:${d.getFullYear()} | Info: ` + Text,
});
console.log(
colors.green(
`${d.getDate()}:${d.getMonth()}:${d.getFullYear()} - ${d.getHours()}:${d.getMinutes()}`
) + colors.yellow(" | Info: " + Text)
);
}
}
module.exports = Logger;
+40
View File
@@ -0,0 +1,40 @@
const fs = require("fs");
const path = require("path");
/**
* Register slash commands for a guild
* @param {require("../structures/QuarksBot")} client
* @param {string} guild
*/
module.exports = (client, guild) => {
let commandsDir = path.join(__dirname, "..", "commands");
fs.readdir(commandsDir, (err, files) => {
if (err) throw err;
files.forEach(async (file) => {
let cmd = require(commandsDir + "/" + file);
if (!cmd.SlashCommand || !cmd.SlashCommand.run) return;
let dataStuff = {
name: cmd.name,
description: cmd.description,
options: cmd.SlashCommand.options,
};
//Creating variables like this, So you might understand my code :)
let ClientAPI = client.api.applications(client.user.id);
let GuildAPI = ClientAPI.guilds(guild);
try {
await GuildAPI.commands.post({ data: dataStuff });
} catch (e) {
client.log('Error: API missing permissions, re-invite the bot');
// Forces bot to leave server
let guildID = client.guilds.cache.get(guild);
if (guildID) guildID.leave();
client.log(`Server stats is now down to ${client.guilds.cache.size}`);
}
});
});
};