mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-11 04:45:02 +00:00
Typed log functions + more
This commit is contained in:
parent
d2ac700143
commit
bed6589d48
166 changed files with 4021 additions and 869 deletions
|
@ -13,6 +13,7 @@ import { ScheduledPostsListCmd } from "./commands/ScheduledPostsListCmd";
|
|||
import { ScheduledPostsShowCmd } from "./commands/ScheduledPostsShowCmd";
|
||||
import { ConfigSchema, PostPluginType } from "./types";
|
||||
import { scheduledPostLoop } from "./util/scheduledPostLoop";
|
||||
import { LogsPlugin } from "../Logs/LogsPlugin";
|
||||
|
||||
const defaultOptions: PluginOptions<PostPluginType> = {
|
||||
config: {
|
||||
|
@ -35,7 +36,7 @@ export const PostPlugin = zeppelinGuildPlugin<PostPluginType>()({
|
|||
prettyName: "Post",
|
||||
},
|
||||
|
||||
dependencies: [TimeAndDatePlugin],
|
||||
dependencies: [TimeAndDatePlugin, LogsPlugin],
|
||||
configSchema: ConfigSchema,
|
||||
defaultOptions,
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import { Channel, Message, TextChannel } from "discord.js";
|
|||
import humanizeDuration from "humanize-duration";
|
||||
import { GuildPluginData } from "knub";
|
||||
import moment from "moment-timezone";
|
||||
import { channelToConfigAccessibleChannel, userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
|
||||
import { channelToTemplateSafeChannel, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { DBDateFormat, errorMessage, MINUTES, StrictMessageContent } from "../../../utils";
|
||||
|
@ -10,6 +10,7 @@ import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
|||
import { PostPluginType } from "../types";
|
||||
import { parseScheduleTime } from "./parseScheduleTime";
|
||||
import { postMessage } from "./postMessage";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
|
||||
const MIN_REPEAT_TIME = 5 * MINUTES;
|
||||
const MAX_REPEAT_TIME = Math.pow(2, 32);
|
||||
|
@ -158,19 +159,19 @@ export async function actualPostCmd(
|
|||
});
|
||||
|
||||
if (opts.repeat) {
|
||||
pluginData.state.logs.log(LogType.SCHEDULED_REPEATED_MESSAGE, {
|
||||
author: userToConfigAccessibleUser(msg.author),
|
||||
channel: channelToConfigAccessibleChannel(targetChannel),
|
||||
pluginData.getPlugin(LogsPlugin).logScheduledRepeatedMessage({
|
||||
author: msg.author,
|
||||
channel: targetChannel,
|
||||
datetime: postAt.format(timeAndDate.getDateFormat("pretty_datetime")),
|
||||
date: postAt.format(timeAndDate.getDateFormat("date")),
|
||||
time: postAt.format(timeAndDate.getDateFormat("time")),
|
||||
repeatInterval: humanizeDuration(opts.repeat),
|
||||
repeatDetails: repeatDetailsStr,
|
||||
repeatDetails: repeatDetailsStr!,
|
||||
});
|
||||
} else {
|
||||
pluginData.state.logs.log(LogType.SCHEDULED_MESSAGE, {
|
||||
author: userToConfigAccessibleUser(msg.author),
|
||||
channel: channelToConfigAccessibleChannel(targetChannel),
|
||||
pluginData.getPlugin(LogsPlugin).logScheduledMessage({
|
||||
author: msg.author,
|
||||
channel: targetChannel,
|
||||
datetime: postAt.format(timeAndDate.getDateFormat("pretty_datetime")),
|
||||
date: postAt.format(timeAndDate.getDateFormat("date")),
|
||||
time: postAt.format(timeAndDate.getDateFormat("time")),
|
||||
|
@ -184,9 +185,9 @@ export async function actualPostCmd(
|
|||
}
|
||||
|
||||
if (opts.repeat) {
|
||||
pluginData.state.logs.log(LogType.REPEATED_MESSAGE, {
|
||||
author: userToConfigAccessibleUser(msg.author),
|
||||
channel: channelToConfigAccessibleChannel(targetChannel),
|
||||
pluginData.getPlugin(LogsPlugin).logRepeatedMessage({
|
||||
author: msg.author,
|
||||
channel: targetChannel,
|
||||
datetime: postAt.format(timeAndDate.getDateFormat("pretty_datetime")),
|
||||
date: postAt.format(timeAndDate.getDateFormat("date")),
|
||||
time: postAt.format(timeAndDate.getDateFormat("time")),
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import { Snowflake, TextChannel, User } from "discord.js";
|
||||
import { GuildPluginData } from "knub";
|
||||
import moment from "moment-timezone";
|
||||
import { channelToConfigAccessibleChannel, userToConfigAccessibleUser } from "../../../utils/configAccessibleObjects";
|
||||
import { channelToTemplateSafeChannel, userToTemplateSafeUser } from "../../../utils/templateSafeObjects";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import { logger } from "../../../logger";
|
||||
import { DBDateFormat, SECONDS } from "../../../utils";
|
||||
import { PostPluginType } from "../types";
|
||||
import { postMessage } from "./postMessage";
|
||||
import { LogsPlugin } from "../../Logs/LogsPlugin";
|
||||
|
||||
const SCHEDULED_POST_CHECK_INTERVAL = 5 * SECONDS;
|
||||
|
||||
|
@ -30,16 +31,16 @@ export async function scheduledPostLoop(pluginData: GuildPluginData<PostPluginTy
|
|||
post.attachments,
|
||||
post.enable_mentions,
|
||||
);
|
||||
pluginData.state.logs.log(LogType.POSTED_SCHEDULED_MESSAGE, {
|
||||
author: userToConfigAccessibleUser(author),
|
||||
channel: channelToConfigAccessibleChannel(channel),
|
||||
pluginData.getPlugin(LogsPlugin).logPostedScheduledMessage({
|
||||
author,
|
||||
channel,
|
||||
messageId: postedMessage.id,
|
||||
});
|
||||
} catch {
|
||||
pluginData.state.logs.log(LogType.BOT_ALERT, {
|
||||
pluginData.getPlugin(LogsPlugin).logBotAlert({
|
||||
body: `Failed to post scheduled message by {userMention(author)} to {channelMention(channel)}`,
|
||||
channel: channelToConfigAccessibleChannel(channel),
|
||||
author: userToConfigAccessibleUser(author),
|
||||
channel,
|
||||
author,
|
||||
});
|
||||
logger.warn(
|
||||
`Failed to post scheduled message to #${channel.name} (${channel.id}) on ${pluginData.guild.name} (${pluginData.guild.id})`,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue