npm.click.util
Version:
NPM.CLICK.UTIL === What does npm.click.util do? **npm.click.util allows you to publish and update your NPM package in one simple execution command!** Example: ```js const PKG = require("npm.click.util") PKG("path to package.json")
257 lines (241 loc) • 11 kB
JavaScript
const Discord = require('discord.js')
module.exports={
commands: async function(table,args,message){
if(!table)throw new TypeError('No commands table specified!')
if(!args)throw new TypeError('No args specified!')
if(!message)throw new TypeError("No message client specified!")
//Create the function
if(!args[0])return message.channel.send('Not a commmand!')
//If not a command, then send this!
const output = table[(args[0] || "null").toLowerCase()]
if(output=='null')return message.channel.send('Not a command!')
else{
const UserRegex = new RegExp(/{user}/gi)
const GuildRegex = new RegExp(/{guild}/gi)
if(output.Type.toLowerCase()=='embed'){
const NewEmbed = new Discord.MessageEmbed()
if(!output.Color)throw new TypeError('No color was specified for your embed!')
if(!output.Title)throw new TypeError('No title was specified for your embed!')
if(!output.Description)throw new TypeError('No description was specified for your embed!')
let newDesc=output.Description.replace(UserRegex,message.author.username).replace(GuildRegex,message.guild.name)
let newTitle=output.Title.replace(UserRegex,message.author.username).replace(GuildRegex,message.guild.name)
NewEmbed.setTitle(newTitle)
NewEmbed.setColor(output.Color)
NewEmbed.setDescription(newDesc)
return message.channel.send(NewEmbed)
}
if(output.Type.toLowerCase()=='message'){
let newContent=output.Content.replace(UserRegex,message.author.username).replace(GuildRegex,message.guild.name)
return message.channel.send(newContent)
} else {
throw new TypeError('That is not a valid type!')
}
}
},
raw:{
client:{
api:{
table:{
run: function(){
const client = new Discord.Client()
return client
},
}
}
}
},
client: async function(table){
if(!table)throw new TypeError('No table specified!')
if(!table.Token)throw new TypeError('No token was supplied in the table.')
if(!table.Prefix)throw new TypeError('No prefix was supplied in the table.')
const Events = table.Events;
const client = new Discord.Client()
const Prefix = table.Prefix;
const Presence = table.Presence
/*
{
Token: '',
Events: {
ready: {
log: '' ,
},
message: {
Commands: {
Table: your command table
}
},
guildCreate: {
Send:
Type: 'Embed',
Title: '',
Color: '',
Description: '',
SpecificChannel: ""
Regex's : {guilds} {guild}
}
},
guildDelete: {
Send:
Type: 'Message',
Content: '',
SpecificChannel: ""
Regex's : {guilds} {guild}
}
}
},
Presence: "Game"
}
*/
if(Events){
if(Events.ready){
const ready = Events.ready;
if(ready.log){
client.on('ready',()=>{
console.log(ready.log)
if(Presence){
let user = client.user;
user.setActivity(Presence)
}
})
}else{
throw new TypeError('Ready table has been created inside the Events table inside the client table yet the ready event has no content.')
}
}
if(Events.message){
const message = Events.message;
if(message.Commands){
const CommandsEntry = message.Commands;
if(CommandsEntry.Table){
const Commands = CommandsEntry.Table
client.on('message',message=>{
if(!message.content.startsWith(Prefix))return;
const args = message.content.slice(Prefix.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
if(cmd.length==0)return
const output = Commands[(cmd ||null)]
if(output==null){return}else{
const UserRegex = new RegExp(/{user}/gi)
const GuildRegex = new RegExp(/{guild}/gi)
if(output.Type.toLowerCase()=='embed'){
const NewEmbed = new Discord.MessageEmbed()
if(!output.Color)throw new TypeError('No color was specified for your embed!')
if(!output.Title)throw new TypeError('No title was specified for your embed!')
if(!output.Description)throw new TypeError('No description was specified for your embed!')
let newDesc=output.Description.replace(UserRegex,message.author.username).replace(GuildRegex,message.guild.name)
let newTitle=output.Title.replace(UserRegex,message.author.username).replace(GuildRegex,message.guild.name)
NewEmbed.setTitle(newTitle)
NewEmbed.setColor(output.Color)
NewEmbed.setDescription(newDesc)
return message.channel.send(NewEmbed)
}
else if(output.Type.toLowerCase()=='message'){
let newContent=output.Content.replace(UserRegex,message.author.username).replace(GuildRegex,message.guild.name)
return message.channel.send(newContent)
} else {
throw new TypeError('That is not a valid type!')
}
}
})
} else{
throw new TypeError('Commands tabled was specified inside client table, however no commands table was specified.')
}
}
}
if(Events.guildCreate){
const Guilds = new RegExp(/{guilds}/gi)
const GuildName = new RegExp(/{guild}/gi)
if(!Events.guildCreate.Send){
throw new TypeError("guildCreate event was added too the Events table in the settings table, however no send table was provided.")
}
const guildAddMSG=Events.guildCreate.Send;
if(!guildAddMSG.Type){
throw new TypeError("No type of message was specified!")
}
if(!guildAddMSG.SpecificChannel){
throw new TypeError("You did not sepcify a specified channel!")
}
client.on('guildCreate',guild=>{
if(guildAddMSG.Type.toLowerCase()=='embed'){
const NewEmbed2 = new Discord.MessageEmbed()
if(!guildAddMSG.Color)throw new TypeError('No color was specified for your embed!')
if(!guildAddMSG.Title)throw new TypeError('No title was specified for your embed!')
if(!guildAddMSG.Description)throw new TypeError('No description was specified for your embed!')
let newDesc=guildAddMSG.Description.replace(Guilds,client.guilds.cache.size).replace(GuildName,guild.name)
let newTitle=guildAddMSG.Title.replace(Guilds,client.guilds.cache.size).replace(GuildName,guild.name)
NewEmbed2.setTitle(newTitle)
NewEmbed2.setColor(guildAddMSG.Color)
NewEmbed2.setDescription(newDesc)
if(guildAddMSG.SpecificChannel){
try{
client.channels.cache.get(guildAddMSG.SpecificChannel).send(NewEmbed2)
}catch(err){
throw new TypeError(`Error! That channel id is probably not a thing. E: ${err}`)
}
}
} else if(guildAddMSG.Type.toLowerCase()=='message'){
if(!guildAddMSG.Content){
throw new TypeError('No content was provided for your message!')
}
let newContent = guildAddMSG.Content.replace(GuildName,message.guild.name).replace(Guilds,client.guilds.cache.size)
if(guildAddMSG.SpecificChannel){
try{
client.channels.cache.get(guildAddMSG.SpecificChannel).send(newContent)
}catch(err){
throw new TypeError(`Error! That channel id is probably not a thing. E: ${err}`)
}
}
}
})
}
if(Events.guildDelete){
const Guilds = new RegExp(/{guilds}/gi)
const GuildName = new RegExp(/{guild}/gi)
if(!Events.guildDelete.Send){
throw new TypeError("guildDelete event was added too the Events table in the settings table, however no send table was provided.")
}
const guildDeleteMSG=Events.guildDelete.Send;
if(!guildDeleteMSG.Type){
throw new TypeError("No type of message was specified!")
}
if(!guildDeleteMSG.SpecificChannel){
throw new TypeError("You did not sepcify a specified channel!")
}
client.on('guildDelete',guild=>{
if(!guildDeleteMSG.Type.toLowerCase()=='embed'){
const NewEmbed3 = new Discord.MessageEmbed()
if(!guildDeleteMSG.Color)throw new TypeError('No color was specified for your embed!')
if(!guildDeleteMSG.Title)throw new TypeError('No title was specified for your embed!')
if(!guildDeleteMSG.Description)throw new TypeError('No description was specified for your embed!')
let newDesc=guildDeleteMSG.Description.replace(Guilds,client.guilds.cache.size).replace(GuildName,message.guild.name)
let newTitle=guildDeleteMSG.Title.replace(Guilds,client.guilds.cache.size).replace(GuildName,message.guild.name)
NewEmbed3.setTitle(newTitle)
NewEmbed3.setColor(guildDeleteMSG.Color)
NewEmbed3.setDescription(newDesc)
if(guildDeleteMSG.SpecificChannel){
try{
client.channels.cache.get(guildDeleteMSG.SpecificChannel).send(NewEmbed2)
}catch(err){
throw new TypeError(`Error! That channel id is probably not a thing. E: ${err}`)
}
}
} else if(guildDeleteMSG.Type.toLowerCase()=='message'){
if(!guildDeleteMSG.Content){
throw new TypeError('No content was provided for your message!')
}
let newContent = guildDeleteMSG.Content.replace(GuildName,guild.name).replace(Guilds,client.guilds.cache.size)
if(guildDeleteMSG.SpecificChannel){
try{
client.channels.cache.get(guildDeleteMSG.SpecificChannel).send(newContent)
}catch(err){
throw new TypeError(`Error! That channel id is probably not a thing. E: ${err}`)
}
} if(!guildDeleteMSG.SpecificChannel){
throw new TypeError('No content was provided for your message!')
}
}
})
}
}
client.login(table.Token)
},
}