mirror of
https://github.com/Equicord/Equicord.git
synced 2025-02-21 15:48:52 -05:00
@Someone
This commit is contained in:
parent
852da78e7b
commit
08d6d36ba1
1 changed files with 53 additions and 0 deletions
53
src/equicordplugins/atSomeone/index.ts
Normal file
53
src/equicordplugins/atSomeone/index.ts
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Vencord, a Discord client mod
|
||||
* Copyright (c) 2024 Vendicated and contributors
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
import { addPreSendListener, removePreSendListener } from "@api/MessageEvents";
|
||||
import { Devs } from "@utils/constants";
|
||||
import definePlugin from "@utils/types";
|
||||
import { ChannelStore, GuildMemberStore, SelectedChannelStore, SelectedGuildStore } from "@webpack/common";
|
||||
|
||||
export default definePlugin({
|
||||
name: "atSomeone",
|
||||
authors: [Devs.Joona],
|
||||
description: "Mention someone randomly",
|
||||
patches: [
|
||||
{
|
||||
find: ".LAUNCHABLE_APPLICATIONS;",
|
||||
replacement: [
|
||||
{
|
||||
match: /&(\i)\(\)\((\i),\i\(\)\.test\)&&(\i)\.push\(\i\(\)\)/g,
|
||||
replace: "$&,$1()($2,/someone/.test)&&$3.push({text:'@someone',description:'Mention someone randomly'})"
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
find: "inQuote:",
|
||||
replacement: {
|
||||
match: /\|Clyde/,
|
||||
replace: "$&|someone"
|
||||
}
|
||||
}
|
||||
],
|
||||
start() {
|
||||
this.preSend = addPreSendListener((_, msg) => {
|
||||
msg.content = msg.content.replace(/@someone/g, () => `<@${randomUser()}>`);
|
||||
});
|
||||
},
|
||||
|
||||
stop() {
|
||||
removePreSendListener(this.preSend);
|
||||
}
|
||||
});
|
||||
|
||||
const randomUser = () => {
|
||||
const guildId = SelectedGuildStore.getGuildId();
|
||||
if (guildId === null) {
|
||||
const dmUsers = ChannelStore.getChannel(SelectedChannelStore.getChannelId()).recipients;
|
||||
return dmUsers[~~(dmUsers.length * Math.random())];
|
||||
}
|
||||
const members = GuildMemberStore.getMembers(guildId);
|
||||
return members[~~(members.length * Math.random())].userId;
|
||||
};
|
Loading…
Add table
Reference in a new issue