Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quality of life update #61

Merged
merged 26 commits into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1030655
Add questions
mezotv Feb 9, 2023
6eba6c2
Rather.js update
mezotv Feb 11, 2023
38e1dee
Add images and canvas command
mezotv Feb 13, 2023
310cb47
Fix bug + language support
mezotv Feb 13, 2023
d4f2e8d
Add more questions
mezotv Feb 15, 2023
0aebea1
Added text resize
mezotv Feb 15, 2023
4854293
Add custom strings
mezotv Feb 15, 2023
70b08fc
Finish new rather command
mezotv Feb 21, 2023
4b2a278
Created settings.js
forgetfulskybro Feb 23, 2023
091d2a9
Fix settings command and translation
mezotv Feb 23, 2023
c764547
Fixed emojis
forgetfulskybro Feb 23, 2023
6750bec
Merge branch 'quality-of-life-update' of https://github.com/Would-You…
forgetfulskybro Feb 23, 2023
c5fe522
Adds never have I ever mode
mezotv Feb 23, 2023
8b951c5
Deleted translations for welcome and dailyMsgs
forgetfulskybro Feb 23, 2023
f77ded4
Merge branch 'quality-of-life-update' of https://github.com/Would-You…
forgetfulskybro Feb 23, 2023
4efeace
More settings (unfinished)
mezotv Feb 23, 2023
4fc9435
Fixed embed
forgetfulskybro Feb 24, 2023
7e74dd3
Feat: emit command, user ping
mezotv Feb 24, 2023
12fc5c6
Add more wwyd questions
mezotv Mar 1, 2023
22ed1cb
Improve either.js
mezotv Mar 4, 2023
c0a8c74
Merge branch 'main' of https://github.com/Would-You-Bot/Would-You int…
mezotv Mar 4, 2023
fa9630a
Resolve conflicts
mezotv Mar 4, 2023
f45ec24
Add either.js class
mezotv Mar 10, 2023
f0fc19f
Add replay and vote cooldown
mezotv Mar 11, 2023
0102b49
String + Either update
mezotv Mar 11, 2023
2e7d843
Update info.js
mezotv Mar 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add images and canvas command
  • Loading branch information
mezotv committed Feb 13, 2023
commit 38e1dee5d1b8a04fcbdf2675d5e2cb73fac74429
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"homepage": "https://github.com/Developer-Dungeon-Studio/Would-You#readme",
"dependencies": {
"@discordjs/rest": "^1.2.0",
"@napi-rs/canvas": "^0.1.34",
"@top-gg/sdk": "^3.1.3",
"axios": "^1.2.2",
"chalk-advanced": "^1.0.3",
Expand Down
85 changes: 85 additions & 0 deletions src/commands/canvas.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
const {
EmbedBuilder,
ActionRowBuilder,
ButtonBuilder,
SlashCommandBuilder,
} = require('discord.js');
const guildModel = require('../util/Models/guildModel');

module.exports = {
requireGuild: true,
data: new SlashCommandBuilder()
.setName('canvas')
.setDescription('Generate a canvas image')
.setDMPermission(false)
.setDescriptionLocalizations({
de: 'Zeigt den Ping des Clients an',
"es-ES": 'Muestra el ping del cliente'
}),

/**
* @param {CommandInteraction} interaction
* @param {Client} client
* @param {guildModel} guildDb
*/
async execute(interaction, client, guildDb) {
const Canvas = require("@napi-rs/canvas");
const canvas = Canvas.createCanvas(800, 600);
const ctx = canvas.getContext("2d");

// Set background color
ctx.fillStyle = "lightgray";
ctx.fillRect(0, 0, canvas.width, canvas.height);

// Draw title
ctx.font = "48px sans-serif";
ctx.fillStyle = "black";
ctx.textAlign = "center";
ctx.fillText("Would You Rather?", canvas.width / 2, 50);

// Draw first question
ctx.font = "36px sans-serif";
ctx.fillStyle = "blue";
ctx.textAlign = "left";
ctx.fillText("Option A", 50, 150);

// Draw second question
ctx.font = "36px sans-serif";
ctx.fillStyle = "red";
ctx.textAlign = "right";
ctx.fillText("Option B", canvas.width - 50, 150);

// Draw separator line
ctx.beginPath();
ctx.moveTo(0, 100);
ctx.lineTo(canvas.width, 100);
ctx.lineWidth = 2;
ctx.strokeStyle = "black";
ctx.stroke();

// Draw circles around the questions
ctx.beginPath();
ctx.arc(50, 150, 40, 0, 2 * Math.PI);
ctx.fillStyle = "blue";
ctx.fill();
ctx.strokeStyle = "black";
ctx.lineWidth = 2;
ctx.stroke();

ctx.beginPath();
ctx.arc(canvas.width - 50, 150, 40, 0, 2 * Math.PI);
ctx.fillStyle = "red";
ctx.fill();
ctx.strokeStyle = "black";
ctx.lineWidth = 2;
ctx.stroke();

const fs = require("fs");
const out = fs.createWriteStream(__dirname + "/would-you-rather.png");
const stream = canvas.toBuffer("image/png");
out.write(stream);
out.end();


},
};
Binary file added src/commands/would-you-rather.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/data/Images/WouldYouRather.psd
Binary file not shown.
Binary file added src/data/Images/rather-de.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/data/Images/rather-en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/data/Images/rather-es.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/data/Images/template.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
20 changes: 19 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
const WouldYou = require('./util/wouldYou');
const {ChalkAdvanced} = require("chalk-advanced");

// Token to UserID Function
// Credits to Meister#9667 for helping me with this
const retriveUserIdbyToken = (token) => {
const parseuser = (token.split('.'))[0]
const buff = Buffer.from(parseuser, 'base64');
const userid = buff.toString('utf-8');
return userid;
}

global.devBot = false;

const botId = retriveUserIdbyToken(process.env.DISCORD_TOKEN);
if(botId !== '981649513427111957' || process.env.STATUS === 'DEVELOPMENT') {
global.devBot = true;
} else if(process.env.STATUS === 'DEVELOPMENT' && botId === '981649513427111957') {
throw new Error('Are you stupid? Why should you run the main bot with status "DEVELOPMENT"?!');
}

const client = new WouldYou();
client.loginBot().then(() => {
console.log(
`${ChalkAdvanced.white('Would You?')} ${ChalkAdvanced.gray(
'>',
)} ${ChalkAdvanced.green('Bot should be started now...')}`,
);
})
})
87 changes: 77 additions & 10 deletions src/util/keepAlive.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
} = require('discord.js');

const {inspect} = require('util');
const {ChalkAdvanced} = require("chalk-advanced");

const warnWebhook = new WebhookClient({
url: process.env.WARNWEBHOOKURL,
Expand All @@ -20,20 +21,64 @@ module.exports = class KeepAlive {
this.c = client;
}

/**
* Log a message to the console
* @param type
* @param msg
* @param _optionalData
* @private
*/
consoleError(type, msg, _optionalData = '') {
console.log(
`${ChalkAdvanced.white(type)} ${ChalkAdvanced.gray(
'>',
)} ${ChalkAdvanced.red(msg)}`,
_optionalData,
);
}

/**
* Start the keep alive system (listener to the process)
*/
start() {
this.c.ws.on('rateLimit', (log) => {
const { path, limit, timeout } = log;

this.consoleError('RateLimit', 'We got rate-limited at', `Path: ${path} Limit: ${limit} Timeout: ${timeout}`);
const embed = new EmbedBuilder()
.setTitle('Rate limited')
.setColor(global?.devBot ? "#e407f5" : "#6e0000")
.addFields([{
name: 'Rate-limit Info',
value: `Path: \`${path}\`\nLimit: \`${limit}\`\nTimeout: \`${timeout}\``,
}])
.setFooter({
text: global?.devBot ? 'Dev Bot' : 'Main Bot',
})
.setTimestamp();

warnWebhook
.send({
embeds: [embed],
})
.catch((err) => {
});
})

this.c.on('debug', (e) => {
if (!e.includes('ratelimit')) return;

console.log('[BOT] Watch-out Possible Rate-limit...\n', e);
this.consoleError('Debug', 'Watch-out Possible Rate-limit...', e);
const embed = new EmbedBuilder()
.setTitle('Watch-out Possible Rate-limit...')
.setColor(global?.devBot ? "#e407f5" : "#F00505")
.addFields([{
name: 'Info',
value: `\`\`\`${inspect(e, {depth: 0})}\`\`\``,
}])
.setFooter({
text: global?.devBot ? 'Dev Bot' : 'Main Bot',
})
.setTimestamp();

warnWebhook
Expand All @@ -45,49 +90,59 @@ module.exports = class KeepAlive {
});

this.c.on('error', (e) => {
console.log('[BOT] Bot got a error...\n\n', e);
this.consoleError('Error', 'Bot got a error...', e);
const embed = new EmbedBuilder()
.setTitle('Bot got a error...')
.setColor(global?.devBot ? "#e407f5" : "#05b1f0")
.addFields([{
name: 'Error',
value: `\`\`\`${inspect(e, {depth: 0})}\`\`\``,
}])
.setFooter({
text: global?.devBot ? 'Dev Bot' : 'Main Bot',
})
.setTimestamp();

errorWebhook
.send({
username: global?.devBot ? 'Dev Bot' : 'Main Bot',
embeds: [embed],
})
.catch((err) => {
});
});

this.c.on('warn', async (info) => {
console.log('[BOT] Bot got a warn...\n\n', info);
this.consoleError('Error', 'Bot got a warn...', info);
const embed = new EmbedBuilder()
.setTitle('Bot got a warn...')
.setColor(global?.devBot ? "#e407f5" : "#05b1f0")
.addFields([{
name: 'Info',
value: `\`\`\`${inspect(info, {depth: 0})}\`\`\``,
}])
.setFooter({
text: global?.devBot ? 'Dev Bot' : 'Main Bot',
})
.setTimestamp();

warnWebhook
.send({
username: global?.devBot ? 'Dev Bot' : 'Main Bot',
embeds: [embed],
})
.catch((err) => {
});
});

process.on('unhandledRejection', async (reason, p) => {
console.log('[BOT | FATAL ERROR] Unhandled Rejection/Catch');
this.consoleError('Fatal Error', 'Unhandled Rejection/Catch');
console.log(reason, p);

const embed = new EmbedBuilder()
.setTitle('New Unhandled Rejection/Catch')
.setDescription(`\`\`\`${reason}\`\`\``)
.setColor('#4E5D94')
.setColor(global?.devBot ? "#e407f5" : "#F00505")
.addFields([
{
name: 'Reason',
Expand All @@ -98,24 +153,28 @@ module.exports = class KeepAlive {
value: `\`\`\`${inspect(p, {depth: 0})}\`\`\``,
},
])
.setFooter({
text: global?.devBot ? 'Dev Bot' : 'Main Bot',
})
.setTimestamp();

errorWebhook
.send({
username: global?.devBot ? 'Dev Bot' : 'Main Bot',
embeds: [embed],
})
.catch((err) => {
});
});

process.on('uncaughtException', async (err, origin) => {
console.log('[BOT | FATAL ERROR] Uncaught Exception/Catch');
this.consoleError('Fatal Error', 'Uncaught Exception/Catch');
console.log(err, origin);

const embed = new EmbedBuilder()
.setTitle('New uncaughtException')
.setDescription(`\`\`\`${err}\`\`\``)
.setColor('#4E5D94')
.setColor(global?.devBot ? "#e407f5" : "#F00505")
.addFields([
{
name: 'Error',
Expand All @@ -126,23 +185,27 @@ module.exports = class KeepAlive {
value: `\`\`\`${inspect(origin, {depth: 0})}\`\`\``,
},
])
.setFooter({
text: global?.devBot ? 'Dev Bot' : 'Main Bot',
})
.setTimestamp();

errorWebhook
.send({
username: global?.devBot ? 'Dev Bot' : 'Main Bot',
embeds: [embed],
})
.catch((err) => {
});
});
process.on('uncaughtExceptionMonitor', async (err, origin) => {
console.log('[BOT | FATAL ERROR] Uncaught Exception/Catch (MONITOR)');
this.consoleError('Fatal Error', 'Uncaught Exception/Catch (MONITOR)');
console.log(err, origin);

const embed = new EmbedBuilder()
.setTitle('New uncaughtExceptionMonitor' + `${global?.CustomBot ? ' (Custom Bot)' : ''}`)
.setDescription(`\`\`\`${err}\`\`\``)
.setColor('#4E5D94')
.setColor(global?.devBot ? "#e407f5" : "#F00505")
.addFields([
{
name: 'Error',
Expand All @@ -153,14 +216,18 @@ module.exports = class KeepAlive {
value: `\`\`\`${inspect(origin, {depth: 0})}\`\`\``,
},
])
.setFooter({
text: global?.devBot ? 'Dev Bot' : 'Main Bot',
})
.setTimestamp();

errorWebhook
.send({
username: global?.devBot ? 'Dev Bot' : 'Main Bot',
embeds: [embed],
})
.catch((err) => {
});
});
}
}
}
Loading