Skip to content
This repository has been archived by the owner on Sep 30, 2022. It is now read-only.

Commit

Permalink
feat: change update tags in user popout
Browse files Browse the repository at this point in the history
Closes GH 2
  • Loading branch information
BenSegal855 committed Feb 7, 2021
1 parent 93935ae commit 9b7f134
Show file tree
Hide file tree
Showing 2 changed files with 232 additions and 32 deletions.
173 changes: 173 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
{
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
"env": {
"node": true,
"es6": true
},
"parser": "@typescript-eslint/parser",
"parserOptions": { "ecmaVersion": 2018, "sourceType": "module" },
"rules": {
"no-extra-parens": ["warn", "all", {
"nestedBinaryExpressions": false
}],
"valid-jsdoc": ["warn", {
"requireReturn": false,
"requireReturnDescription": false,
"prefer": {
"arg": "param",
"argument": "param",
"prop": "property",
"constructor": "class",
"augments": "extends",
"fires": "emits",
"var": "member",
"yield": "yields",
"return": "returns",
"exception": "throws",
"virtual": "abstract"
},
"preferType": {
"String": "string",
"Number": "number",
"Boolean": "boolean",
"Symbol": "symbol",
"function": "Function",
"object": "Object",
"date": "Date",
"error": "Error"
}
}],
"@typescript-eslint/indent": ["error", "tab"],
"accessor-pairs": "warn",
"array-callback-return": "error",
"complexity": "warn",
"curly": ["error", "multi-line", "consistent"],
"dot-location": ["error", "property"],
"dot-notation": "error",
"eqeqeq": "error",
"no-console": ["error", { "allow": ["log", "warn", "error"] }],
"no-empty-function": "error",
"no-floating-decimal": "error",
"no-implied-eval": "error",
"no-lone-blocks": "error",
"no-multi-spaces": "error",
"no-new-func": "error",
"no-new-wrappers": "error",
"no-new": "error",
"no-octal-escape": "error",
"no-return-assign": "error",
"no-self-compare": "error",
"no-sequences": "error",
"no-unmodified-loop-condition": "error",
"no-unused-expressions": "error",
"no-useless-call": "error",
"no-useless-concat": "error",
"no-useless-escape": "error",
"no-void": "error",
"no-warning-comments": "warn",
"wrap-iife": "error",
"yoda": "error",

"no-label-var": "error",
"no-shadow": "error",
"no-undef-init": "error",

"callback-return": "error",
"handle-callback-err": "error",
"no-mixed-requires": "error",
"no-new-require": "error",
"no-path-concat": "error",

"array-bracket-spacing": "error",
"block-spacing": "error",
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
"camelcase": "error",
"comma-dangle": "error",
"comma-spacing": "error",
"comma-style": "error",
"computed-property-spacing": "error",
"consistent-this": "error",
"eol-last": "error",
"func-names": "error",
"func-style": ["error", "declaration", { "allowArrowFunctions": true }],
"id-length": ["error", { "exceptions": ["i", "j", "a", "b", "e", "r", "m", "c"] }],
"indent": [0, 4, { "SwitchCase": 1 }],
"key-spacing": "error",
"keyword-spacing": ["error", {
"overrides": {
"if": { "after": true },
"for": { "after": true },
"while": { "after": true },
"catch": { "after": true },
"switch": { "after": true }
}
}],
"max-depth": "error",
"max-len": ["error", 200, 2],
"max-nested-callbacks": ["error", { "max": 4 }],
"max-statements-per-line": ["error", { "max": 2 }],
"new-cap": "error",
"newline-per-chained-call": ["error", { "ignoreChainWithDepth": 6 }],
"no-array-constructor": "error",
"no-bitwise": "off",
"no-lonely-if": "error",
"no-mixed-operators": "error",
"no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }],
"no-new-object": "error",
"no-spaced-func": "error",
"no-trailing-spaces": "error",
"no-unneeded-ternary": ["error", { "defaultAssignment": false }],
"no-whitespace-before-property": "error",
"object-curly-newline": "error",
"object-curly-spacing": ["error", "always"],
"operator-assignment": "error",
"operator-linebreak": [
"error",
"before",
{
"overrides": {
"+": "after",
"-": "after"
}
}
],
"padded-blocks": ["error", { "classes": "always", "blocks": "never", "switches": "never" }],
"quote-props": ["error", "as-needed"],
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
"semi-spacing": "error",
"semi": "error",
"space-before-blocks": "error",
"space-before-function-paren": ["error", {"anonymous": "always", "named": "never", "asyncArrow": "always"}],
"space-in-parens": "error",
"space-infix-ops": "error",
"space-unary-ops": "error",
"spaced-comment": "error",
"unicode-bom": "error",

"arrow-body-style": "error",
"arrow-spacing": "error",
"no-duplicate-imports": "error",
"no-useless-computed-key": "error",
"no-useless-constructor": "error",
"prefer-arrow-callback": "error",
"prefer-const": "error",
"prefer-destructuring": ["error", {
"VariableDeclarator": {
"array": false,
"object": true
},
"AssignmentExpression": {
"array": true,
"object": true
}
}, {
"enforceForRenamedProperties": false
}],
"prefer-rest-params": "error",
"prefer-spread": "error",
"prefer-template": "error",
"rest-spread-spacing": "error",
"template-curly-spacing": "error",
"yield-star-spacing": "error"
}
}
91 changes: 59 additions & 32 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,67 @@
const { Plugin } = require('powercord/entities');
const { getModule, React } = require('powercord/webpack');
const { getModule, getModuleByDisplayName, React } = require('powercord/webpack');
const { inject, uninject } = require('powercord/injector');
const { findInReactTree } = require('powercord/util');

const Tag = require('./Components/tag');

module.exports = class WebTag extends Plugin {
startPlugin () {
const MessageTimestamp = getModule([ 'MessageTimestamp' ], false);
const botTagRegularClasses = getModule([ 'botTagRegular' ], false);
const botTagClasses = getModule([ 'botTagCozy' ], false);
const remClasses = getModule([ 'rem' ], false);

inject('webhook-tag', MessageTimestamp, 'default', (args, res) => {
const msg = args[0].message;

if (msg.webhookId !== null && msg.messageReference === null && msg.author.discriminator === '0000') {
args[0].message.author.bot = false;

const header = findInReactTree(res, e => Array.isArray(e?.props?.children) && e.props.children.find(c => c?.props?.message));
header.props.children.push(React.createElement(
'span',
{
className: `${botTagClasses.botTagCozy} ${botTagClasses.botTagCompact} ${botTagRegularClasses.botTagRegular} ${remClasses.rem}`
},
React.createElement(Tag, {
className: botTagRegularClasses.botText
})
));
}

return res;
});
}

pluginWillUnload () {
uninject('webhook-tag');
}
async startPlugin() {
const MessageTimestamp = getModule(['MessageTimestamp'], false);
const botTagRegularClasses = getModule(['botTagRegular'], false);
const botTagClasses = getModule(['botTagCozy'], false);
const remClasses = getModule(['rem'], false);

inject('webhook-tag-messages', MessageTimestamp, 'default', (args, res) => {
const msg = args[0].message;

if (msg.webhookId !== null && msg.messageReference === null && msg.author.discriminator === '0000') {
args[0].message.author.bot = false;

const header = findInReactTree(res, e => Array.isArray(e?.props?.children) && e.props.children.find(c => c?.props?.message));
header.props.children.push(React.createElement(
'span',
{
className: `${botTagClasses.botTagCozy} ${botTagClasses.botTagCompact} ${botTagRegularClasses.botTagRegular} ${remClasses.rem}`
},
React.createElement(Tag, {
className: botTagRegularClasses.botText
})
));
}

return res;
});

const AnalyticsContext = await getModuleByDisplayName('AnalyticsContext');
inject('webhook-tag-popout', AnalyticsContext.prototype, 'renderProvider', (_, res) => {
const elements = findInReactTree(res, a => Array.isArray(a) && a.find(c => c && c.type && c.type.displayName === 'CustomStatus'));
if (!elements) return res;

const { user } = findInReactTree(elements, p => p.user);
if (user.discriminator !== '0000') return res;

user.bot = false;

elements[1].props.children[1].props.children = [
elements[1].props.children[1].props.children,
React.createElement(
'span',
{
className: `${botTagClasses.botTagCozy} ${botTagClasses.botTagCompact} ${botTagRegularClasses.botTagRegular} ${remClasses.rem}`
},
React.createElement(Tag, {
className: botTagRegularClasses.botText
})
)
]

return res;
});
}

pluginWillUnload() {
uninject('webhook-tag-messages');
uninject('webhook-tag-popout');
}
};

0 comments on commit 9b7f134

Please sign in to comment.