Skip to content

Commit

Permalink
Merge pull request #93 from BobbyWibowo/pr-3.2.17
Browse files Browse the repository at this point in the history
Pitu authored Oct 27, 2023
2 parents b4993f2 + 70e6d79 commit d025c69
Showing 1 changed file with 63 additions and 69 deletions.
132 changes: 63 additions & 69 deletions src/App.svelte
Original file line number Diff line number Diff line change
@@ -167,8 +167,8 @@
};
const coords = { top: 0, left: 0 };
const selectorVoiceChatWrapper = '[class^="channelChatWrapper-"]';
const selectorTextArea = '[class^="channelTextArea-"]:not([class*="channelTextAreaDisabled-"])';
const selectorVoiceChatWrapper = '[class^="chatLayerWrapper_"]';
const selectorTextArea = '[class^="channelTextArea_"]:not([class*="channelTextAreaDisabled_"])';
let main = null;
let base = null;
let forceHideMagane = false;
@@ -218,7 +218,7 @@
useLeftToolbar: false,
showPackAppendix: false,
disableDownscale: false,
disableImportedObfuscation: false,
disableUploadObfuscation: false,
alwaysSendAsLink: false,
maskStickerLink: false,
ctrlInvertSendBehavior: false,
@@ -497,6 +497,12 @@
// Permissions
Modules.DiscordConstants = Helper.findByProps('Permissions', 'ActivityTypes', 'StatusTypes');
Modules.DiscordPermissions = Helper.find(m => m.ADD_REACTIONS, { searchExports: true });
try {
const module = Helper.find(m => m.Permissions && m.Permissions.ADMINISTRATOR, { searchExports: true });
Modules.PermissionsBits = module.Permissions;
} catch {
Modules.PermissionsBits = Helper.find(m => typeof m.ADMINISTRATOR === 'bigint', { searchExports: true });
}
Modules.Permissions = Helper.findByProps('computePermissions');
Modules.UserStore = Helper.findByProps('getCurrentUser', 'getUser');
@@ -505,10 +511,7 @@
Modules.MessageUpload = Helper.findByProps('instantBatchUpload');
Modules.MessageUtils = Helper.findByProps('sendMessage');
Modules.PendingReplyStore = Helper.findByProps('getPendingReply');
Modules.UploadObject = Helper.find(
m => m.prototype && m.prototype.upload && m.prototype.getSize,
{ searchExports: true }
);
Modules.UploadUI = Helper.findByProps('showUploadFileSizeExceededError', 'promptToUpload');
Modules.React = Helper.findByProps('createElement', 'version');
};
@@ -823,12 +826,12 @@
let append = sending ? '&h=180p' : '&h=100p';
if (localPacks[pack].animated) {
url = url.replace(/sticker(@2x)?\.png/, 'sticker_animation$1.png');
// In case one day images.weserv.nl starts properly supporting APNGs -> GIFs
// In case one day wsrv.nl starts properly supporting APNGs -> GIFs
append += '&output=gif';
}
if (!settings.disableDownscale) {
// Downsizing with images.weserv.nl to stay consistent with Magane's built-in packs
url = `https://images.weserv.nl/?url=${encodeURIComponent(url)}${append}`;
// Downsizing with wsrv.nl to stay consistent with Magane's built-in packs
url = `https://wsrv.nl/?url=${encodeURIComponent(url)}${append}`;
}
} else if (pack.startsWith('emojis-')) {
/*
@@ -845,12 +848,12 @@
let append = sending ? '' : '&h=100p';
if (localPacks[pack].animated) {
url = url.replace(/\.png/, '_animation.png');
// In case one day images.weserv.nl starts properly supporting APNGs -> GIFs
// In case one day wsrv.nl starts properly supporting APNGs -> GIFs
append += '&output=gif';
}
if (!settings.disableDownscale) {
// Downsizing with images.weserv.nl to stay consistent with Magane's built-in packs
url = `https://images.weserv.nl/?url=${encodeURIComponent(url)}${append}`;
// Downsizing with wsrv.nl to stay consistent with Magane's built-in packs
url = `https://wsrv.nl/?url=${encodeURIComponent(url)}${append}`;
}
} else if (pack.startsWith('custom-')) {
// Unified imported custom packs
@@ -892,24 +895,21 @@
}
};
const hasPermission = (permission, channelId) => {
const hasPermission = (permission, context) => {
// Always true if could not fetch the necessary modules
if (!Modules.DiscordPermissions || !Modules.Permissions || !Modules.UserStore || !Modules.ChannelStore) {
if (!Modules.DiscordPermissions || !Modules.Permissions || !Modules.UserStore) {
return true;
}
const user = Modules.UserStore.getCurrentUser();
const context = Modules.ChannelStore.getChannel(channelId);
if (!user) return false;
// Always true in non-guild channels (e.g. DMs)
if (!permission || !context.guild_id) return true;
if (!permission || !context.guild_id || context.isDM() || context.isGroupDM()) {
return true;
}
return Modules.Permissions.can({
permission: Modules.DiscordPermissions[permission],
user,
context
});
return Modules.Permissions.can(Modules.PermissionsBits[permission], context);
};
const sendSticker = async (pack, id, event) => {
@@ -922,10 +922,6 @@
onCooldown = true;
try {
// const channelId = Modules.SelectedChannelStore.getChannelId();
// Good ol' reliable
// const channelId = window.location.href.split('/').slice(-1)[0];
// If multiple active channels (i.e. split-view), SelectedChannelStore will only return the main channel,
// so determining through active component's textArea instance is more reliable, if available.
let channelId;
@@ -937,6 +933,11 @@
channelId = Modules.SelectedChannelStore.getChannelId();
}
let channel;
if (Modules.ChannelStore) {
channel = Modules.ChannelStore.getChannel(channelId);
}
// Magane will also appear in Create Thread screen,
// but at that point the thread has not yet been made, and thus will not have ID.
if (!channelId) {
@@ -949,7 +950,6 @@
return toastError('You do not have permission to send message in this channel.');
}
toast('Sending\u2026', { nolog: true });
if (settings.closeWindowOnSend) {
// eslint-disable-next-line no-use-before-define
toggleStickerWindow(false, activeComponent);
@@ -975,8 +975,11 @@
sendAsLink = !sendAsLink;
}
if (!sendAsLink && hasPermission('ATTACH_FILES', channelId)) {
log(`Fetching sticker from remote: ${url}`);
// Always send as link if channel instance is not available (due to missing module)
if (!sendAsLink && channel && hasPermission('ATTACH_FILES', channel)) {
toast('Fetching sticker from remote\u2026', { timeout: 1000 });
log(`Fetching: ${url}`);
const response = await fetch(url, { cache: 'force-cache' });
const blob = await response.blob();
@@ -985,40 +988,30 @@
if (localPacks[pack].animated && (pack.startsWith('startswith-') || pack.startsWith('emojis-'))) {
filename = filename.replace(/\.png$/i, '.gif');
toastWarn('Animated stickers/emojis from LINE Store currently cannot be animated.');
} else if (pack.startsWith('custom-')) {
if (settings.disableImportedObfuscation) {
filename = id;
} else {
const ext = id.match(/(\.\w+)$/);
filename = `${Date.now().toString()}${ext ? ext[1] : ''}`;
}
}
}
if (!settings.disableUploadObfuscation) {
const ext = id.match(/(\.\w+)$/);
filename = `${Date.now().toString()}${ext ? ext[1] : ''}`;
}
if (settings.markAsSpoiler) {
filename = `SPOILER_${filename}`;
}
const file = new File([blob], filename);
log(`Sending sticker as ${filename}\u2026`);
Modules.MessageUpload.uploadFiles({
channelId,
draftType: 0,
hasSpoiler: false,
options: messageOptions || {},
parsedMessage: {
content: messageContent
},
uploads: [
new Modules.UploadObject({
file,
platform: 1
}, channelId, false, 0)
]
});
} else if (settings.ignoreEmbedLinksPermission || hasPermission('EMBED_LINKS', channelId)) {
// Immediately after the command finishes, Discord clears all input, including pending attachments.
// Thus, setTimeout is needed to make this execute after Discord cleared the input
setTimeout(() => Modules.UploadUI.promptToUpload([file], channel, 0), 10);
} else if (settings.ignoreEmbedLinksPermission || (channel && hasPermission('EMBED_LINKS', channel))) {
if (!sendAsLink) {
toastWarn('You do not have permission to attach files, sending sticker as link\u2026');
if (channel) {
toastWarn('You do not have permission to attach files, sending sticker as link\u2026');
} else {
toastWarn('Unable to fetch ChannelStore module, sending sticker as link\u2026');
}
}
let append = url;
@@ -1030,6 +1023,16 @@
Modules.MessageUtils._sendMessage(channelId, {
content: `${messageContent} ${append}`.trim()
}, messageOptions || {});
// Clear chat input if required
if (!settings.disableSendingWithChatInput && textAreaInstance) {
log('Clearing chat input\u2026');
textAreaInstance.stateNode.setState({
textValue: '',
// richValue: modules.richUtils.toRichValue('')
richValue: [{ type: 'line', children: [{ text: '' }] }]
});
}
} else {
toastError('You do not have permissions to attach files nor embed links.');
}
@@ -1049,16 +1052,6 @@
// eslint-disable-next-line no-use-before-define
updateFrequentlyUsed();
}
// Clear chat input if required
if (!settings.disableSendingWithChatInput && textAreaInstance) {
log('Clearing chat input\u2026');
textAreaInstance.stateNode.setState({
textValue: '',
// richValue: modules.richUtils.toRichValue('')
richValue: [{ type: 'line', children: [{ text: '' }] }]
});
}
} catch (error) {
console.error(error);
toastError(error.toString(), { nolog: true, timeout: 6000 });
@@ -1398,6 +1391,7 @@
editPack,
deletePack,
searchPacks,
Helper,
Modules,
hasPermission
};
@@ -2724,16 +2718,16 @@
name="disableDownscale"
type="checkbox"
bind:checked={ settings.disableDownscale } />
Disable downscaling of imported LINE packs using <code>images.weserv.nl</code> (this service is known to be blocked by Discord if sending as links)
Disable downscaling of imported LINE packs using <code>wsrv.nl</code> (this service is known to be blocked by Discord if sending as links)
</label>
</p>
<p>
<label>
<input
name="disableImportedObfuscation"
name="disableUploadObfuscation"
type="checkbox"
bind:checked={ settings.disableImportedObfuscation } />
Disable obfuscation of files names for imported custom packs (obfuscation happens only for uploads)
bind:checked={ settings.disableUploadObfuscation } />
Disable obfuscation of files names for uploaded stickers
</label>
</p>
<p>
@@ -2778,7 +2772,7 @@
name="markAsSpoiler"
type="checkbox"
bind:checked={ settings.markAsSpoiler } />
Mark stickers as spoilers when sending (does not work when sending stickers as links)
Mark as spoiler when sending stickers as uploads
</label>
</p>
<p>
@@ -2796,7 +2790,7 @@
name="disableSendingWithChatInput"
type="checkbox"
bind:checked={ settings.disableSendingWithChatInput } />
Do not send text chat input alongside sticker
Do not include chat input when sending stickers as links
</label>
</p>
</div>

0 comments on commit d025c69

Please sign in to comment.