mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-11 04:45:02 +00:00
Update to new Knub 30 beta. Code clean-up.
This commit is contained in:
parent
5d579446c5
commit
2f470dc37a
299 changed files with 1075 additions and 1004 deletions
|
@ -1,9 +1,9 @@
|
|||
import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { PluginOptions } from "knub";
|
||||
import { ConfigSchema, PostPluginType } from "./types";
|
||||
import { GuildSavedMessages } from "src/data/GuildSavedMessages";
|
||||
import { GuildScheduledPosts } from "src/data/GuildScheduledPosts";
|
||||
import { GuildLogs } from "src/data/GuildLogs";
|
||||
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
|
||||
import { GuildScheduledPosts } from "../../data/GuildScheduledPosts";
|
||||
import { GuildLogs } from "../../data/GuildLogs";
|
||||
import { PostCmd } from "./commands/PostCmd";
|
||||
import { PostEmbedCmd } from "./commands/PostEmbedCmd";
|
||||
import { EditCmd } from "./commands/EditCmd";
|
||||
|
@ -28,7 +28,7 @@ const defaultOptions: PluginOptions<PostPluginType> = {
|
|||
],
|
||||
};
|
||||
|
||||
export const PostPlugin = zeppelinPlugin<PostPluginType>()("post", {
|
||||
export const PostPlugin = zeppelinGuildPlugin<PostPluginType>()("post", {
|
||||
showInDocs: true,
|
||||
info: {
|
||||
prettyName: "Post",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { postCmd } from "../types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "src/pluginUtils";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { formatContent } from "../util/formatContent";
|
||||
|
||||
export const EditCmd = postCmd({
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { postCmd } from "../types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "src/pluginUtils";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { Embed } from "eris";
|
||||
import { trimLines } from "src/utils";
|
||||
import { trimLines } from "../../../utils";
|
||||
import { formatContent } from "../util/formatContent";
|
||||
import { parseColor } from "../../../utils/parseColor";
|
||||
import { rgbToInt } from "../../../utils/rgbToInt";
|
||||
|
@ -52,7 +52,7 @@ export const EditEmbedCmd = postCmd({
|
|||
await sendSuccessMessage(pluginData, msg.channel, "Embed edited");
|
||||
|
||||
if (args.content) {
|
||||
const prefix = pluginData.guildConfig.prefix || "!";
|
||||
const prefix = pluginData.fullConfig.prefix || "!";
|
||||
msg.channel.createMessage(
|
||||
trimLines(`
|
||||
<@!${msg.author.id}> You can now specify an embed's content directly at the end of the command:
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { postCmd } from "../types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { actualPostCmd } from "../util/actualPostCmd";
|
||||
import { sendErrorMessage } from "src/pluginUtils";
|
||||
import { sendErrorMessage } from "../../../pluginUtils";
|
||||
import { Embed } from "eris";
|
||||
import { isValidEmbed, trimLines } from "src/utils";
|
||||
import { isValidEmbed, trimLines } from "../../../utils";
|
||||
import { formatContent } from "../util/formatContent";
|
||||
import { parseColor } from "../../../utils/parseColor";
|
||||
import { rgbToInt } from "../../../utils/rgbToInt";
|
||||
|
@ -72,7 +72,7 @@ export const PostEmbedCmd = postCmd({
|
|||
}
|
||||
|
||||
if (args.content) {
|
||||
const prefix = pluginData.guildConfig.prefix || "!";
|
||||
const prefix = pluginData.fullConfig.prefix || "!";
|
||||
msg.channel.createMessage(
|
||||
trimLines(`
|
||||
<@!${msg.author.id}> You can now specify an embed's content directly at the end of the command:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { postCmd } from "../types";
|
||||
import { sorter } from "src/utils";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "src/pluginUtils";
|
||||
import { sorter } from "../../../utils";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
|
||||
export const ScheduledPostsDeleteCmd = postCmd({
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
deactivateMentions,
|
||||
createChunkedMessage,
|
||||
DBDateFormat,
|
||||
} from "src/utils";
|
||||
} from "../../../utils";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import moment from "moment-timezone";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { postCmd } from "../types";
|
||||
import { sorter } from "src/utils";
|
||||
import { sendErrorMessage } from "src/pluginUtils";
|
||||
import { sorter } from "../../../utils";
|
||||
import { sendErrorMessage } from "../../../pluginUtils";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { postMessage } from "../util/postMessage";
|
||||
import { TextChannel } from "eris";
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import * as t from "io-ts";
|
||||
import { BasePluginType, command } from "knub";
|
||||
import { GuildSavedMessages } from "src/data/GuildSavedMessages";
|
||||
import { GuildScheduledPosts } from "src/data/GuildScheduledPosts";
|
||||
import { GuildLogs } from "src/data/GuildLogs";
|
||||
import { BasePluginType, guildCommand } from "knub";
|
||||
import { GuildSavedMessages } from "../../data/GuildSavedMessages";
|
||||
import { GuildScheduledPosts } from "../../data/GuildScheduledPosts";
|
||||
import { GuildLogs } from "../../data/GuildLogs";
|
||||
|
||||
export const ConfigSchema = t.type({
|
||||
can_post: t.boolean,
|
||||
|
@ -20,4 +20,4 @@ export interface PostPluginType extends BasePluginType {
|
|||
};
|
||||
}
|
||||
|
||||
export const postCmd = command<PostPluginType>();
|
||||
export const postCmd = guildCommand<PostPluginType>();
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { Message, Channel, TextChannel } from "eris";
|
||||
import { StrictMessageContent, errorMessage, stripObjectToScalars, MINUTES, DBDateFormat } from "src/utils";
|
||||
import { StrictMessageContent, errorMessage, stripObjectToScalars, MINUTES, DBDateFormat } from "../../../utils";
|
||||
import moment from "moment-timezone";
|
||||
import { LogType } from "src/data/LogType";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "src/pluginUtils";
|
||||
import { PluginData } from "knub";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { PostPluginType } from "../types";
|
||||
import { parseScheduleTime } from "./parseScheduleTime";
|
||||
import { postMessage } from "./postMessage";
|
||||
|
@ -15,7 +15,7 @@ const MAX_REPEAT_TIME = Math.pow(2, 32);
|
|||
const MAX_REPEAT_UNTIL = moment.utc().add(100, "years");
|
||||
|
||||
export async function actualPostCmd(
|
||||
pluginData: PluginData<PostPluginType>,
|
||||
pluginData: GuildPluginData<PostPluginType>,
|
||||
msg: Message,
|
||||
targetChannel: Channel,
|
||||
content: StrictMessageContent,
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
export function formatContent(str) {
|
||||
export function formatContent(str: string) {
|
||||
return str.replace(/\\n/g, "\n");
|
||||
}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
import moment, { Moment } from "moment-timezone";
|
||||
import { convertDelayStringToMS } from "src/utils";
|
||||
import { PluginData } from "knub";
|
||||
import { convertDelayStringToMS } from "../../../utils";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { TimeAndDatePlugin } from "../../TimeAndDate/TimeAndDatePlugin";
|
||||
|
||||
// TODO: Extract out of the Post plugin, use everywhere with a date input
|
||||
export async function parseScheduleTime(pluginData: PluginData<any>, memberId: string, str: string): Promise<Moment> {
|
||||
export async function parseScheduleTime(
|
||||
pluginData: GuildPluginData<any>,
|
||||
memberId: string,
|
||||
str: string,
|
||||
): Promise<Moment> {
|
||||
const tz = await pluginData.getPlugin(TimeAndDatePlugin).getMemberTz(memberId);
|
||||
|
||||
const dt1 = moment.tz(str, "YYYY-MM-DD HH:mm:ss", tz);
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { PostPluginType } from "../types";
|
||||
import { TextChannel, MessageContent, Attachment, Message, Role } from "eris";
|
||||
import { downloadFile, getRoleMentions } from "src/utils";
|
||||
import { downloadFile, getRoleMentions } from "../../../utils";
|
||||
import fs from "fs";
|
||||
import { formatContent } from "./formatContent";
|
||||
|
||||
const fsp = fs.promises;
|
||||
|
||||
export async function postMessage(
|
||||
pluginData: PluginData<PostPluginType>,
|
||||
pluginData: GuildPluginData<PostPluginType>,
|
||||
channel: TextChannel,
|
||||
content: MessageContent,
|
||||
attachments: Attachment[] = [],
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { PostPluginType } from "../types";
|
||||
import { logger } from "src/logger";
|
||||
import { stripObjectToScalars, SECONDS, DBDateFormat } from "src/utils";
|
||||
import { LogType } from "src/data/LogType";
|
||||
import { logger } from "../../../logger";
|
||||
import { stripObjectToScalars, SECONDS, DBDateFormat } from "../../../utils";
|
||||
import { LogType } from "../../../data/LogType";
|
||||
import moment from "moment-timezone";
|
||||
import { TextChannel, User } from "eris";
|
||||
import { postMessage } from "./postMessage";
|
||||
|
||||
const SCHEDULED_POST_CHECK_INTERVAL = 5 * SECONDS;
|
||||
|
||||
export async function scheduledPostLoop(pluginData: PluginData<PostPluginType>) {
|
||||
export async function scheduledPostLoop(pluginData: GuildPluginData<PostPluginType>) {
|
||||
const duePosts = await pluginData.state.scheduledPosts.getDueScheduledPosts();
|
||||
for (const post of duePosts) {
|
||||
const channel = pluginData.guild.channels.get(post.channel_id);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue