Pre-plugin moves
This commit is contained in:
parent
9fc045cd38
commit
8f7a6510eb
13 changed files with 62 additions and 52 deletions
|
@ -2,7 +2,6 @@
|
|||
* @file Utility functions that are plugin-instance-specific (i.e. use PluginData)
|
||||
*/
|
||||
|
||||
import { AdvancedMessageContent, AllowedMentions, GuildTextableChannel, Member, Message, TextableChannel } from "eris";
|
||||
import { CommandContext, configUtils, ConfigValidationError, GuildPluginData, helpers, PluginOptions } from "knub";
|
||||
import { decodeAndValidateStrict, StrictValidationError, validate } from "./validatorUtils";
|
||||
import { deepKeyIntersect, errorMessage, successMessage, tDeepPartial, tNullable } from "./utils";
|
||||
|
@ -14,11 +13,17 @@ import { Tail } from "./utils/typeUtils";
|
|||
import { AnyPluginData } from "knub/dist/plugins/PluginData";
|
||||
import { ZeppelinPlugin } from "./plugins/ZeppelinPlugin";
|
||||
import { logger } from "./logger";
|
||||
import { APIMessage, GuildMember, Message, MessageMentionOptions, MessageOptions, TextChannel, User } from "discord.js";
|
||||
|
||||
const { getMemberLevel } = helpers;
|
||||
|
||||
export function canActOn(pluginData: GuildPluginData<any>, member1: Member, member2: Member, allowSameLevel = false) {
|
||||
if (member2.id === pluginData.client.user.id) {
|
||||
export function canActOn(
|
||||
pluginData: GuildPluginData<any>,
|
||||
member1: GuildMember,
|
||||
member2: GuildMember,
|
||||
allowSameLevel = false,
|
||||
) {
|
||||
if (member2.id === pluginData.client.user!.id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -180,21 +185,19 @@ export function getPluginConfigPreprocessor(
|
|||
|
||||
export function sendSuccessMessage(
|
||||
pluginData: AnyPluginData<any>,
|
||||
channel: TextableChannel,
|
||||
channel: TextChannel,
|
||||
body: string,
|
||||
allowedMentions?: AllowedMentions,
|
||||
allowedMentions?: MessageMentionOptions,
|
||||
): Promise<Message | undefined> {
|
||||
const emoji = pluginData.fullConfig.success_emoji || undefined;
|
||||
const formattedBody = successMessage(body, emoji);
|
||||
const content: AdvancedMessageContent = allowedMentions
|
||||
const content: MessageOptions = allowedMentions
|
||||
? { content: formattedBody, allowedMentions }
|
||||
: { content: formattedBody };
|
||||
return channel
|
||||
.createMessage(content) // Force line break
|
||||
.send({ content }) // Force line break
|
||||
.catch(err => {
|
||||
const channelInfo = (channel as GuildTextableChannel).guild
|
||||
? `${channel.id} (${(channel as GuildTextableChannel).guild.id})`
|
||||
: `${channel.id}`;
|
||||
const channelInfo = channel.guild ? `${channel.id} (${channel.guild.id})` : `${channel.id}`;
|
||||
logger.warn(`Failed to send success message to ${channelInfo}): ${err.code} ${err.message}`);
|
||||
return undefined;
|
||||
});
|
||||
|
@ -202,21 +205,19 @@ export function sendSuccessMessage(
|
|||
|
||||
export function sendErrorMessage(
|
||||
pluginData: AnyPluginData<any>,
|
||||
channel: TextableChannel,
|
||||
channel: TextChannel,
|
||||
body: string,
|
||||
allowedMentions?: AllowedMentions,
|
||||
allowedMentions?: MessageMentionOptions,
|
||||
): Promise<Message | undefined> {
|
||||
const emoji = pluginData.fullConfig.error_emoji || undefined;
|
||||
const formattedBody = errorMessage(body, emoji);
|
||||
const content: AdvancedMessageContent = allowedMentions
|
||||
const content: MessageOptions = allowedMentions
|
||||
? { content: formattedBody, allowedMentions }
|
||||
: { content: formattedBody };
|
||||
return channel
|
||||
.createMessage(content) // Force line break
|
||||
.send({ ...content, split: false }) // Force line break
|
||||
.catch(err => {
|
||||
const channelInfo = (channel as GuildTextableChannel).guild
|
||||
? `${channel.id} (${(channel as GuildTextableChannel).guild.id})`
|
||||
: `${channel.id}`;
|
||||
const channelInfo = channel.guild ? `${channel.id} (${channel.guild.id})` : `${channel.id}`;
|
||||
logger.warn(`Failed to send error message to ${channelInfo}): ${err.code} ${err.message}`);
|
||||
return undefined;
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue