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

Add Sticker metadata change/add #178

Open
wants to merge 7 commits into
base: multi-device
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions lib/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ const data = {
NOT_A_GROUP: "```This command is only applicable in a group chat.```",
ICON_CHANGED: "```Changing icon/group image...```",
},
smeta: {
DESCRIPTION: "Module to add or change metadata to a sticker such as emojis associated with the sticker, pack name, author name and shape of the sticker.",
EXTENDED_DESCRIPTION:
"```Use this module to add/change metadata to a sticker. Reply to a sticker with the command``` *.smeta <emoji> <shape> <packname> <authorname>* ```to add/change metadata to the sticker.``` \n\n```<emoji> - Emoji to be used for searching in the sticker whatsapp's menu.``` \n```<Shape> - Type of the sticker's shape: default, crop, full, circle, rounded.``` \n```<packname> - Name of the sticker pack.``` \n```<authorname> - Name of the sticker pack author.``` \n\n```For example\n``` *.smeta 🤣 circle myPack anAuthor*\n *.smeta ❤️*\n\nTo avoid using the emoji or shape metadata in the command, use the keyword``` *null* ```in place of the metadata.``` \n\n```For example```\n*.smeta null null myPack anAuthor*",
},
song: {
DESCRIPTION: "Download songs",
EXTENDED_DESCRIPTION:
Expand Down
69 changes: 69 additions & 0 deletions modules/smeta.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import Strings from "../lib/db";
import inputSanitization from "../sidekick/input-sanitization";
import { MessageType } from "../sidekick/message-type";
import { downloadContentFromMessage, proto } from "@adiwajshing/baileys";
import Client from "../sidekick/client";
import BotsApp from "../sidekick/sidekick";
import fs from "fs";
import { readFileSync } from 'fs'

import { Transform } from "stream";
import { Sticker, extractMetadata, StickerTypes, Categories } from 'wa-sticker-formatter'

const smeta = Strings.smeta;

function getStickerType(arg: string): StickerTypes {
if (Object.values(StickerTypes).includes(arg as StickerTypes)) {
return arg as StickerTypes;
}
return StickerTypes.FULL;
}

export = {
name: "smeta",
description: smeta.DESCRIPTION,
extendedDescription: smeta.EXTENDED_DESCRIPTION,
demo: { isEnabled: false, text: ".smeta" },
async handle(client: Client, chat: proto.IWebMessageInfo, BotsApp: BotsApp, args: string[]): Promise<void> {

if (BotsApp.isReplySticker) {
//it allows more than 1 emoji but its a secret for now
//convert from string separate by commas to Categories
const arg_emojis: Categories[] = [];
for (let i = 0; i < args[0].split(",").length; i++) {
arg_emojis.push(args[0].split(",")[i] as Categories);
}

var replyChatObject: any = {
message: chat.message.extendedTextMessage.contextInfo.quotedMessage.stickerMessage,
type: 'sticker'
};
var stickerId = chat.message.extendedTextMessage.contextInfo.stanzaId;
const filePath = "./tmp/convert_to_image-" + stickerId;
const fileWebp = './tmp/sticker-' + stickerId + '.webp';
const stream: Transform = await downloadContentFromMessage(replyChatObject.message, replyChatObject.type)
await inputSanitization.saveBuffer(filePath, stream);

const stickerRead = readFileSync(filePath)
let metadata = await extractMetadata(stickerRead) // { emojis: [], 'sticker-pack-id': '', 'sticker-pack-name': '', 'sticker-author-name': '' }

const sticker = new Sticker(filePath, {
categories: args[0] != "null" ? arg_emojis : [],
type: args[1] != "null" ? getStickerType(args[1]) : StickerTypes.FULL,
pack: args[2] ?? metadata['sticker-pack-name'],
author: args[3] ?? metadata['sticker-author-name']
// id: '12345', // The sticker id
// quality: 100, // The quality of the output file
// background: '#000000' // The sticker background color (only for full stickers)
})
await sticker.toFile(fileWebp)
await client.sendMessage(
BotsApp.chatId,
fs.readFileSync(fileWebp),
MessageType.sticker,
).catch(err => inputSanitization.handleError(err, client, BotsApp));
await inputSanitization.deleteFiles(filePath, fileWebp);
}
}

};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"typescript": "^4.6.4",
"unofficial-carbon-now": "^1.0.3",
"urban-dictionary": "^3.0.2",
"wa-sticker-formatter": "^4.4.4",
"yt-search": "^2.10.1",
"ytdl-core": "^4.11.2"
},
Expand Down