Make log files rotate, clean up separated text input, add more uncanny images, use a more reliable method to get the instance owner username

This commit is contained in:
Essem 2022-08-03 20:54:07 -05:00
parent b0f4c16d50
commit 4265e3e914
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
22 changed files with 128 additions and 88 deletions

5
app.js
View file

@ -24,6 +24,7 @@ import PrometheusWorker from "./utils/services/prometheus.js";
// some utils
import { promises, readFileSync } from "fs";
import winston from "winston";
import "winston-daily-rotate-file";
import { exec as baseExec } from "child_process";
import { promisify } from "util";
@ -113,8 +114,8 @@ if (isMaster) {
},
transports: [
new winston.transports.Console({ format: winston.format.colorize({ all: true }), stderrLevels: ["error", "warn"] }),
new winston.transports.File({ filename: "logs/error.log", level: "error" }),
new winston.transports.File({ filename: "logs/main.log" })
new winston.transports.DailyRotateFile({ filename: "logs/error-%DATE%.log", level: "error", zippedArchive: true, maxSize: 4194304, maxFiles: 8 }),
new winston.transports.DailyRotateFile({ filename: "logs/main-%DATE%.log", zippedArchive: true, maxSize: 4194304, maxFiles: 8 })
],
level: process.env.DEBUG_LOG ? "debug" : "main",
format: winston.format.combine(

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 396 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 314 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 426 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 484 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

View file

@ -81,20 +81,17 @@ class ImageCommand extends Command {
}
if (this.constructor.requiresText) {
const text = this.options.text ?? this.args;
if (text.length === 0 || !await this.criteria(text)) {
const text = this.options.text ?? this.args.join(" ").trim();
if (text.length === 0 || !await this.criteria(text, magickParams.url)) {
runningCommands.delete(this.author.id);
return this.constructor.noText;
}
}
switch (typeof this.params) {
case "function":
Object.assign(magickParams.params, this.params(magickParams.url, magickParams.name));
break;
case "object":
Object.assign(magickParams.params, this.params);
break;
if (typeof this.params === "function") {
Object.assign(magickParams.params, this.params(magickParams.url, magickParams.name));
} else if (typeof this.params === "object") {
Object.assign(magickParams.params, this.params);
}
let status;

View file

@ -9,7 +9,8 @@ const exec = promisify(baseExec);
class InfoCommand extends Command {
async run() {
const owner = await this.ipc.fetchUser(process.env.OWNER.split(",")[0]);
let owner = await this.ipc.fetchUser(process.env.OWNER.split(",")[0]);
if (!owner) owner = await this.client.getRESTUser(process.env.OWNER.split(",")[0]);
const stats = await this.ipc.getStats();
return {
embeds: [{

View file

@ -1,11 +1,9 @@
import ImageCommand from "../../classes/imageCommand.js";
class GrayscaleCommand extends ImageCommand {
params() {
return {
color: "grayscale"
};
}
params = {
color: "grayscale"
};
static description = "Adds a grayscale filter";

View file

@ -1,9 +1,18 @@
import ImageCommand from "../../classes/imageCommand.js";
class MemeCommand extends ImageCommand {
async criteria(text, url) {
const [topText, bottomText] = text.replaceAll(url, "").split(/(?<!\\),/).map(elem => elem.trim());
if (topText === "" && bottomText === "") {
return false;
} else {
return true;
}
}
params(url) {
const newArgs = this.options.text ?? this.args.filter(item => !item.includes(url)).join(" ");
const [topText, bottomText] = newArgs.split(/(?<!\\),/).map(elem => elem.trim());
const newArgs = this.options.text ?? this.args.join(" ");
const [topText, bottomText] = newArgs.replaceAll(url, "").split(/(?<!\\),/).map(elem => elem.trim());
return {
top: (this.options.case ? topText : topText.toUpperCase()).replaceAll("&", "&amp;").replaceAll(">", "&gt;").replaceAll("<", "&lt;").replaceAll("\"", "&quot;").replaceAll("'", "&apos;").replaceAll("\\n", "\n"),
bottom: bottomText ? (this.options.case ? bottomText : bottomText.toUpperCase()).replaceAll("&", "&amp;").replaceAll(">", "&gt;").replaceAll("<", "&lt;").replaceAll("\"", "&quot;").replaceAll("'", "&apos;").replaceAll("\\n", "\n") : "",

View file

@ -1,9 +1,18 @@
import ImageCommand from "../../classes/imageCommand.js";
class MotivateCommand extends ImageCommand {
async criteria(text, url) {
const [topText, bottomText] = text.replaceAll(url, "").split(/(?<!\\),/).map(elem => elem.trim());
if (topText === "" && bottomText === "") {
return false;
} else {
return true;
}
}
params(url) {
const newArgs = this.options.text ?? this.args.filter(item => !item.includes(url)).join(" ");
const [topText, bottomText] = newArgs.split(/(?<!\\),/).map(elem => elem.trim());
const newArgs = this.options.text ?? this.args.join(" ");
const [topText, bottomText] = newArgs.replaceAll(url, "").split(/(?<!\\),/).map(elem => elem.trim());
return {
top: topText.replaceAll("&", "&amp;").replaceAll(">", "&gt;").replaceAll("<", "&lt;").replaceAll("\"", "&quot;").replaceAll("'", "&apos;").replaceAll("\\n", "\n"),
bottom: bottomText ? bottomText.replaceAll("&", "&amp;").replaceAll(">", "&gt;").replaceAll("<", "&lt;").replaceAll("\"", "&quot;").replaceAll("'", "&apos;").replaceAll("\\n", "\n") : "",

View file

@ -1,11 +1,9 @@
import ImageCommand from "../../classes/imageCommand.js";
class SepiaCommand extends ImageCommand {
params() {
return {
color: "sepia"
};
}
params = {
color: "sepia"
};
static description = "Adds a sepia filter";

View file

@ -1,11 +1,9 @@
import ImageCommand from "../../classes/imageCommand.js";
class SooSCommand extends ImageCommand {
params() {
return {
soos: true
};
}
params = {
soos: true
};
static description = "\"Loops\" an image sequence by reversing it when it's finished";
static aliases = ["bounce", "boomerang"];

View file

@ -10,9 +10,9 @@ const names = readdirSync(resolve(dirname(fileURLToPath(import.meta.url)), "../.
class UncannyCommand extends ImageCommand {
params(url, name = "unknown") {
const newArgs = this.options.text ?? this.args.filter(item => !item.includes(url)).join(" ");
const newArgs = this.options.text ?? this.args.join(" ");
// eslint-disable-next-line prefer-const
let [text1, text2] = newArgs.split(/(?<!\\),/).map(elem => elem.trim());
let [text1, text2] = newArgs.replaceAll(url, "").split(/(?<!\\),/).map(elem => elem.trim());
if (!text2?.trim()) text2 = name;
return {
caption: text1?.trim() ? text1.replaceAll("&", "&amp;").replaceAll(">", "&gt;").replaceAll("<", "&lt;").replaceAll("\"", "&quot;").replaceAll("'", "&apos;").replaceAll("\\n", "\n") : random(prompts),

View file

@ -23,7 +23,8 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) {
VImage::new_from_buffer(data.Data(), data.Length(), "",
type == "gif" ? options->set("n", -1) : options)
.colourspace(VIPS_INTERPRETATION_sRGB);
if (!in.has_alpha()) in = in.bandjoin(255);
if (!in.has_alpha())
in = in.bandjoin(255);
int width = in.width();
int size = width / 5;
@ -33,16 +34,19 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) {
string font_string = font == "roboto" ? "Roboto Condensed" : font;
string topText = "<span foreground=\"white\" background=\"black\">" +
top_text + "</span>";
VImage topImage;
if (top_text != "") {
string topText = "<span foreground=\"white\" background=\"black\">" +
top_text + "</span>";
VImage topImage = VImage::text(
topText.c_str(),
VImage::option()
->set("rgba", true)
->set("align", VIPS_ALIGN_CENTRE)
->set("font", (font_string + " " + to_string(size)).c_str())
->set("width", textWidth));
topImage = VImage::text(
topText.c_str(),
VImage::option()
->set("rgba", true)
->set("align", VIPS_ALIGN_CENTRE)
->set("font", (font_string + " " + to_string(size)).c_str())
->set("width", textWidth));
}
VImage bottomImage;
if (bottom_text != "") {
@ -82,13 +86,17 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) {
sideAddition / 2, addition / 2, bordered2.width() + sideAddition,
bordered2.height() + addition,
VImage::option()->set("extend", "black"));
VImage frame = bordered3.join(
topImage.gravity(VIPS_COMPASS_DIRECTION_NORTH, bordered3.width(),
topImage.height() + (size / 4),
VImage::option()->set("extend", "black")),
VIPS_DIRECTION_VERTICAL,
VImage::option()->set("background", 0x000000)->set("expand", true));
VImage frame;
if (top_text != "") {
frame = bordered3.join(
topImage.gravity(VIPS_COMPASS_DIRECTION_NORTH, bordered3.width(),
topImage.height() + (size / 4),
VImage::option()->set("extend", "black")),
VIPS_DIRECTION_VERTICAL,
VImage::option()->set("background", 0x000000)->set("expand", true));
}
if (bottom_text != "") {
if (top_text == "") frame = bordered3;
frame = frame.join(
bottomImage.gravity(VIPS_COMPASS_DIRECTION_NORTH, bordered3.width(),
bottomImage.height() + (size / 4),
@ -105,9 +113,9 @@ Napi::Value Motivate(const Napi::CallbackInfo &info) {
void *buf;
size_t length;
final.write_to_buffer(
("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 1) : 0);
final.write_to_buffer(("." + type).c_str(), &buf, &length,
type == "gif" ? VImage::option()->set("dither", 1)
: 0);
result.Set("data", Napi::Buffer<char>::Copy(env, (char *)buf, length));
result.Set("type", type);

View file

@ -37,8 +37,9 @@
"node-fetch": "^3.2.9",
"qrcode": "^1.5.1",
"sharp": "^0.30.7",
"shoukaku": "^3.1.2",
"winston": "^3.8.1"
"shoukaku": "github:TheEssem/shoukaku",
"winston": "^3.8.1",
"winston-daily-rotate-file": "^4.7.1"
},
"devDependencies": {
"@babel/core": "^7.18.9",

View file

@ -25,9 +25,10 @@ specifiers:
pg: ^8.7.3
qrcode: ^1.5.1
sharp: ^0.30.7
shoukaku: ^3.1.2
shoukaku: github:TheEssem/shoukaku
uuid: ^8.3.2
winston: ^3.8.1
winston-daily-rotate-file: ^4.7.1
ws: ^8.8.1
zlib-sync: ^0.1.7
@ -36,7 +37,7 @@ dependencies:
cmake-js: 6.3.2
dotenv: 16.0.1
emoji-regex: 10.1.0
eris: github.com/esmBot/eris/828a57e7e8f52ec1b0b50d4f7f302f25705e46cc_bufferutil@4.0.6
eris: github.com/esmBot/eris/128cd6c99086d33afda7eef4b2f9ef8d9b5bea8c_bufferutil@4.0.6
eris-fleet: 1.0.2_eris@0.17.2-dev
file-type: 17.1.2
format-duration: 2.0.0
@ -46,8 +47,9 @@ dependencies:
node-fetch: 3.2.9
qrcode: 1.5.1
sharp: 0.30.7
shoukaku: 3.1.2_bufferutil@4.0.6
shoukaku: github.com/TheEssem/shoukaku/7f1aa66df448354898a78da1ff5ed88d20c8d562_bufferutil@4.0.6
winston: 3.8.1
winston-daily-rotate-file: 4.7.1_winston@3.8.1
optionalDependencies:
better-sqlite3: 7.6.2
@ -885,7 +887,7 @@ packages:
/duplexer2/0.1.4:
resolution: {integrity: sha512-asLFVfWWtJ90ZyOUHMqk7/S2w2guQKxUI2itj3d92ADHhxUSbCMGi1f1cBcJ7xM1To+pE/Khbwo1yuNbMEPKeA==}
dependencies:
readable-stream: 2.1.5
readable-stream: 2.3.7
dev: false
/electron-to-chromium/1.4.195:
@ -919,7 +921,7 @@ packages:
peerDependencies:
eris: ~0.16.0
dependencies:
eris: github.com/esmBot/eris/828a57e7e8f52ec1b0b50d4f7f302f25705e46cc_bufferutil@4.0.6
eris: github.com/esmBot/eris/128cd6c99086d33afda7eef4b2f9ef8d9b5bea8c_bufferutil@4.0.6
dev: false
/error-ex/1.3.2:
@ -1125,6 +1127,12 @@ packages:
flat-cache: 3.0.4
dev: true
/file-stream-rotator/0.6.1:
resolution: {integrity: sha512-u+dBid4PvZw17PmDeRcNOtCP9CCK/9lRN2w+r1xIS7yOL9JFrIBKTvrYsxT4P0pGtThYTn++QS5ChHaUov3+zQ==}
dependencies:
moment: 2.29.4
dev: false
/file-type/17.1.2:
resolution: {integrity: sha512-3thBUSfa9YEUEGO/NAAiQGvjujZxZiJTF6xNwyDn6kB0NcEtwMn5ttkGG9jGwm/Nt/t8U1bpBNqyBNZCz4F4ig==}
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
@ -1596,6 +1604,10 @@ packages:
minimist: 1.2.6
dev: false
/moment/2.29.4:
resolution: {integrity: sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==}
dev: false
/ms/2.1.2:
resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==}
@ -1690,6 +1702,11 @@ packages:
engines: {node: '>=0.10.0'}
dev: false
/object-hash/2.2.0:
resolution: {integrity: sha512-gScRMn0bS5fH+IuwyIFgnh9zBdo4DV+6GhygmWM9HyNJSgS0hScp1f5vjtm7oIIOiT9trXrShAkLFSc2IqKNgw==}
engines: {node: '>= 6'}
dev: false
/once/1.4.0:
resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==}
dependencies:
@ -1786,11 +1803,6 @@ packages:
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dev: false
/petitio/1.4.0:
resolution: {integrity: sha512-9LaVd/5BLmbNU8Q4Ax8NezihiPt2ISNqi2vKilEchSSf+YSOXxfsLUb0SUmDskm1WkBOVTsqdyuyYI0RYKqr0Q==}
engines: {node: '>=12.3.0'}
dev: false
/pg-connection-string/2.5.0:
resolution: {integrity: sha512-r5o/V/ORTA6TmUnyWZR9nCj1klXCO2CEKNRlVuJptZe85QuhFayC7WeMic7ndayT5IRIR0S0xFxFi2ousartlQ==}
dev: false
@ -2162,17 +2174,6 @@ packages:
engines: {node: '>=8'}
dev: true
/shoukaku/3.1.2_bufferutil@4.0.6:
resolution: {integrity: sha512-p3dqnKx0cv2BlVi2tvi++JilVRu5wBGG6Q0GHlrpNhiEe7kxZotSJom/smodUTGr+QaEYCY3e1j3JL+TO1NRkg==}
engines: {node: '>=16.0.0', npm: '>=7.0.0'}
dependencies:
petitio: 1.4.0
ws: 8.8.1_bufferutil@4.0.6
transitivePeerDependencies:
- bufferutil
- utf-8-validate
dev: false
/simple-concat/1.0.1:
resolution: {integrity: sha512-cSFtAPtRhljv69IK0hTVZQ+OfE9nePi/rtJmw5UjHeVyVroEqJXP1sFztKUy1qU+xvz3u/sfYJLa947b7nAN2Q==}
dev: false
@ -2536,6 +2537,19 @@ packages:
hasBin: true
dev: false
/winston-daily-rotate-file/4.7.1_winston@3.8.1:
resolution: {integrity: sha512-7LGPiYGBPNyGHLn9z33i96zx/bd71pjBn9tqQzO3I4Tayv94WPmBNwKC7CO1wPHdP9uvu+Md/1nr6VSH9h0iaA==}
engines: {node: '>=8'}
peerDependencies:
winston: ^3
dependencies:
file-stream-rotator: 0.6.1
object-hash: 2.2.0
triple-beam: 1.3.0
winston: 3.8.1
winston-transport: 4.5.0
dev: false
/winston-transport/4.5.0:
resolution: {integrity: sha512-YpZzcUzBedhlTAfJg6vJDlyEai/IFMIVcaEZZyl3UXIl4gmqRpU7AE89AHLkbzLUsv0NVmw7ts+iztqKxxPW1Q==}
engines: {node: '>= 6.4.0'}
@ -2667,6 +2681,21 @@ packages:
dev: false
optional: true
github.com/TheEssem/shoukaku/7f1aa66df448354898a78da1ff5ed88d20c8d562_bufferutil@4.0.6:
resolution: {tarball: https://codeload.github.com/TheEssem/shoukaku/tar.gz/7f1aa66df448354898a78da1ff5ed88d20c8d562}
id: github.com/TheEssem/shoukaku/7f1aa66df448354898a78da1ff5ed88d20c8d562
name: shoukaku
version: 3.1.3
engines: {node: '>=16.0.0', npm: '>=7.0.0'}
prepare: true
requiresBuild: true
dependencies:
ws: 8.8.1_bufferutil@4.0.6
transitivePeerDependencies:
- bufferutil
- utf-8-validate
dev: false
github.com/abalabahaha/erlpack/f7d730debe32c416d1b55b4217f8aef2ade05874:
resolution: {tarball: https://codeload.github.com/abalabahaha/erlpack/tar.gz/f7d730debe32c416d1b55b4217f8aef2ade05874}
name: erlpack
@ -2678,9 +2707,9 @@ packages:
dev: false
optional: true
github.com/esmBot/eris/828a57e7e8f52ec1b0b50d4f7f302f25705e46cc_bufferutil@4.0.6:
resolution: {tarball: https://codeload.github.com/esmBot/eris/tar.gz/828a57e7e8f52ec1b0b50d4f7f302f25705e46cc}
id: github.com/esmBot/eris/828a57e7e8f52ec1b0b50d4f7f302f25705e46cc
github.com/esmBot/eris/128cd6c99086d33afda7eef4b2f9ef8d9b5bea8c_bufferutil@4.0.6:
resolution: {tarball: https://codeload.github.com/esmBot/eris/tar.gz/128cd6c99086d33afda7eef4b2f9ef8d9b5bea8c}
id: github.com/esmBot/eris/128cd6c99086d33afda7eef4b2f9ef8d9b5bea8c
name: eris
version: 0.17.2-dev
engines: {node: '>=10.4.0'}

View file

@ -66,7 +66,7 @@ export async function play(client, sound, options, music = false) {
const voiceChannel = options.channel.guild.channels.get(options.member.voiceState.channelID);
if (!voiceChannel.permissionsOf(client.user.id).has("voiceConnect")) return "I don't have permission to join this voice channel!";
const playerMeta = players.get(options.channel.guild.id);
if (!music && manager.players.has(options.channel.guild.id) && (playerMeta?.type === "music")) return "I can't play a sound effect while playing music!";
if (!music && manager.players.has(options.channel.guild.id)) return "I can't play a sound effect while other audio is playing!";
let node = manager.getNode();
if (!node) {
const status = await checkStatus();
@ -122,15 +122,6 @@ export async function nextSong(client, options, connection, track, info, music,
skipVotes.delete(voiceChannel.guild.id);
const parts = Math.floor((0 / info.length) * 10);
let playingMessage;
if (!music && players.has(voiceChannel.guild.id)) {
const playMessage = players.get(voiceChannel.guild.id).playMessage;
try {
players.delete(voiceChannel.guild.id);
await playMessage.delete();
} catch {
// no-op
}
}
if (music && lastTrack === track && players.has(voiceChannel.guild.id)) {
playingMessage = players.get(voiceChannel.guild.id).playMessage;
} else {