Skip to content

Commit

Permalink
Further Optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
SammCheese committed Jun 28, 2022
1 parent 15f7e58 commit 3209f25
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 36 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
/.dccache
/.dccache

.vscode/**
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Dont Slowmode Me Mommy~!
# Dont Slowmode Me

A Powercord Plugin to Prevent you getting stuck in the Slowmode Bucket

Expand Down
2 changes: 1 addition & 1 deletion components/Settings.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module.exports = class Settings extends React.PureComponent {
const { getSetting, updateSetting } = this.props
return (<div>
<TextInput
note="The Time in Seconds at which the Slowmode blocker should activate"
note="The Time in Seconds at which the Warning will be displayed"
defaultValue={getSetting("slowmodeTrigger", "600")}
onChange={v => updateSetting("slowmodeTrigger", v)}>
Slowmode Trigger
Expand Down
50 changes: 18 additions & 32 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const { Plugin } = require('powercord/entities')
const { inject, uninject } = require('powercord/injector')
const { getModule, channels, messages, React, constants: { Permissions } } = require('powercord/webpack')

const highestRole = getModule(['getHighestRole'], false)
const channelObj = getModule(['getChannel', 'getDMFromUserId'], false)

const { getGuild } = getModule(['getGuild'], false);
Expand All @@ -24,11 +23,12 @@ module.exports = class doNotSlowmode extends Plugin {
}

_injectMessageSent() {
inject('dontSlowmodeMeMommy', messages, 'sendMessage', (args) => {
inject('dontSlowmodeMe', messages, 'sendMessage', (args) => {

const guildID = channelObj.getChannel(channels.getChannelId()).guild_id;
// Avoid Unnecessary Checks if there is no Slowmode
if (!this.cooldownTime()) return args;

if (!guildID) return args;
const guildID = channelObj.getChannel(channels.getChannelId()).guild_id;

let permissions = this.getPermissionsRaw(
getGuild(guildID),
Expand All @@ -37,22 +37,19 @@ module.exports = class doNotSlowmode extends Plugin {

let parsedPermissions = this.parseBitFieldPermissions(permissions);

// There is no need to show a notice if the user has perms
if (
parsedPermissions['MANAGE_MESSAGES'] ||
parsedPermissions['MANAGE_CHANNELS'] ||
parsedPermissions['ADMINISTRATOR']
) return args;

if (this.cooldownTime() >= this.settings.get('slowmodeTrigger', '600')) {
if (!args[1]?.__DNSM_afterWarn) {
open(() => React.createElement(Modal, {
slowmode: this.cooldownTime(),
channel: channels.getChannelId(),
message: args[1]
}));
return false;
}
// There is no need to show a notice if the user has perms that bypass the slowmode
if (parsedPermissions['MANAGE_MESSAGES'] || parsedPermissions['MANAGE_CHANNELS']) return args;


if (this.cooldownTime() < this.settings.get('slowmodeTrigger', '600')) return args;

if (!args[1]?.__DNSM_afterWarn) {
open(() => React.createElement(Modal, {
slowmode: this.cooldownTime(),
channel: channels.getChannelId(),
message: args[1]
}));
return false;
}
return args;
}, true);
Expand Down Expand Up @@ -107,17 +104,6 @@ module.exports = class doNotSlowmode extends Plugin {
return permissions;
}

hasPermissions() {
console.log(highestRole.can(Permissions.ADD_REACTIONS, channels.getChannelId()))

if (highestRole.can(Permissions.MANAGE_MESSAGES, channels.getChannelId()) ||
highestRole.can(Permissions.MANAGE_CHANNELS, channels.getChannelId())
) {
console.log('has permissions')
return true
}
}

cooldownTime() {
const channel = channels.getChannelId();
return channelObj.getChannel(channel).rateLimitPerUser
Expand All @@ -131,7 +117,7 @@ module.exports = class doNotSlowmode extends Plugin {
}

pluginWillUnload() {
uninject('dontSlowmodeMeMommy')
uninject('dontSlowmodeMe')
powercord.api.settings.unregisterSettings('DNSM!')
}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Do Not Slowmode Me",
"version": "1.1.1",
"version": "1.1.2",
"description": "Warns you before sending a Message about slowmode",
"author": "SammCheese",
"license": "Unlicensed"
Expand Down

0 comments on commit 3209f25

Please sign in to comment.