Skip to content

Commit

Permalink
v2.3.0 is here
Browse files Browse the repository at this point in the history
  • Loading branch information
CSP02 committed Dec 11, 2021
1 parent 15d3f3f commit 3764c1c
Show file tree
Hide file tree
Showing 33 changed files with 1,305 additions and 1,151 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ infraction | infr, wi | replies with the warning of the given infraction ID | @
> Inorder to know more about the commands join my discord server.
### Version Info:
* Optimised code and updated API
* Fixed bugs in ban and bam command.
* Added Slash Commands (a few but will release a minor release after adding more slash commands),
* Added error handling which sends a embed message to the channel describing the error,
* Refined interactionCreate which accepts the slash commands interaction.

### Reference for graph API
* The API is developed by [@Denzven](https://github.com/denzven) in python. For more information about examples visit [Pythonwhere](https://denzven.pythonanywhere.com/)
Expand Down Expand Up @@ -77,4 +78,4 @@ You can contribute to The-Bot by opening an issue for bugs or by opening a pull

### Support me:
you can support me on [The Atelier team patreon](https://www.patreon.com/the_Atelier)
Thanks for the support.
Thanks for the support.
6 changes: 6 additions & 0 deletions SlashCommands/slashPing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data:new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with pong!')
}
6 changes: 6 additions & 0 deletions SlashCommands/slashPrefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data:new SlashCommandBuilder()
.setName('prefix')
.setDescription('Replies with prefix of this bot.')
}
7 changes: 7 additions & 0 deletions SlashInteractions/ping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
name: 'ping',
aliases: ['ping'],
async execute(client, interaction, Discord) {
interaction.reply(`Present heart beat of the bot is ${client.ws.ping}ms.`);
}
}
7 changes: 7 additions & 0 deletions SlashInteractions/prefix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
name: 'prefix',
aliases: ['prefix'],
async execute(client, interaction, Discord) {
interaction.reply(`prefix of this bot is \`\`\`!\`\`\``);
}
}
187 changes: 95 additions & 92 deletions commands/Moderation/ban.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,113 +9,116 @@ module.exports = {
permissions: ['BAN_MEMBERS'],
syntax: '!ban <user>',
async execute(client, message, args, Discord) {
const sLogsChannel = message.guild.channels.cache.find(chn => chn.name === 'server-logs')
const server = message.guild;
const infrType = 'Ban'

const target = message.mentions.users.first();
const memberTarget = message.guild.members.cache.get(target.id) || message.guild.members.cache.get(`${args[0]}`)
if (target) {
if (memberTarget.permissions.has('BAN_MEMBERS')) {
console.log('2nd')
message.channel.send('Be a good mod').catch(err => {
message.channel.send(`${err.message}`)
});
} else {
if (!args[1]) {
console.log('3rd')
message.channel.send('Provide a good reason to ban a member.').catch(err => {
try {
const sLogsChannel = message.guild.channels.cache.find(chn => chn.name === 'server-logs')
const server = message.guild;
const infrType = 'Ban'
let target
if (isNaN(args[0])) { target = message.mentions.members.first(); }
else if (!isNaN(args[0])) { target = await message.guild.members.fetch(args[0]) }
if (!target)
return message.channel.send('User not found!')
if (target) {
if (target.permissions.BAN_MEMBERS) {
message.channel.send('Be a good mod').catch(err => {
message.channel.send(`${err.message}`)
});
} else {
const guildId = message.guild.id;
const userId = target.id;
let reason = 'Undefined'
if (args[1]) {
reason = args.slice(1).join(' ')
}
var infrID = parseInt('1', 10);
if (!args[1]) {
message.channel.send('Provide a good reason to ban a member.').catch(err => {
message.channel.send(`${err.message}`)
});
} else {
const guildId = message.guild.id;
const userId = target.id;
let reason = 'Undefined'
if (args[1]) {
reason = args.slice(1).join(' ')
}
var infrID = parseInt('1', 10);


await mongo().then(async mongoose => {
try {
const results = await warnShema.findOne({
guildId
})
if (results == null) {
return
} else {
let reply = ' '
var infr
if (results.warnings.length != 0) {
for (const warning of results.warnings) {
const { author, userID, timestamp, reason, infrID } = warning
infr = parseInt(infrID, 10)
await mongo().then(async mongoose => {
try {
const results = await warnShema.findOne({
guildId
})
if (results == null) {
return
} else {
let reply = ' '
var infr
if (results.warnings.length != 0) {
for (const warning of results.warnings) {
const { author, userID, timestamp, reason, infrID } = warning
infr = parseInt(infrID, 10)
}
infrID += parseInt(infr, 10)
}
infrID += parseInt(infr, 10)
}
} finally {
mongoose.connection.close()
}
} finally {
mongoose.connection.close()
}
})
})



const warning = {
author: message.member.user.id,
userID: userId,
timestamp: new Date().getTime(),
reason,
infrType,
infrID
}
const warning = {
author: message.member.user.id,
userID: userId,
timestamp: new Date().getTime(),
reason,
infrType,
infrID
}

const embedMsg = new Discord.MessageEmbed()
.setColor('#ff0000')
.setTitle('Banned:')
.setFooter(`Infraction ID: ${infrID}`)
.addFields({
name: 'Reason:',
value: `${args.slice(1).join(' ')}`
const embedMsg = new Discord.MessageEmbed()
.setColor('#ff0000')
.setTitle('Banned:')
.setFooter(`Infraction ID: ${infrID}`)
.addFields({
name: 'Reason:',
value: `${args.slice(1).join(' ')}`
});
message.channel.send({ embeds: [embedMsg] }).catch(err => {
message.channel.send(`${err.message}`)
});
console.log('4th')
message.channel.send({ embeds: [embedMsg] }).catch(err => {
message.channel.send(`${err.message}`)
});
console.log('5th')
memberTarget.send({ embeds: [embedMsg] }).catch(err => {
message.channel.send(`${err.message}`)
});
console.log('6th')
sLogsChannel.send({ embeds: [embedMsg] }).catch(err => {
message.channel.send(`${err.message}`)
});
console.log('7th')
memberTarget.ban().catch(err => {
message.channel.send(`${err.message}`)
});
await mongo().then(async mongoose => {
try {
await warnShema.findOneAndUpdate({
guildId,
}, {
guildId,
$push: {
warnings: warning
}
}, {
upsert: true
})
} finally {
mongoose.connection.close()
}
})
target.send({ embeds: [embedMsg] }).catch(err => {
message.channel.send(`${err.message}`)
});
sLogsChannel.send({ embeds: [embedMsg] }).catch(err => {
message.channel.send(`${err.message}`)
});
target.ban().catch(err => {
message.channel.send(`${err.message}`)
});
await mongo().then(async mongoose => {
try {
await warnShema.findOneAndUpdate({
guildId,
}, {
guildId,
$push: {
warnings: warning
}
}, {
upsert: true
})
} finally {
mongoose.connection.close()
}
})
}
}
} else {
message.channel.send('cant find that member');
}
} else {
console.log('8th')
message.channel.send('cant find that member');
} catch (e) {
const emd = new Discord.MessageEmbed()
.setColor('#ff0000')
.setTitle('command raised an error in the source code:')
.setDescription(`\`\`\`${e}\`\`\`\n\nYou can crease a issue report here https://github.com/Chandra-sekhar-pilla/The-Bot-v2.0.0`)
message.channel.send({ embeds: [emd] })
}
}
}
58 changes: 20 additions & 38 deletions commands/Moderation/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,18 @@ module.exports = {
syntax: '!clear <number of messages>|<user>',
permissions: ['KICK_MEMBERS'],
async execute(client, message, args, Discord) {
if (message.member.permissions.has('MANAGE_MESSAGES')) {
try {
const target = message.mentions.users.first();

if (target) {
const messages = await message.channel.messages.fetch();
const filter = m => m.author.id === target.id;
const userMessage = message.channel.awaitMessages({ filter, max: args[0] }).then(collected => console.log(collected.size))
.catch(collected => console.log(`After a minute, only ${collected.size} out of 4 voted.`));
// const userMessage = messages.filter({m => m.author.id === target.id, max:args[0]})
const row = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageButton()
.setCustomId('clearYesUser')
.setLabel("Yes")
.setStyle('DANGER'),

new Discord.MessageButton()
.setCustomId('clearNoUser')
.setLabel("No")
.setStyle('PRIMARY')
)
await message.reply({ content: `Are you sure want to delete ${target}'s' messages?`, components: [row] })



const filter = m => m.author.id === target.id
const userMessage = await message.channel.messages.fetch(/*{limit:args[1]}*/)
userMessage.forEach(mess => {
console.log(mess.author.id === target.id)
if (mess.author.id === target.id)
mess.delete()
console.log(mess.content)
})
} else {
if (!args[0]) return message.reply("please enter the number of messages you want to clear");

Expand All @@ -37,23 +24,18 @@ module.exports = {
if (args[0] > 100) return message.reply('you cannot');
if (args[0] < 1) return message.reply('you cant time travel');

const row = new Discord.MessageActionRow()
.addComponents(
new Discord.MessageButton()
.setCustomId('clearYes')
.setLabel("Yes")
.setStyle('DANGER'),

new Discord.MessageButton()
.setCustomId('clearNo')
.setLabel("No")
.setStyle('PRIMARY')
)
await message.reply({ content: `Are you sure want to delete ${args[0]} messages?`, components: [row] })
await message.channel.messages.fetch({ limit: args[0] }).then(messages => {
message.channel.bulkDelete(messages).catch(e => {
message.channel.send(e.message)
});
});
}
}
else {
message.reply('you have no permission to use this command');
} catch (e) {
const emd = new Discord.MessageEmbed()
.setColor('#ff0000')
.setTitle('command raised an error in the source code:')
.setDescription(`\`\`\`${e}\`\`\`\n\nYou can crease a issue report here https://github.com/Chandra-sekhar-pilla/The-Bot-v2.0.0`)
message.channel.send({ embeds: [emd] })
}
}
}
Loading

0 comments on commit 3764c1c

Please sign in to comment.