stuff and things

This commit is contained in:
murm 2023-03-16 20:23:01 -04:00
parent 3957b17645
commit e67c0d96ca
28 changed files with 54 additions and 150 deletions

3
.gitignore vendored
View file

@ -118,4 +118,5 @@ libvips/
# Databases
data/
*.sqlite
*.sqlite
*.sqlite-journal

View file

@ -31,7 +31,7 @@ class ImageCommand extends Command {
id: this.message.event_id
};
// if (this.type === "application") await this.acknowledge();
// if (this.type === "application") // await this.acknowledge();
if (this.constructor.requiresImage) {
try {

View file

@ -3,7 +3,7 @@ import Command from "../../classes/command.js";
class AncientCommand extends Command {
async run() {
await this.acknowledge();
// await this.acknowledge();
const controller = new AbortController();
const timeout = setTimeout(() => {
controller.abort();

View file

@ -3,7 +3,7 @@ import Command from "../../classes/command.js";
class BirdCommand extends Command {
async run() {
await this.acknowledge();
// await this.acknowledge();
const controller = new AbortController();
const timeout = setTimeout(() => {
controller.abort();

View file

@ -3,7 +3,7 @@ import Command from "../../classes/command.js";
class CatCommand extends Command {
async run() {
await this.acknowledge();
// await this.acknowledge();
const controller = new AbortController();
const timeout = setTimeout(() => {
controller.abort();

View file

@ -3,7 +3,7 @@ import Command from "../../classes/command.js";
class DogCommand extends Command {
async run() {
await this.acknowledge();
// await this.acknowledge();
const controller = new AbortController();
const timeout = setTimeout(() => {
controller.abort();

View file

@ -3,7 +3,7 @@ import Command from "../../classes/command.js";
class WikihowCommand extends Command {
async run() {
await this.acknowledge();
// await this.acknowledge();
const controller = new AbortController();
const timeout = setTimeout(() => {
controller.abort();

View file

@ -1,53 +0,0 @@
import Command from "../../classes/command.js";
const mentionRegex = /^<?[@#]?[&!]?(\d+)>?$/;
class AvatarCommand extends Command {
async run() {
const member = this.options.member ?? this.args[0];
const self = this.client.users.get(this.author) ?? await this.client.rest.users.get(this.author);
if (this.type === "classic" && this.message.mentions.users[0]) {
return this.message.mentions.users[0].avatarURL(null, 512);
} else if (member && member > 21154535154122752n) {
const user = this.client.users.get(member) ?? await this.client.rest.users.get(member);
if (user) {
return user.avatarURL(null, 512);
} else if (mentionRegex.test(member)) {
const id = member.match(mentionRegex)[1];
if (id < 21154535154122752n) {
this.success = false;
return "That's not a valid mention!";
}
try {
const user = this.client.users.get(id) ?? await this.client.rest.users.get(id);
return user.avatarURL(null, 512);
} catch {
return self.avatarURL(null, 512);
}
} else {
return self.avatarURL(null, 512);
}
} else if (this.args.join(" ") !== "" && this.guild) {
const searched = await this.guild.searchMembers({
query: this.args.join(" "),
limit: 1
});
if (searched.length === 0) return self.avatarURL(null, 512);
const user = this.client.users.get(searched[0].user.id) ?? await this.client.rest.users.get(searched[0].user.id);
return user ? user.avatarURL(null, 512) : self.avatarURL(null, 512);
} else {
return self.avatarURL(null, 512);
}
}
static description = "Gets a user's avatar";
static aliases = ["pfp", "ava"];
static arguments = ["{mention/id}"];
static flags = [{
name: "member",
type: 6,
description: "The member to get the avatar from",
required: false
}];
}
export default AvatarCommand;

View file

@ -1,55 +0,0 @@
import Command from "../../classes/command.js";
import { Routes } from "oceanic.js";
const mentionRegex = /^<?[@#]?[&!]?(\d+)>?$/;
class BannerCommand extends Command {
// this command sucks
async run() {
const member = this.options.member ?? this.args[0];
const self = await this.client.rest.users.get(this.author); // banners are only available over REST
if (this.type === "classic" && this.message.mentions.users[0] && this.message.mentions.users[0].banner) {
return this.client.util.formatImage(Routes.BANNER(this.message.mentions.users[0].id, this.message.mentions.users[0].banner), null, 512);
} else if (member && member > 21154535154122752n) {
const user = await this.client.rest.users.get(member);
if (user && user.banner) {
return this.client.util.formatImage(Routes.BANNER(user.id, user.banner), null, 512);
} else if (mentionRegex.test(member)) {
const id = member.match(mentionRegex)[1];
if (id < 21154535154122752n) {
this.success = false;
return "That's not a valid mention!";
}
try {
const user = await this.client.rest.users.get(id);
return user.banner ? this.client.util.formatImage(Routes.BANNER(user.id, user.banner), null, 512) : "This user doesn't have a banner!";
} catch {
return self.banner ? this.client.util.formatImage(Routes.BANNER(self.id, self.banner), null, 512) : "You don't have a banner!";
}
} else {
return "This user doesn't have a banner!";
}
} else if (this.args.join(" ") !== "" && this.guild) {
const searched = await this.guild.searchMembers({
query: this.args.join(" "),
limit: 1
});
if (searched.length === 0) return self.banner ? this.client.util.formatImage(Routes.BANNER(self.id, self.banner), null, 512) : "This user doesn't have a banner!";
const user = await this.client.rest.users.get(searched[0].user.id);
return user.banner ? this.client.util.formatImage(Routes.BANNER(user.id, user.banner), null, 512) : (self.banner ? this.client.util.formatImage(Routes.BANNER(self.id, self.banner), null, 512) : "This user doesn't have a banner!");
} else {
return self.banner ? this.client.util.formatImage(Routes.BANNER(self.id, self.banner), null, 512) : "You don't have a banner!";
}
}
static description = "Gets a user's banner";
static aliases = ["userbanner"];
static arguments = ["{mention/id}"];
static flags = [{
name: "member",
type: 6,
description: "The member to get the banner from",
required: false
}];
}
export default BannerCommand;

View file

@ -3,7 +3,7 @@ import Command from "../../classes/command.js";
class DonateCommand extends Command {
async run() {
await this.acknowledge();
// await this.acknowledge();
let prefix = "";
const controller = new AbortController();
const timeout = setTimeout(() => {

View file

@ -8,7 +8,7 @@ class EvalCommand extends Command {
this.success = false;
return "Only the bot owner can use eval!";
}
await this.acknowledge();
// await this.acknowledge();
const code = this.options.code ?? this.args.join(" ");
try {
let evaled = eval(code);

View file

@ -11,7 +11,7 @@ class ExecCommand extends Command {
this.success = false;
return "Only the bot owner can use exec!";
}
await this.acknowledge();
// await this.acknowledge();
const code = this.options.cmd ?? this.args.join(" ");
try {
const execed = await exec(code);

View file

@ -11,7 +11,7 @@ class ImageSearchCommand extends Command {
if (this.channel && !this.channel.permissionsOf(this.client.user.id.toString()).has("EMBED_LINKS")) return "I don't have the `Embed Links` permission!";
const query = this.options.query ?? this.args.join(" ");
if (!query || !query.trim()) return "You need to provide something to search for!";
await this.acknowledge();
// await this.acknowledge();
const embeds = [];
const rawImages = await request(`${random(searx)}/search?format=json&safesearch=2&categories=images&q=!goi%20!ddi%20${encodeURIComponent(query)}`).then(res => res.body.json());
if (rawImages.results.length === 0) return "I couldn't find any results!";

View file

@ -8,7 +8,7 @@ class ImageReloadCommand extends Command {
this.success = false;
return "Only the bot owner can reload the image servers!";
}
await this.acknowledge();
// await this.acknowledge();
const length = await reloadImageConnections();
if (!length) {
if (process.env.PM2_USAGE) {

View file

@ -3,28 +3,15 @@ import { connections } from "../../utils/image.js";
class ImageStatsCommand extends Command {
async run() {
await this.acknowledge();
const embed = {
embeds: [{
"author": {
"name": "esmBot Image Statistics",
"iconURL": this.client.user.avatarURL()
},
"color": 16711680,
"description": `The bot is currently connected to ${connections.size} image server(s).`,
"fields": []
}]
};
// await this.acknowledge();
let desc = `The bot is currently connected to ${connections.size} image server(s).\n`
let i = 0;
for (const connection of connections.values()) {
const count = await connection.getCount();
if (!count) continue;
embed.embeds[0].fields.push({
name: `Server ${i++}`,
value: `Running Jobs: ${count}`
});
desc = desc + `Server ${i++}\nRunning Jobs: ${count}`
}
return embed;
return desc;
}
static description = "Gets some statistics about the image servers";

View file

@ -8,7 +8,7 @@ class InfoCommand extends Command {
let owner = this.client.users.get(process.env.OWNER.split(",")[0]);
if (!owner) owner = await this.client.rest.users.get(process.env.OWNER.split(",")[0]);
const servers = await getServers(this.client);
await this.acknowledge();
// await this.acknowledge();
return {
embeds: [{
color: 16711680,

View file

@ -4,7 +4,7 @@ import Command from "../../classes/command.js";
class LengthenCommand extends Command {
async run() {
await this.acknowledge();
// await this.acknowledge();
const input = this.options.url ?? this.args.join(" ");
this.success = false;
if (!input || !input.trim() || !urlCheck(input)) return "You need to provide a short URL to lengthen!";

View file

@ -8,7 +8,7 @@ class QrCreateCommand extends Command {
this.success = false;
return "You need to provide some text to generate a QR code!";
}
await this.acknowledge();
// await this.acknowledge();
const writable = new PassThrough();
qrcode.toFileStream(writable, this.content, { margin: 1 });
const file = await this.streamToBuf(writable);

View file

@ -10,7 +10,7 @@ class QrReadCommand extends Command {
const image = await imageDetect(this.client, this.message, this.interaction, this.options);
this.success = false;
if (image === undefined) return "You need to provide an image/GIF with a QR code to read!";
await this.acknowledge();
// await this.acknowledge();
const data = Buffer.from(await (await request(image.path)).body.arrayBuffer());
const rawData = await sharp(data).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
const qrBuffer = jsqr(rawData.data, rawData.info.width, rawData.info.height);

View file

@ -3,7 +3,7 @@ import imageDetect from "../../utils/imagedetect.js";
class RawCommand extends Command {
async run() {
await this.acknowledge();
// await this.acknowledge();
const image = await imageDetect(this.client, this.message, this.interaction, this.options);
if (image === undefined) {
this.success = false;

View file

@ -8,7 +8,7 @@ class ReloadCommand extends Command {
if (!owners.includes(this.author)) return "Only the bot owner can reload commands!";
const commandName = this.options.cmd ?? this.args.join(" ");
if (!commandName || !commandName.trim()) return "You need to provide a command to reload!";
await this.acknowledge();
// await this.acknowledge();
const path = paths.get(commandName);
if (!path) return "I couldn't find that command!";
const result = await load(this.client, path, true);

View file

@ -8,7 +8,7 @@ class SoundReloadCommand extends Command {
this.success = false;
return "Only the bot owner can reload Lavalink!";
}
await this.acknowledge();
// await this.acknowledge();
const length = await reload();
if (process.env.PM2_USAGE) {
process.send({

View file

@ -10,7 +10,7 @@ class YouTubeCommand extends Command {
const query = this.options.query ?? this.args.join(" ");
this.success = false;
if (!query || !query.trim()) return "You need to provide something to search for!";
await this.acknowledge();
// await this.acknowledge();
const messages = [];
const videos = await request(`${random(searx)}/search?format=json&safesearch=1&categories=videos&q=!youtube%20${encodeURIComponent(query)}`).then(res => res.body.json());
if (videos.results.length === 0) return "I couldn't find any results!";

View file

@ -4,7 +4,7 @@ import { selectedImages } from "../../utils/collections.js";
class SelectImageCommand extends Command {
async run() {
await this.acknowledge();
// await this.acknowledge();
const message = this.interaction.data.target;
const image = await imageDetect(this.client, message, this.interaction, this.options, true, false, false, true);
this.success = false;

View file

@ -6,7 +6,7 @@ class MusicAIOCommand extends Command {
async run() {
let cmd = this.type === "classic" ? this.args[0] : this.optionsArray[0].name;
if (cmd === "music" || this.constructor.aliases.includes(cmd)) return "https://esmbot.net/robotdance.gif";
await this.acknowledge();
// await this.acknowledge();
if (this.type === "classic") {
this.origOptions.args.shift();
} else {

View file

@ -11,7 +11,7 @@ class SoundboardAIOCommand extends Command {
return "You need to provide a sound to play!";
}
const name = sounds.get(soundName);
await this.acknowledge();
// await this.acknowledge();
return await play(this.client, name, { channel: this.channel, member: this.member, type: this.type, interaction: this.interaction });
}

View file

@ -89,13 +89,17 @@ export default async function (matrixClient, event, room, toStartOfTimeline) {
const mxcUri = await matrixClient.uploadContent(result.contents);
// TODO: make info object get width, height, and mime from natives so i dont need to read the buffer
const imgsize = sizeOf(result.contents)
await matrixClient.sendImageMessage(event.event.room_id, mxcUri.content_uri, {h: imgsize.height, w: imgsize.width, mimetype: `image/${imgsize.type}`, size: result.contents.length, thumbnail_info: {h: imgsize.height, w: imgsize.width, mimetype: `image/${imgsize.type}`, size: result.contents.length}}, result.name)
let mime = imgsize.type;
if (mime == "jpg") {
mime = "jpeg";
}
await matrixClient.sendImageMessage(event.event.room_id, mxcUri.content_uri, {h: imgsize.height, w: imgsize.width, mimetype: `image/${mime}`, size: result.contents.length, thumbnail_info: {h: imgsize.height, w: imgsize.width, mimetype: `image/${mime}`, size: result.contents.length}}, result.name)
}
} else {
// await client.rest.channels.createMessage(message.channelID, Object.assign(result, reference));
}
} else {
console.log(typeof result)
// console.log(typeof result)
}
} catch (error) {
logger.log("error", error.stack)

View file

@ -38,6 +38,17 @@ const combined = [...tenorURLs, ...giphyURLs, ...giphyMediaURLs, ...imgurURLs, .
const imageFormats = ["image/jpeg", "image/png", "image/webp", "image/gif", "large"];
const videoFormats = ["video/mp4", "video/webm", "video/mov"];
// check if url contents is valid url
const isValidUrl = urlString=> {
var urlPattern = new RegExp('^(https?:\\/\\/)?'+ // validate protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // validate domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // validate OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // validate port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // validate query string
'(\\#[-a-z\\d_]*)?$','i'); // validate fragment locator
return !!urlPattern.test(urlString);
}
// gets the proper image paths
const getImage = async (image, image2, video, extraReturnTypes, gifv = false, type = null, link = false) => {
try {
@ -125,7 +136,16 @@ const checkImages = async (message, extraReturnTypes, video, sticker) => {
const fileNameNoExtension = message.content.body.slice(0, message.content.body.lastIndexOf("."));
type = {name: fileNameNoExtension, path: url, url: url, type: message.content.info.mimetype}
}
}
if (message.content.msgtype == "m.text") {
let url = message.content.body
url = url.replace(/.*\n\n/g, "")
if (isValidUrl(url)){
const mimetype = await getType(url, extraReturnTypes)
type = {name: "image", path: url, url: url, type: mimetype}
}
}
// // first check the embeds
// if (message.embeds.length !== 0) {
// // embeds can vary in types, we check for tenor gifs first