2022-10-21 19:17:06 -04:00
|
|
|
/*
|
|
|
|
* Vencord, a modification for Discord's desktop app
|
|
|
|
* Copyright (c) 2022 Vendicated and contributors
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2023-11-29 21:14:52 -05:00
|
|
|
import { MessageActions } from "@utils/discord";
|
2022-11-28 07:37:55 -05:00
|
|
|
import { mergeDefaults } from "@utils/misc";
|
2023-10-25 10:16:16 -04:00
|
|
|
import { findByPropsLazy } from "@webpack";
|
2022-12-16 09:51:23 -05:00
|
|
|
import { SnowflakeUtils } from "@webpack/common";
|
2022-10-12 16:22:21 -04:00
|
|
|
import { Message } from "discord-types/general";
|
2022-10-22 12:18:41 -04:00
|
|
|
import type { PartialDeep } from "type-fest";
|
|
|
|
|
2022-10-12 16:22:21 -04:00
|
|
|
import { Argument } from "./types";
|
|
|
|
|
2022-11-28 07:37:55 -05:00
|
|
|
const MessageSender = findByPropsLazy("receiveMessage");
|
2022-10-12 16:22:21 -04:00
|
|
|
|
|
|
|
export function generateId() {
|
|
|
|
return `-${SnowflakeUtils.fromTimestamp(Date.now())}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Send a message as Clyde
|
|
|
|
* @param {string} channelId ID of channel to send message to
|
|
|
|
* @param {Message} message Message to send
|
|
|
|
* @returns {Message}
|
|
|
|
*/
|
|
|
|
export function sendBotMessage(channelId: string, message: PartialDeep<Message>): Message {
|
2023-11-29 21:14:52 -05:00
|
|
|
const botMessage = MessageActions.createBotMessage({ channelId, content: "", embeds: [] });
|
2022-10-12 16:22:21 -04:00
|
|
|
|
|
|
|
MessageSender.receiveMessage(channelId, mergeDefaults(message, botMessage));
|
|
|
|
|
|
|
|
return message as Message;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the value of an option by name
|
|
|
|
* @param args Arguments array (first argument passed to execute)
|
|
|
|
* @param name Name of the argument
|
|
|
|
* @param fallbackValue Fallback value in case this option wasn't passed
|
|
|
|
* @returns Value
|
|
|
|
*/
|
|
|
|
export function findOption<T>(args: Argument[], name: string): T & {} | undefined;
|
|
|
|
export function findOption<T>(args: Argument[], name: string, fallbackValue: T): T & {};
|
|
|
|
export function findOption(args: Argument[], name: string, fallbackValue?: any) {
|
|
|
|
return (args.find(a => a.name === name)?.value || fallbackValue) as any;
|
|
|
|
}
|