Type fixes + use template safe values for renderTemplate() everywhere

This commit is contained in:
Dragory 2021-08-18 20:32:45 +03:00
parent e16eb8c8d1
commit d109a58cb7
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
21 changed files with 190 additions and 98 deletions

View file

@ -2,7 +2,7 @@ import { Snowflake } from "discord.js";
import * as t from "io-ts";
import { GuildPluginData } from "knub";
import { canActOn } from "../../../pluginUtils";
import { renderTemplate } from "../../../templateFormatter";
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
import { resolveMember } from "../../../utils";
import { ActionError } from "../ActionError";
import { CustomEventsPluginType, TCustomEvent } from "../types";
@ -17,7 +17,7 @@ export type TAddRoleAction = t.TypeOf<typeof AddRoleAction>;
export async function addRoleAction(
pluginData: GuildPluginData<CustomEventsPluginType>,
action: TAddRoleAction,
values: any,
values: TemplateSafeValueContainer,
event: TCustomEvent,
eventData: any,
) {

View file

@ -1,7 +1,7 @@
import * as t from "io-ts";
import { GuildPluginData } from "knub";
import { CaseTypes } from "../../../data/CaseTypes";
import { renderTemplate } from "../../../templateFormatter";
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
import { CasesPlugin } from "../../Cases/CasesPlugin";
import { ActionError } from "../ActionError";
import { CustomEventsPluginType, TCustomEvent } from "../types";
@ -18,7 +18,7 @@ export type TCreateCaseAction = t.TypeOf<typeof CreateCaseAction>;
export async function createCaseAction(
pluginData: GuildPluginData<CustomEventsPluginType>,
action: TCreateCaseAction,
values: any,
values: TemplateSafeValueContainer,
event: TCustomEvent,
eventData: any,
) {

View file

@ -4,6 +4,7 @@ import { GuildPluginData } from "knub";
import { convertDelayStringToMS, noop, tDelayString } from "../../../utils";
import { ActionError } from "../ActionError";
import { CustomEventsPluginType, TCustomEvent } from "../types";
import { TemplateSafeValueContainer } from "../../../templateFormatter";
export const MakeRoleMentionableAction = t.type({
type: t.literal("make_role_mentionable"),
@ -15,7 +16,7 @@ export type TMakeRoleMentionableAction = t.TypeOf<typeof MakeRoleMentionableActi
export async function makeRoleMentionableAction(
pluginData: GuildPluginData<CustomEventsPluginType>,
action: TMakeRoleMentionableAction,
values: any,
values: TemplateSafeValueContainer,
event: TCustomEvent,
eventData: any,
) {

View file

@ -3,6 +3,7 @@ import * as t from "io-ts";
import { GuildPluginData } from "knub";
import { ActionError } from "../ActionError";
import { CustomEventsPluginType, TCustomEvent } from "../types";
import { TemplateSafeValueContainer } from "../../../templateFormatter";
export const MakeRoleUnmentionableAction = t.type({
type: t.literal("make_role_unmentionable"),
@ -13,7 +14,7 @@ export type TMakeRoleUnmentionableAction = t.TypeOf<typeof MakeRoleUnmentionable
export async function makeRoleUnmentionableAction(
pluginData: GuildPluginData<CustomEventsPluginType>,
action: TMakeRoleUnmentionableAction,
values: any,
values: TemplateSafeValueContainer,
event: TCustomEvent,
eventData: any,
) {

View file

@ -1,7 +1,7 @@
import { Snowflake, TextChannel } from "discord.js";
import * as t from "io-ts";
import { GuildPluginData } from "knub";
import { renderTemplate } from "../../../templateFormatter";
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
import { ActionError } from "../ActionError";
import { CustomEventsPluginType } from "../types";
@ -15,7 +15,7 @@ export type TMessageAction = t.TypeOf<typeof MessageAction>;
export async function messageAction(
pluginData: GuildPluginData<CustomEventsPluginType>,
action: TMessageAction,
values: any,
values: TemplateSafeValueContainer,
) {
const targetChannelId = await renderTemplate(action.channel, values, false);
const targetChannel = pluginData.guild.channels.cache.get(targetChannelId as Snowflake);

View file

@ -2,7 +2,7 @@ import { Snowflake, VoiceChannel } from "discord.js";
import * as t from "io-ts";
import { GuildPluginData } from "knub";
import { canActOn } from "../../../pluginUtils";
import { renderTemplate } from "../../../templateFormatter";
import { renderTemplate, TemplateSafeValueContainer } from "../../../templateFormatter";
import { resolveMember } from "../../../utils";
import { ActionError } from "../ActionError";
import { CustomEventsPluginType, TCustomEvent } from "../types";
@ -17,7 +17,7 @@ export type TMoveToVoiceChannelAction = t.TypeOf<typeof MoveToVoiceChannelAction
export async function moveToVoiceChannelAction(
pluginData: GuildPluginData<CustomEventsPluginType>,
action: TMoveToVoiceChannelAction,
values: any,
values: TemplateSafeValueContainer,
event: TCustomEvent,
eventData: any,
) {

View file

@ -3,6 +3,7 @@ import * as t from "io-ts";
import { GuildPluginData } from "knub";
import { ActionError } from "../ActionError";
import { CustomEventsPluginType, TCustomEvent } from "../types";
import { TemplateSafeValueContainer } from "../../../templateFormatter";
export const SetChannelPermissionOverridesAction = t.type({
type: t.literal("set_channel_permission_overrides"),
@ -21,7 +22,7 @@ export type TSetChannelPermissionOverridesAction = t.TypeOf<typeof SetChannelPer
export async function setChannelPermissionOverridesAction(
pluginData: GuildPluginData<CustomEventsPluginType>,
action: TSetChannelPermissionOverridesAction,
values: any,
values: TemplateSafeValueContainer,
event: TCustomEvent,
eventData: any,
) {