2022-08-06 18:16:45 +02:00
const client = require ( '../../index.js' ). client ;
const servers = require ( '../../models/server' );
2022-08-13 08:26:49 +02:00
const bots = require ( '../../models/bot' );
const users = require ( '../../models/user' );
2022-08-06 18:16:45 +02:00
var config = client . config
2022-08-13 08:26:49 +02:00
const { SlashCommandBuilder , Routes , EmbedBuilder } = require ( 'discord.js' );
2022-08-06 18:16:45 +02:00
const { REST } = require ( '@discordjs/rest' );
2022-08-08 10:55:08 +02:00
const colors = require ( 'colors' );
2022-08-06 18:16:45 +02:00
const commands = [
new SlashCommandBuilder (). setName ( 'ping' ). setDescription ( 'Replies with pong!' ),
2022-08-13 08:26:49 +02:00
new SlashCommandBuilder (). setName ( 'topvoted' ). setDescription ( 'Replies with highest server/bots!' ),
2022-08-18 14:44:12 +02:00
new SlashCommandBuilder (). setName ( 'profile' ). setDescription ( 'Replies with user info and connected bots/servers!' ),
2022-08-13 08:26:49 +02:00
new SlashCommandBuilder (). setName ( 'queue' ). setDescription ( 'Replies with queue' ),
2022-08-06 18:16:45 +02:00
]
. map ( command => command . toJSON ());
const rest = new REST ({ version : '10' }). setToken ( config . bot . token );
rest . put ( Routes . applicationGuildCommands ( config . bot . id , config . discord . id ), { body : commands })
2022-08-13 08:26:49 +02:00
. then (() => console . log ( colors . green ( "Website: " ), 'Successfully registered application commands.' ))
2022-08-06 18:16:45 +02:00
. catch ( console . error );
client . on ( 'interactionCreate' , async interaction => {
if ( ! interaction . isChatInputCommand ()) return ;
const { commandName } = interaction ;
if ( commandName === 'ping' ) {
await interaction . reply ( 'Pong!' );
2022-08-13 08:26:49 +02:00
} else if ( commandName === 'topvoted' ) {
const serversdata = await servers . find ();
const botsdata = await bots . find ({ verified : true });
var botsdata1 = botsdata
. sort (( a , b ) => b . votes - a . votes )
. slice ( 0 , 6 )
. map (
a => ` ${ a . name } **[ \` ${ a . votes } \` Votes ]**`
)
. join ( '\n' );
var serversdata1 = serversdata
. sort (( a , b ) => b . votes - a . votes )
. slice ( 0 , 6 )
. map (
a => ` ${ a . name } | ${ a . id } **[ \` ${ a . votes } \` Votes ]**`
)
. join ( '\n' );
if ( ! serversdata1 ) {
var serversdata1 = 'no servers' ;
}
if ( ! botsdata1 ) {
var botsdata1 = 'no bots' ;
}
const embed = new EmbedBuilder ()
. setAuthor ({ name : interaction . user . tag , iconURL : interaction . user . avatarURL ({ dynamic : true }) })
. setColor ( "#7289da" )
. setDescription ( `**Top 6 voted bots of the week!**\n ${ botsdata1 } \n\n**Top 6 voted servers of the week!**\n ${ serversdata1 } ` )
interaction . reply ({ embeds : [ embed ] });
2022-08-06 18:16:45 +02:00
} else if ( commandName === 'user' ) {
const { user } = interaction ;
2022-08-18 14:44:12 +02:00
bots . find ({ owner : user . id }). then ( bots => {
var bots1 = bots
. map (
a => ` ${ a . name } | ${ a . id } **[ \` ${ a . votes } \` Votes ]**`
)
. join ( '\n' );
if ( ! bots1 ) {
var bots1 = 'no bots' ;
}
const embed = new EmbedBuilder ()
. setAuthor ({ name : interaction . user . tag , iconURL : interaction . user . avatarURL ({ dynamic : true }) })
. setColor ( "#7289da" )
. setDescription ( `**Bots owned by ${ user . tag } **\n ${ bots1 } ` )
interaction . reply ({ embeds : [ embed ] });
}). catch ( console . error );
} else if ( commandName === 'profile' ) {
bots . find ({ owner : interaction . user . id }). then ( async function ( bots ){
var bots1 = bots
. map (
a => ` ${ a . name } | ${ a . id } **[ \` ${ a . votes } \` Votes ]**`
)
. join ( '\n' );
if ( ! bots1 ) {
var bots1 = 'no bots' ;
}
2022-08-22 16:22:25 +02:00
var user = await users . findOne ({ id : interaction . user . id });
2022-08-18 14:44:12 +02:00
const embed = new EmbedBuilder ()
. setAuthor ({ name : interaction . user . tag , iconURL : interaction . user . avatarURL ({ dynamic : true }) })
. setColor ( "#7289da" )
. setDescription ( `**Bots owned by ${ user . tag } **\n ${ bots1 } \nCoins: ${ user . coins } ` )
interaction . reply ({ embeds : [ embed ] });
})
2022-08-13 08:26:49 +02:00
} else if ( commandName === 'queue' ) {
if ( ! global . config . users . owner . includes ( interaction . user . id ) && ! global . config . users . verificator . includes ( interaction . user . id )) return interaction . reply ( 'You are not allowed to use this command!' );
const unVerified = await bots . find ({ verified : false });
var desc = "" ;
for ( let i = 0 ; i < unVerified . length ; i ++ ) {
desc += ` ${ i + 1 } . ${ unVerified [ i ]. name } - ${ unVerified [ i ]. id } Invite: https://discord.com/api/oauth2/authorize?client_id= ${ unVerified [ i ]. id } &scope=applications.commands%20bot\n` ;
}
const embed = new EmbedBuilder ()
. setTitle ( 'Unverified Bots' )
. setDescription ( desc )
. setColor ( "#5865F2" )
. setFooter ({ text : 'BotsCord' , iconURL : 'https://botscord.xyz/img/logo.png' })
. setTimestamp ()
interaction . reply ({ embeds : [ embed ] });
2022-08-06 18:16:45 +02:00
}
2022-08-08 10:55:08 +02:00
});
client . on ( "guildMemberAdd" , async ( member ) => {
2022-08-16 16:51:42 +02:00
console . log ( colors . green ( "Website: " ), ` ${ member . user . tag } has joined ${ member . guild . name } ` );
let guild = client . guilds . cache . get ( global . config . discord . id );
2022-08-08 10:55:08 +02:00
if ( member . user . bot ) {
try {
2022-08-16 16:51:42 +02:00
guild . members . cache . get ( member . id ). roles . add ( global . config . discord . roles . bot );
client . channels . cache . get ( global . config . bot . channels . welcome ). send ( ` ${ member . user . tag } has joined the server!` );
2022-08-15 16:27:59 +02:00
2022-08-08 10:55:08 +02:00
} catch ( error ) {
}
2022-08-13 08:26:49 +02:00
} else {
2022-08-08 10:55:08 +02:00
try {
2022-08-16 16:51:42 +02:00
guild . members . cache . get ( member . id ). roles . add ( global . config . discord . roles . user );
client . channels . cache . get ( global . config . bot . channels . welcome ). send ( ` ${ member . user . tag } has joined the server!` );
2022-08-08 10:55:08 +02:00
} catch ( error ) {
2022-08-16 16:51:42 +02:00
console . log ( error )
2022-08-08 10:55:08 +02:00
}
}
2022-08-13 08:26:49 +02:00
});
var cooldown = [];
client . on ( "messageCreate" , async ( message ) => {
if ( message . author . bot ) return ;
if ( message . channel . type === "dm" ) return ;
2022-08-18 14:44:12 +02:00
if ( cooldown . some ( code => code . id === message . author . id )) {
2022-08-15 16:27:59 +02:00
var userr = cooldown . findIndex (( obj => obj . id == message . author . id ));
cooldown [ userr ]. message += 1 ;
if ( cooldown [ userr ]. message >= 15 ) {
cooldown [ userr ]. message = 0 ;
const coins = await users . findOne ({ id : message . author . id });
if ( ! coins ) {
await users . create ({ id : message . author . id , coins : 0 });
} else {
if ( coins . coins < 1 ) {
coins . coins = 1 ;
coins . save ();
} else {
coins . coins ++ ;
coins . save ();
}
message . reply ( `You earned 1 coin! You now have ${ coins . coins } coins!` );
}
2022-08-13 08:26:49 +02:00
}
2022-08-15 16:27:59 +02:00
return
};
cooldown . push ({
id : message . author . id ,
message : 0 ,
});
2022-08-06 18:16:45 +02:00
});