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 ability to send images as links #88

Open
wants to merge 1 commit into
base: master
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
1 change: 1 addition & 0 deletions src/pluginConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const DEFAULT_SETTINGS = {
autocompleteEmoteSize: 15,
autocompleteItems: 10,
customEmotes: {},
sendAsLink,
requirePrefix: true,
prefix: ';',
resizeMethod: 'largest',
Expand Down
34 changes: 27 additions & 7 deletions src/services/sendMessageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,33 @@ export class SendMessageService extends BaseService {
foundEmote.channel = channelId;

try {
if (!this.attachService.canAttach) {
throw new Error('This channel does not allow sending images!');
}

this.attachService.pendingUpload = this.fetchBlobAndUpload(foundEmote);
await this.attachService.pendingUpload;
return;
if (!this.attachService.canAttach) {
throw new Error('This channel does not allow sending images!');
}
if(this.settingsService.settings.sendAsLink) {
let contentBefore = args[1].content.substring(0, foundEmote.pos);
let emojiContent = foundEmote.url + `?size=${this.settingsService.settings.emoteSize}`;
let contentAfter = args[1].content.substring(foundEmote.pos + foundEmote.emoteLength, args[1].content.length);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code doesn't / can't handle emote modifiers


if(contentBefore) {
args[1].content = contentBefore;
await callDefault(...args);
}
if(emojiContent) {
args[1].content = emojiContent;
await callDefault(...args);
}
if(contentAfter) {
args[1].content = contentAfter;
await callDefault(...args);
}
Copy link
Owner

@Yentis Yentis Dec 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will send up to 3 messages for a single user action, which qualifies as self-botting

}
else {
this.attachService.pendingUpload = this.fetchBlobAndUpload(foundEmote);
await this.attachService.pendingUpload;
}

return;
} catch (error: unknown) {
const errorMessage = error instanceof Error ? error.message : (error as string);

Expand Down
11 changes: 11 additions & 0 deletions src/services/settingsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,17 @@ export class SettingsService extends BaseService {
},
});
settings.push(autocompleteItems);

const sendAsLink = Utils.SwitchSetting({
id: 'sendAsLink',
name: 'Send as link',
note: 'If this is enabled, the images will be sent as links instead of images.',
value: this.settings.sendAsLink,
onChange: (checked) => {
this.settings.sendAsLink = checked;
},
});
settings.push(sendAsLink);

const requirePrefix = Utils.SwitchSetting({
id: 'requirePrefix',
Expand Down