mirror of
https://github.com/xHyroM/roles-bot.git
synced 2024-12-22 13:51:04 +01:00
Allow empty message
This commit is contained in:
parent
6ec3bb47b3
commit
1f23b2536e
3 changed files with 19 additions and 18 deletions
|
@ -1,5 +1,6 @@
|
|||
import { APIApplicationCommandInteraction, APIInteractionResponse, APIMessageComponentInteraction, APIPingInteraction, InteractionResponseType, InteractionType, MessageFlags, RouteBases, Routes } from 'discord-api-types/v9';
|
||||
import { isJSON } from './utils/isJson';
|
||||
import { resolvePartialEmoji } from './utils/resolveEmoji';
|
||||
import { verify } from './utils/verify';
|
||||
|
||||
const respond = (response: APIInteractionResponse) => new Response(JSON.stringify(response), {headers: {'content-type': 'application/json'}});
|
||||
|
@ -42,11 +43,11 @@ export const handleRequest = async(request: Request): Promise<Response> => {
|
|||
if (!json) return badFormatting();
|
||||
|
||||
const channelId = json.channel;
|
||||
const message = json.message?.toString();
|
||||
let message = json.message?.toString();
|
||||
let roles = json.roles;
|
||||
|
||||
if (!channelId) return badFormatting();
|
||||
if (!message) return badFormatting();
|
||||
if (!message) message = '';
|
||||
if (!roles || Object.values(json.roles).filter((role: any) => role.id && role.label).length === 0 || roles.length === 0 || roles.length > 25) return badFormatting(roles.length > 25);
|
||||
|
||||
roles = roles.map((r: any) => {
|
||||
|
@ -88,13 +89,13 @@ export const handleRequest = async(request: Request): Promise<Response> => {
|
|||
content: message,
|
||||
components: finalComponents
|
||||
})
|
||||
}).catch(() => {});
|
||||
}).catch(e => e);
|
||||
|
||||
return respond({
|
||||
type: InteractionResponseType.ChannelMessageWithSource,
|
||||
data: {
|
||||
flags: 64,
|
||||
content: fetched?.ok ? 'Done!' : 'Error, invalid channelId or duplication button ids.'
|
||||
content: fetched?.ok ? 'Done!' : 'Error, bad channel id/missing permissions.'
|
||||
}
|
||||
});
|
||||
} else if (interaction.type === InteractionType.MessageComponent) {
|
||||
|
|
|
@ -2,18 +2,18 @@
|
|||
* https://github.com/discordjs/discord.js/blob/3c0bbac82fa9988af4a62ff00c66d149fbe6b921/packages/discord.js/src/util/Util.js#L292-L311
|
||||
*/
|
||||
|
||||
const resolvePartialEmoji = (emoji: string) => {
|
||||
if (!emoji) return null;
|
||||
if (typeof emoji === 'string') return /^\d{17,19}$/.test(emoji) ? { id: emoji } : parseEmoji(emoji);
|
||||
const { id, name, animated } = emoji;
|
||||
if (!id && !name) return null;
|
||||
return { id, name, animated: Boolean(animated) };
|
||||
}
|
||||
export const resolvePartialEmoji = (emoji: string) => {
|
||||
if (!emoji) return null;
|
||||
if (typeof emoji === 'string') return /^\d{17,19}$/.test(emoji) ? { id: emoji } : parseEmoji(emoji);
|
||||
const { id, name, animated } = emoji;
|
||||
if (!id && !name) return null;
|
||||
return { id, name, animated: Boolean(animated) };
|
||||
};
|
||||
|
||||
const parseEmoji = (text: string) => {
|
||||
if (text.includes('%')) text = decodeURIComponent(text);
|
||||
if (!text.includes(':')) return { animated: false, name: text, id: null };
|
||||
export const parseEmoji = (text: string) => {
|
||||
if (text.includes('%')) text = decodeURIComponent(text);
|
||||
if (!text.includes(':')) return { animated: false, name: text, id: null };
|
||||
|
||||
const match = text.match(/<?(?:(a):)?(\w{2,32}):(\d{17,19})?>?/);
|
||||
return match && { animated: Boolean(match[1]), name: match[2], id: match[3] ?? null };
|
||||
}
|
||||
const match = text.match(/<?(?:(a):)?(\w{2,32}):(\d{17,19})?>?/);
|
||||
return match && { animated: Boolean(match[1]), name: match[2], id: match[3] ?? null };
|
||||
};
|
|
@ -18,7 +18,7 @@ export default function Home() {
|
|||
<h1>Generate</h1>
|
||||
<form>
|
||||
<input placeholder="Your Message" name="message" id="message"/><br />
|
||||
<input placeholder="Channel Id" name="channel" id="channel"/>
|
||||
<input placeholder="Channel Id*" name="channel" id="channel" required/>
|
||||
</form>
|
||||
<button id="addRole">Add Role</button>
|
||||
<button id="buttonCopy">Copy</button>
|
||||
|
|
Loading…
Reference in a new issue