Skip to content

Commit

Permalink
Fixed bugs and added a command
Browse files Browse the repository at this point in the history
  • Loading branch information
CSP02 committed Aug 21, 2023
1 parent a927d47 commit a1c5db7
Show file tree
Hide file tree
Showing 34 changed files with 454 additions and 299 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
.vs
.vscode

desktop.ini

node_modules/
37 changes: 7 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# The-Bot
![The-Bot](Resources/The-Bot-logo.png "The-Bot")

![issues](https://img.shields.io/github/issues/Chandra-sekhar-pilla/The-Bot)
![forks](https://img.shields.io/github/forks/Chandra-sekhar-pilla/The-Bot)
![stars](https://img.shields.io/github/stars/Chandra-sekhar-pilla/The-Bot)
![license](https://img.shields.io/github/license/Chandra-sekhar-pilla/The-Bot)
![version](https://img.shields.io/badge/Version-4.0.1-green)


> The default prefix is "!".
(Prefix is same for every Guild/Server will release an update to make it able to change for different guilds.)
![version](https://img.shields.io/badge/Version-4.1.1-green)

* It is a discord bot for moderation.

Expand All @@ -18,31 +15,11 @@

* Use !help to get the commands you can use.

### Basic commands (Not all):

Command | Alias | Task | Permission
---------- | ----- | ---- | ----------
help | - | Displays the commands you can use | @everyone
serverinfo | si | Displays the information about the server | @everyone
userinfo | ui | Displays the information of mentioned user if not mentioned Displays the info about you | @everyone
ping | - | Displays the current speed or latency of the bot | @everyone
github | gh | Sends a link of this Bot's repository | @everyone
removerole | remove, rr | removes a role from a user | @everyone
role | - | assigns the given role | @everyone
kick | - | Kicks the mentioned member | @staff
ban | - | Banes the mentioned member | @staff
mute | - | Mutes the mentioned member | @staff
deleteinfraction | di, delinfr | Deletes the infraction with infraction id specified | @staff
clear | - | Clears the given number of messages including the bot's message | @staff
unmute | - | unmutes the mentioned member | @staff
warn | - | warns the mentioned member | @staff
infraction | infr, wi | replies with the warning of the given infraction ID | @staff

> Inorder to know more about the commands join my discord server.
### Version Info:
* 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.
* Fixed most of the bugs.
* Added "tex" command which can render the tex markdown.
* Now The-Bot will log the login timestamps into a json file.

### 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 All @@ -58,8 +35,8 @@ infraction | infr, wi | replies with the warning of the given infraction ID | @
```
Example:
You:
!ping
The bot:
/ping
@The-bot
Present heartbeat of the bot is 42ms.
```
#### License:
Expand Down
12 changes: 12 additions & 0 deletions SlashCommands/Custom Commands/ModuleInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ module.exports = {
Description: 'Send the cdn link of toggler.js.',
Syntax: '/togglerjs',
Permission: 'Everyone',
},
{
Name: 'buildtex',
Description: 'Sends an tex rendered rendered image.',
Syntax: '/buildtex <tex_input>\nFor more details visit https://katex.org/docs/support_table.html',
Permission: 'Everyone'
},
{
Name: 'topic',
Description: 'Sends a topic to chat when chat is inactive',
Syntax: '/topic',
Permission: 'Everyone'
}
]
}
3 changes: 2 additions & 1 deletion SlashCommands/Custom Commands/debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
.setDescription('A way to debug your code/game in unity.'),

async execute(client, interaction, Discord) {
await interaction.channel.send("If you have a code which isn't working and there are no errors or warnings of such kind use ``Debug.Log()``. This will help you where actually the unknown error is.\nlet's take an example like if you wrote a code of rotating something but after you start or run the code the object is not rotating use ``Debug.Log()`` command at the part where you think the code is not working.This is a nice practise even while in general coding. ~~Even I use this type of commands more~~.\n\n'When you get lost, use Debug.Log()' - BLAME <@341756841576890378> for this quote.")
//sends a way to debug your unity C# code
await interaction.reply("If you have a code which isn't working and there are no errors or warnings of such kind use ``Debug.Log()``. This will help you where actually the unknown error is.\nlet's take an example like if you wrote a code of rotating something but after you start or run the code the object is not rotating use ``Debug.Log()`` command at the part where you think the code is not working.This is a nice practise even while in general coding. ~~Even I use this type of commands more~~.\n\n'When you get lost, use Debug.Log()' - BLAME <@341756841576890378> for this quote.")
}
}
8 changes: 4 additions & 4 deletions SlashCommands/Custom Commands/learndjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ module.exports = {
.setColor('#9C27B0')
.setTitle('__Discord.js tutorial links__')
.addFields([
{ name: ' Official Discord.js Guide : ', value: 'https://discordjs.guide' },
{ name: ' Guide by Codelyon : ', value: 'https://anidiots.guide/getting-started/getting-started-long-version ' },
{ name: ' Tutorial series by Codelyon : ', value: 'https://youtube.com/playlist?list=PLbbLC0BLaGjpyzN1rg-gK4dUqbn8eJQq4 ' },
{ name: ' Tutorial series by Worn off keys : ', value: 'https://youtube.com/playlist?list=PLaxxQQak6D_fxb9_-YsmRwxfw5PH9xALe ' }
{ name: ' Official Discord.js Guide : ', value: '[discord.js guide](https://discordjs.guide)' },
{ name: ' Guide by Codelyon : ', value: '[Codelyon guide](https://anidiots.guide/getting-started/getting-started-long-version)' },
{ name: ' Tutorial series by Codelyon : ', value: '[YouTube tutorials of codelyon](https://youtube.com/playlist?list=PLbbLC0BLaGjpyzN1rg-gK4dUqbn8eJQq4)' },
{ name: ' Tutorial series by Worn off keys : ', value: '[YouTube tutorials of WOK](https://youtube.com/playlist?list=PLaxxQQak6D_fxb9_-YsmRwxfw5PH9xALe)' }
])
.setThumbnail("https://i.ibb.co/7th2xwt/images.png")
.setFooter({ text: 'See github repository of the atelier bot by using !gh command. Enjoy learning Discord-js and make your own custom bot 😃 .' })
Expand Down
18 changes: 9 additions & 9 deletions SlashCommands/Custom Commands/learnjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ module.exports = {
.setThumbnail("https://i.ibb.co/5sy5y5H/javascript-logo.png")
.addFields([
{ name: '__**Documentation:**__', value: '\u200b' },
{ name: 'MDN Javascript: ', value: 'https://developer.mozilla.org/en-US/docs/Web/JavaScript ' },
{ name: 'W3School (Javascript): ', value: 'https://www.w3schools.com/js/ ' },
{ name: 'jQuery Documentation: ', value: 'http://contribute.jquery.org/documentation/ ' },
{ name: 'NodeJS: ', value: 'https://nodejs.org/en/docs/ ' },
{ name: 'MDN Javascript: ', value: '[MDN Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript)' },
{ name: 'W3School (Javascript): ', value: '[W3 Schools docs](https://www.w3schools.com/js/)' },
{ name: 'jQuery Documentation: ', value: '[jQuery docs](http://contribute.jquery.org/documentation/)' },
{ name: 'NodeJS: ', value: '[NodeJS docs](https://nodejs.org/en/docs/)' },
{ name: '__**Tutorials:**__ ', value: '\u200b' },
{ name: 'Eloquent Javascript: ', value: ' http://eloquentjavascript.net/' },
{ name: "You Don't Know JS: ", value: 'https://github.com/getify/You-Dont-Know-JS ' },
{ name: 'Modern Javascript: ', value: 'https://javascript.info/ ' },
{ name: 'Eloquent Javascript: ', value: 'http://eloquentjavascript.net/' },
{ name: "You Don't Know JS: ", value: 'https://github.com/getify/You-Dont-Know-JS ' },
{ name: 'Modern Javascript: ', value: 'https://javascript.info/ ' },
{ name: '__**Interesting:**__', value: '\u200b' },
{ name: 'You might not need jQuery: ', value: 'http://youmightnotneedjquery.com/ ' },
{ name: 'CodingTrain (tutorials with examples using p5.js): ', value: ' https://www.youtube.com/user/shiffman' }
{ name: 'You might not need jQuery: ', value: 'http://youmightnotneedjquery.com/ ' },
{ name: 'CodingTrain (tutorials with examples using p5.js): ', value: '[YouTube tutorials for JS](https://www.youtube.com/user/shiffman)' }
])
.setFooter({ text: "This list does not contain every resource out there because the internet is huge and listing everything down is impossible." })
interaction.reply({ embeds: [embed] });
Expand Down
8 changes: 7 additions & 1 deletion SlashCommands/Custom Commands/learnunity.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ module.exports = {
.setColor('#9C27B0')
.setTitle('**Learn C# basics before starting with Unity!**')
.addFields(
[{ name: "Learning the syntax of C# definitely helps when using Unity. Here are some links to get you started!", value: "https://docs.microsoft.com/en-us/dotnet/csharp/ (Microsofts 'Getting Started' Guide on C#)\nhttps://channel9.msdn.com/Series/CSharp-Fundamentals-for-Absolute-Beginners (Teaches you the C# fundamentals)\nhttps://github.com/ossu/computer-science (Not strictly C#, a general open-source education in Computer Science)\n https://www.classcentral.com/report/stanford-on-campus-courses (Publicly available Computer Science courses from Stanford)\n https://codecademy.com/learn/learn-c-sharp (Code Academy course on C#)\n https://learn.unity.com/ (Has great tutorials on using C# with Unity)" }])
[
{
name: "Learning the syntax of C# definitely helps when using Unity. Here are some links to get you started!",
value: "1. [Microsofts 'Getting Started' Guide on C#](https://docs.microsoft.com/en-us/dotnet/csharp/)\n2. [Teaches you the C# fundamentals](https://channel9.msdn.com/Series/CSharp-Fundamentals-for-Absolute-Beginners)\n3. [Not strictly C#, a general open-source education in Computer Science](https://github.com/ossu/computer-science)\n4. [Publicly available Computer Science courses from Stanford](https://www.classcentral.com/report/stanford-on-campus-courses)\n5. [Code Academy course on C#](https://codecademy.com/learn/learn-c-sharp)\n6. [Has great tutorials on using C# with Unity](https://learn.unity.com/)"
}
]
)
.setFooter({ text: `Most programming problems come from not knowing how to use the language - if you haven’t programmed much or you’re not confident about the OOP concepts in your mind, it's useful to understand these before diving into the engine.` })
interaction.reply({ embeds: [embedMsg] });
}
Expand Down
81 changes: 81 additions & 0 deletions SlashCommands/Custom Commands/tex.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
const puppeteer = require('puppeteer-core');
const { SlashCommandBuilder } = require('discord.js');
require('dotenv').config()
const katex = require('katex');

module.exports = {
name: 'buildtex',
data: new SlashCommandBuilder()
.setName('buildtex')
.setDescription('sends an image link of generated tex')
.addStringOption((option) =>
option.setName('tex').setDescription('tex code to be generated').setRequired(true)
),

async execute(client, interaction, Discord) {
let height = 0;
let width = 0;
try {
interaction.reply('Connecting...');
const latexText = interaction.options.getString('tex');

const html = `
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex/dist/katex.min.css">
<style>
body{
background-color: #1f1f1f;
color: #dcddde;
}
.katex{
font-size: 38pt;
text-align: left;
margin: 0;
}
.base{
margin: .5rem;
padding: .5rem;
}
#katexBuilt{
width: fit-content;
padding: .5rem;
display: block;
}
</style>
</head>
<body>
<div id="katexBuilt">${katex.renderToString(latexText, { displayMode: true })}</div>
</body>
</html>
`;

const browser = await puppeteer.connect({
browserWSEndpoint: `wss://chrome.browserless.io?token=${process.env.API_KEY_BLC}`,
});
interaction.editReply("Connected!")
const page = await browser.newPage();
await page.setViewport({
width: 960,
height: 760,
deviceScaleFactor: 1,
});
interaction.editReply("Generating...")
await page.setContent(html, { waitUntil: 'networkidle0' });
const hw = await page.$eval('#katexBuilt', el => {
h = el.offsetHeight
w = el.offsetWidth
return { height: h, width: w }
});
height = hw.height
width = hw.width
await page.screenshot({ path: 'GeneratedImages/screenshot.png', clip: { x: 0, y: 0, width: width, height: height } });
await browser.close();
interaction.editReply('Generated! To get full details of latex input visit this site!\n[katex reference table](<https://katex.org/docs/support_table.html>)');
} catch (error) {
console.error('An error occurred:', error);
} finally {
await interaction.editReply({ files: [{ attachment: 'GeneratedImages/screenshot.png' }] });
}
},
};
2 changes: 1 addition & 1 deletion SlashCommands/Custom Commands/toggler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ module.exports = {
.setDescription('sends the cdn link and docs links for toggler.js'),

async execute(client, interaction, Discord) {
interaction.reply("Link for Toggler CDN:\n https://cdn.jsdelivr.net/gh/Chandra-sekhar-pilla/Toggler@main/Toggler.js\n\nToggler Docs:\nhttps://the-atelier.ml/Pages/Toggler/toggler.html")
interaction.reply("[Toggler.js CDN](https://cdn.jsdelivr.net/gh/Chandra-sekhar-pilla/Toggler@main/Toggler.js)\n\n[Toggler Docs](https://csp02.me/The-Atelier/Pages/Toggler/toggler.html)")
}
}
17 changes: 16 additions & 1 deletion SlashCommands/Fun/ask.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,22 @@ module.exports = {
const question = interaction.options.getString("question");
if (!question) return await interaction.reply("Please enter the question ! ");
if (interaction.member.user.id != '437277018632093718') {
const replies = ["Yes", "No", "Maybe", "Never", "Definitely!", "Ask again later", "Most likely", "Cannot predict now.", "indeed", "perhaps", `${emote}`]
const replies = [
"Yes",
"No",
"Maybe",
"Never",
"Definitely!",
"Ask again later",
"Most likely",
"Cannot predict now.",
"indeed",
"perhaps",
`${emote}`,
`The What ${emote}`,
"Absolutely", "Definitely not", "Of course", "Certainly", "No way", "Without a doubt", "I don't think so", "You bet", "Not at all", "It's possible", "I'm afraid not", "I doubt it", "For sure", "Negative", "I'm inclined to say yes", "I'm leaning towards no",
"Yep", "Nah", "True", "False", "Sure thing", "Not really", "I suppose so", "Unlikely", "Absolutely not", "I'm not so sure", "You got it", "No doubt", "In all likelihood", "It's unlikely", "I'd say so", "It's a possibility", "Certainly not", "Not in a million years", "You're right", "I can't say for certain",
"I'm not quite sure, but maybe?", "I'm a bit confused, but I'll go with yes.", "Hmm, I'm not sure how to answer that with a simple yes or no.", "This is a tough one... I'm leaning towards yes, though.", "Oh, I'm feeling a bit puzzled here. Let's say yes for now?", "Well, this question has me scratching my head, but I'll tentatively say no.", "I'm a bit lost, but let's go with a hesitant yes.", "Honestly, I'm baffled. Maybe yes?", "My circuits are a bit jumbled by this question. I guess no?", "I'm in a state of confusion here, but my gut says yes.", "Confusion overload! How about a confused yes?", "I'm as confused as a cat in a dog park, but let's say no.", "This question has me stumped, but I'll opt for a cautious yes.", "I'm divided on this one. Let's settle for a puzzled no.", "Can I phone a friend? Just kidding! I'll say yes, I think.", "I'm feeling like a compass in a magnetic storm, but my compass points to no.", "I'm tangled up in thought, but I'll say no for now."]
const answer = Math.floor(Math.random() * replies.length);
const embed = new Discord.EmbedBuilder()
.setColor('#e08aff')
Expand Down
2 changes: 1 addition & 1 deletion SlashCommands/Fun/emote.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = {
const msg = await interaction.channel.messages.fetch(replyMsg.split('/')[replyMsg.split('/').length - 1])
const emoji = await interaction.client.emojis.cache.find(emo => emo.name === emoteReq)
await msg.reply(`${emoji} sent by ${await interaction.user}`).catch(console.error)
await interaction.reply({ content: "Reaction sent!", ephimeral: true }).catch(console.error)
await interaction.reply({ content: "Reaction sent!", ephemeral: true }).catch(console.error)
} else {
let emote = await interaction.client.emojis.cache.find(emo => emo.name === emoteReq)
if (emote) {
Expand Down
10 changes: 7 additions & 3 deletions SlashCommands/Moderation/clear.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { SlashCommandBuilder } = require('discord.js');
const wait = require('node:timers/promises').setTimeout;

module.exports = {
name: 'clear',
data: new SlashCommandBuilder()
Expand All @@ -18,6 +20,8 @@ module.exports = {
try {
const amount = await interaction.options.getInteger('amount')

await interaction.deferReply()
await interaction.editReply("Cleared")
if (interaction.options.getUser('user')) {
const target = await interaction.guild.members.fetch(await interaction.options.getUser('user').id)
const messagesMap = await interaction.channel.messages.fetch()
Expand All @@ -27,7 +31,7 @@ module.exports = {
userMessagesMap.forEach(userMsg => {
userMsg.delete()
})
interaction.reply(`**${amount}** ${target}'s messages have been deleted!`)
await interaction.editReply(`**${amount}** ${target}'s messages have been deleted!`)
}
else {
if (!amount) return interaction.reply("please enter the number of messages you want to clear");
Expand All @@ -39,8 +43,8 @@ module.exports = {
interaction.channel.send(e.interaction)
});
});

interaction.reply(`**${amount}** messages have been deleted!`)
await wait(2000)
await interaction.channel.send(`**${amount}** messages have been deleted!`)
}
} catch (e) {
require(`../../handlers/ErrorHandler.js`)(client, interaction, Discord, e, this.name)
Expand Down
10 changes: 5 additions & 5 deletions SlashCommands/Moderation/infraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ module.exports = {
else {
let infrIds = ""
if (infractionId) {
const warnings = results.warnings.filter((warning) => {
return warning.infrID === infractionId
const warnings = results.warnings.filter(warning => {
if (warning.infrID === infractionId)
return warning
})

if (warnings.length <= 0) return interaction.reply("Infraction not found for the given id!")
embedMsg.setTitle('Infraction')
.setColor('#ff0000')
.setFooter({ text: `Infraction ID: ${infractionId}` })
Expand All @@ -46,11 +47,10 @@ module.exports = {
const warnings = results.warnings.filter((warning) => {
return warning.userID === `${mentionedUser.id}`
})

// if(warnings.length <= 0) return interaction.reply("Infraction not found for this user!")
warnings.forEach(warning => {
infrIds += `${warning.infrID}, `
})

embedMsg.setTitle('Infraction')
.setColor('#ff0000')
.setFooter({ text: `Infractions of user ${mentionedUser}` })
Expand Down
Loading

0 comments on commit a1c5db7

Please sign in to comment.