Add tAllowedMentions

Mirrors AllowedMentions type from Eris
This commit is contained in:
Dragory 2021-04-29 00:48:37 +03:00
parent 7e40308a8a
commit f2cf46e734
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
2 changed files with 21 additions and 1 deletions

View file

@ -1,6 +1,10 @@
import { convertDelayStringToMS, convertMSToDelayString, getUrlsInString } from "./utils";
import * as ioTs from "io-ts";
import { convertDelayStringToMS, convertMSToDelayString, getUrlsInString, tAllowedMentions } from "./utils";
import test from "ava";
import { AllowedMentions as ErisAllowedMentions } from "eris";
type AssertEquals<TActual, TExpected> = TActual extends TExpected ? true : false;
test("getUrlsInString(): detects full links", t => {
const urls = getUrlsInString("foo https://google.com/ bar");
@ -45,3 +49,9 @@ test("delay strings: reverse conversion (conservative)", t => {
const expected = "2w";
t.is(convertMSToDelayString(ms), expected);
});
test("tAllowedMentions matches Eris's AllowedMentions", t => {
type TAllowedMentions = ioTs.TypeOf<typeof tAllowedMentions>;
const typeTest: AssertEquals<TAllowedMentions, ErisAllowedMentions> = true;
t.pass();
});

View file

@ -282,6 +282,16 @@ export const tStrictMessageContent = t.type({
export const tMessageContent = t.union([t.string, tStrictMessageContent]);
/**
* Mirrors AllowedMentions from Eris
*/
export const tAllowedMentions = t.type({
everyone: tNormalizedNullOptional(t.boolean),
users: tNormalizedNullOptional(t.union([t.boolean, t.array(t.string)])),
roles: tNormalizedNullOptional(t.union([t.boolean, t.array(t.string)])),
repliedUser: tNormalizedNullOptional(t.boolean),
});
export function dropPropertiesByName(obj, propName) {
if (obj.hasOwnProperty(propName)) delete obj[propName];
for (const value of Object.values(obj)) {