Skip to content

Commit

Permalink
3.0.1 bugfixes
Browse files Browse the repository at this point in the history
1. fixed a bug with text with textWidth() (levels, card), non standard character xoffset was set to 0 but emoji caused it to crash, replaces emoji with '*'

2. improved error reporting (levels), if the specified image is not found, posts the 404 background instead

3. finally fixed that cunty bug (levels), forgot to adjust image proportions to fit backgroud size, assumed it was a square, its actually 800x750 teehe

4. updated to mongod v3.4.18 on the awesomo3 server to allow for some of the voodoo shit were doing with that (levels?, activity, shits)

5. rewrote the guild discovery part of bot preloading (incorrect guild count on scritps), new guilds are now added synchronously so the same script cant be loaded twice at the same time and be overwritten

6. added playing status and version (in config)
  • Loading branch information
Dragon1320 committed Nov 7, 2018
1 parent 3d6a2dd commit 2d49e90
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 50 deletions.
Binary file added src/bot/commands/assets/404.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 12 additions & 2 deletions src/bot/commands/levels.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const {
printCenter
} = require("./libs/jimp_print");

let defaultBanner = null;

let fontLevel = null;
let fontPercent = null;
let fontRank = null;
Expand Down Expand Up @@ -167,15 +169,21 @@ const levels = new Command({

const bg = new jimp(800, 750);

const banner = await jimp.read(users[0].banner);
//const let = await jimp.read(users[0].banner);
let banner = await jimp.read("https://cdn.discordapp.com/attachments/449655476297138177/502508170019864586/tweekxcraig.png");
if (banner === undefined) {

banner = defaultBanner;
}

const prop = banner.bitmap.width / banner.bitmap.height;
const prop = (banner.bitmap.width / banner.bitmap.height) * (bg.bitmap.width / bg.bitmap.height);
if (prop >= 1) {

// change height
const heightDiff = bg.bitmap.height - banner.bitmap.height;
banner.resize((banner.bitmap.height + heightDiff) * prop, banner.bitmap.height + heightDiff);

// 750x750 (375 - 400, 0, 800, 750)
banner.crop((banner.bitmap.width / 2) - bg.bitmap.width / 2, 0, bg.bitmap.width, bg.bitmap.height);
banner.blur(2);

Expand Down Expand Up @@ -298,6 +306,8 @@ const levels = new Command({
load: function () {
return new Promise(async (resolve, reject) => {

defaultBanner = await jimp.read(path.join(__dirname, "assets", "404.jpg"));

fontLevel = await jimp.loadFont(path.join(__dirname, "assets", "fonts", "fontLevel.fnt"));
fontPercent = await jimp.loadFont(path.join(__dirname, "assets", "fonts", "fontPercent.fnt"));
fontRank = await jimp.loadFont(path.join(__dirname, "assets", "fonts", "fontRank.fnt"));
Expand Down
205 changes: 157 additions & 48 deletions src/bot/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ const initClient = async () => {
commands[i]._id = script._id
validCommands.push(commands[i]);

botLogger.log("stadtup", `validated local command: ${commands[i].name}`);
botLogger.log("stdout", `validated local command: ${commands[i].name}`);
}
}

Expand Down Expand Up @@ -243,66 +243,82 @@ const initClient = async () => {

client.on("guildCreate", async guild => {

// add guilds that are not already in the database
schemas.GuildSchema
.findOne({ discord_id: guild.id })
.then(async dbguild => {
// make sure all the local commands are loaded before attempting to load/add guilds
const preloadLocal = await commands;

// already in the database
if (dbguild !== null) {
const clientGuilds = client.guilds.array();
for (let guild of clientGuilds) {

return;
}
await schemas.GuildSchema
.findOne({
discord_id: guild.id
})
.then(async dbguild => {

// preload base commands
const local = await commands;
const preload = local.filter(e => e.preload === true).map(e => e.name);
if (dbguild !== null) {

schemas.ScriptSchema
.find({ author_id: "feinwaru-devs", name: { $in: preload } })
.then(scripts => {
// already in the database
botLogger.log("stdout", `successfully loaded guild: ${guild.name}, ${guild.id}`);
return;
}

// add new guild to the database
dbguild = new schemas.GuildSchema({
discord_id: guild.id,
scripts: []
});
// add new guild to database and preload it with local commands
const preloadLocalNames = preloadLocal.map(e => e.name);
await schemas.ScriptSchema
.find({
author_id: "feinwaru-devs",
name: {
$in: preloadLocalNames
}
})
.then(async dbscripts => {

for (let script of scripts) {
const newGuild = new schemas.GuildSchema({
discord_id: guild.id,
scripts: []
});

script.guild_count++;
script
.save()
.catch(error => {
const promises = [];

for (let dbscript of dbscripts) {

botLogger.error(`could increment preload script guild count: ${error}`);
dbscript.guild_count++;

promises.push(dbscript.save());

newGuild.scripts.push({
object_id: dbscript._id
});
}

await Promise
.all(promises)
.catch(error => {

botLogger.error(`failed to update preload scripts for new guild: ${guild.name}, ${guild.id}: ${error}`);
});

dbguild.scripts.push({
object_id: script._id
});
}
await newGuild
.save()
.then(() => {

dbguild
.save()
.then(() => {
botLogger.log("stdout", `successfully added new guild: ${guild.name}, ${guild.id}`);
})
.catch(error => {

botLogger.log("stdout", `successully added new guild: ${guild.name}, ${guild.id}`);
botLogger.error(`failed to save new guild: ${guild.name}, ${guild.id}: ${error}`);
});
})
.catch(error => {

botLogger.error(`failed to save guild: ${guild.name}, ${guild.id}: ${error}`);
});
})
.catch(error => {

botLogger.error(`error adding guild, could not preload base commands: ${error}`);
});
})
.catch(error => {
botLogger.error(`failed to find preload scripts for new guild: ${guild.name}, ${guild.id}: ${error}`);
});
})
.catch(error => {

botLogger.error(`failed to add guild: ${guild.name}, ${guild.id}: ${error}`);
});
botLogger.error(`failed to load guild from database: ${guild.name}, ${guild.id}: ${error}`);
});
}
});

/*
Expand Down Expand Up @@ -781,6 +797,100 @@ const initClient = async () => {

client.on("ready", async () => {

// make sure all the local commands are loaded before attempting to load/add guilds
const preloadLocal = await commands;

const clientGuilds = client.guilds.array();
for (let guild of clientGuilds) {

await schemas.GuildSchema
.findOne({
discord_id: guild.id
})
.then(async dbguild => {

if (dbguild !== null) {

// already in the database
botLogger.log("stdout", `successfully loaded guild: ${guild.name}, ${guild.id}`);
return;
}

// add new guild to database and preload it with local commands
const preloadLocalNames = preloadLocal.map(e => e.name);
await schemas.ScriptSchema
.find({
author_id: "feinwaru-devs",
name: {
$in: preloadLocalNames
}
})
.then(async dbscripts => {

const newGuild = new schemas.GuildSchema({
discord_id: guild.id,
scripts: []
});

const promises = [];

for (let dbscript of dbscripts) {

dbscript.guild_count++;

promises.push(dbscript.save());

newGuild.scripts.push({
object_id: dbscript._id
});
}

await Promise
.all(promises)
.catch(error => {

botLogger.error(`failed to update preload scripts for new guild: ${guild.name}, ${guild.id}: ${error}`);
});

await newGuild
.save()
.then(() => {

botLogger.log("stdout", `successfully added new guild: ${guild.name}, ${guild.id}`);
})
.catch(error => {

botLogger.error(`failed to save new guild: ${guild.name}, ${guild.id}: ${error}`);
});
})
.catch(error => {

botLogger.error(`failed to find preload scripts for new guild: ${guild.name}, ${guild.id}: ${error}`);
});
})
.catch(error => {

botLogger.error(`failed to load guild from database: ${guild.name}, ${guild.id}: ${error}`);
});
}

client.user
.setActivity(
`AWESOM-O ${config.version}`,
{
type: "PLAYING"
}
)
.then(() => {

botLogger.log("stdout", "bot ready");
})
.catch(error => {

botLogger.error(`could not set bot activity: ${error}`);
});

/*
await commands;
// go through each guild the bot is on and add it to the database if its not already there
Expand Down Expand Up @@ -853,16 +963,15 @@ const initClient = async () => {
botLogger.log("stdout", "bot ready");


}).catch(error => {
``
botLogger.fatalError(`error saving new guilds: ${error}`);
});
}).catch(error => {
botLogger.fatalError(`error loading guilds: ${error}`);
});
*/
});

/*`
Expand Down
6 changes: 6 additions & 0 deletions src/utils/print.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const textWidth = (font, str) => {
let width = 0;

for (let i = 0; i < str.length; i++) {

if (font.chars[str[i]] === undefined) {

str[i] = "*";
}

width += font.chars[str[i]].xoffset + font.chars[str[i]].xadvance;
}

Expand Down

0 comments on commit 2d49e90

Please sign in to comment.