Skip to content

Commit

Permalink
Merge pull request #2 from Vendicated/main
Browse files Browse the repository at this point in the history
Way better than the crap i did lmao
  • Loading branch information
SammCheese committed May 8, 2021
2 parents 0509d2d + b74b068 commit baa3e6b
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 49 deletions.
26 changes: 26 additions & 0 deletions Someone.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { React, getModuleByDisplayName, getModule, channels } = require("powercord/webpack");
const { Generic } = getModuleByDisplayName("AutoComplete", false);
const { sendMessage } = getModule(["sendMessage"], false);

function getRandomUserID() {
const Members = getModule(["getMemberIds"], false).getMemberIds(getModule(["getLastSelectedGuildId"], false).getLastSelectedGuildId());
return Members[Math.floor(Math.random() * Members.length)];
}

module.exports = () => {
const [selected, setSelected] = React.useState(false);
return (
<Generic
description="Mentions Someone!"
text="@someone"
selected={selected}
index={selected ? 1 : 0}
onHover={() => {
// TODO: unselect somehow
setSelected(true);
}}
// TODO: Close modal
onClick={() => sendMessage(channels.getChannelId(), { content: `<@${getRandomUserID()}>` })}
/>
);
};
84 changes: 35 additions & 49 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,42 @@
/* eslint-disable indent */
const { Plugin } = require('powercord/entities');
const { inject, uninject } = require('powercord/injector');
const { findInReactTree } = require('powercord/util');
const { getModule } = require('powercord/webpack');
const { Plugin } = require("powercord/entities");
const { inject, uninject } = require("powercord/injector");
const { getModule, React } = require("powercord/webpack");

function getRandomUserID () {
const Members = getModule([ 'getMemberIds' ], false)
.getMemberIds(getModule([ 'getLastSelectedGuildId' ], false)
.getLastSelectedGuildId());
return Members[Math.floor(Math.random() * Members.length)];
}
const {
AUTOCOMPLETE_OPTIONS: { MENTIONS }
} = getModule(["AUTOCOMPLETE_OPTIONS"], false);

const Someone = require("./Someone");

module.exports = class atSomeone extends Plugin {
async startPlugin () {
this._injectAutoComplete();
powercord.api.commands.registerCommand({
command: '@/Someone',
aliases: [ '@s' ],
description: 'Ats Someone',
usage: '',
async executor () {
return {
send: true,
result: `<@${getRandomUserID()}>`
};
}
});
}
async startPlugin() {
this._injectAutoComplete();
powercord.api.commands.registerCommand({
command: "@/Someone",
aliases: ["@s"],
description: "Ats Someone",
usage: "",
async executor() {
return {
send: true,
result: `<@${getRandomUserID()}>`
};
}
});
}

_injectAutoComplete() {
inject("as-mention-container", MENTIONS, "renderResults", (args, res) => {
if (!"someone".includes(args[1].toLowerCase())) return res;

async _injectAutoComplete () {
const { AUTOCOMPLETE_OPTIONS: { MENTIONS } } = getModule([ 'AUTOCOMPLETE_OPTIONS' ], false);
inject('as-mention-container', MENTIONS, 'renderResults', (args, res) => {
if (args[7].globals.length === 2 || args[7].globals.length === 0) {
args[7].globals.push({
description: 'Mentions Someone!',
text: '@someone'
});
}
try {
const sex = findInReactTree(res, ({ key }) => key === '@someone');
sex.props.onClick = () => {
const currentChannel = require('powercord/webpack').channels.getChannelId();
require('powercord/webpack').getModule([ 'sendMessage' ], false)
.sendMessage(currentChannel, { content: '<@' + getRandomUserID() + '>' });
};
} catch {}
return res;
});
}
res.props.children[3]?.unshift(React.createElement(Someone));
return res;
});
}

pluginWillUnload () {
powercord.api.commands.unregisterCommand('@/Someone');
uninject('as-mention-container');
}
pluginWillUnload() {
powercord.api.commands.unregisterCommand("@/Someone");
uninject("as-mention-container");
}
};

0 comments on commit baa3e6b

Please sign in to comment.