mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 20:35: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,7 +1,7 @@
|
|||
import { PluginOptions } from "knub";
|
||||
import { ConfigSchema, LocateUserPluginType } from "./types";
|
||||
import { zeppelinPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { GuildVCAlerts } from "src/data/GuildVCAlerts";
|
||||
import { zeppelinGuildPlugin } from "../ZeppelinPluginBlueprint";
|
||||
import { GuildVCAlerts } from "../../data/GuildVCAlerts";
|
||||
import { outdatedAlertsLoop } from "./utils/outdatedLoop";
|
||||
import { fillActiveAlertsList } from "./utils/fillAlertsList";
|
||||
import { WhereCmd } from "./commands/WhereCmd";
|
||||
|
@ -27,7 +27,7 @@ const defaultOptions: PluginOptions<LocateUserPluginType> = {
|
|||
],
|
||||
};
|
||||
|
||||
export const LocateUserPlugin = zeppelinPlugin<LocateUserPluginType>()("locate_user", {
|
||||
export const LocateUserPlugin = zeppelinGuildPlugin<LocateUserPluginType>()("locate_user", {
|
||||
showInDocs: true,
|
||||
info: {
|
||||
prettyName: "Locate user",
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { locateUserCommand } from "../types";
|
||||
import { locateUserCmd } from "../types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import moment from "moment-timezone";
|
||||
import humanizeDuration from "humanize-duration";
|
||||
import { MINUTES, SECONDS } from "src/utils";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "src/pluginUtils";
|
||||
import { MINUTES, SECONDS } from "../../../utils";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
|
||||
export const FollowCmd = locateUserCommand({
|
||||
export const FollowCmd = locateUserCmd({
|
||||
trigger: ["follow", "f"],
|
||||
description: "Sets up an alert that notifies you any time `<member>` switches or joins voice channels",
|
||||
usage: "!f 108552944961454080",
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { locateUserCommand } from "../types";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "src/pluginUtils";
|
||||
import { locateUserCmd } from "../types";
|
||||
import { sendErrorMessage, sendSuccessMessage } from "../../../pluginUtils";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { createChunkedMessage, sorter } from "src/utils";
|
||||
import { createChunkedMessage, sorter } from "../../../utils";
|
||||
|
||||
export const ListFollowCmd = locateUserCommand({
|
||||
export const ListFollowCmd = locateUserCmd({
|
||||
trigger: ["follows", "fs"],
|
||||
description: "Displays all of your active alerts ordered by expiration time",
|
||||
usage: "!fs",
|
||||
|
@ -29,7 +29,7 @@ export const ListFollowCmd = locateUserCommand({
|
|||
},
|
||||
});
|
||||
|
||||
export const DeleteFollowCmd = locateUserCommand({
|
||||
export const DeleteFollowCmd = locateUserCmd({
|
||||
trigger: ["follows delete", "fs d"],
|
||||
description:
|
||||
"Deletes the alert at the position <num>.\nThe value needed for <num> can be found using `!follows` (`!fs`)",
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { locateUserCommand } from "../types";
|
||||
import { locateUserCmd } from "../types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { resolveMember } from "src/utils";
|
||||
import { resolveMember } from "../../../utils";
|
||||
import { sendWhere } from "../utils/sendWhere";
|
||||
|
||||
export const WhereCmd = locateUserCommand({
|
||||
export const WhereCmd = locateUserCmd({
|
||||
trigger: ["where", "w"],
|
||||
description: "Posts an instant invite to the voice channel that `<member>` is in",
|
||||
usage: "!w 108552944961454080",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { locateUserEvent } from "../types";
|
||||
import { locateUserEvt } from "../types";
|
||||
|
||||
export const GuildBanRemoveAlertsEvt = locateUserEvent({
|
||||
export const GuildBanRemoveAlertsEvt = locateUserEvt({
|
||||
event: "guildBanAdd",
|
||||
|
||||
async listener(meta) {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { locateUserEvent } from "../types";
|
||||
import { locateUserEvt } from "../types";
|
||||
import { sendAlerts } from "../utils/sendAlerts";
|
||||
import { TextableChannel, VoiceChannel } from "eris";
|
||||
|
||||
export const ChannelJoinAlertsEvt = locateUserEvent({
|
||||
export const ChannelJoinAlertsEvt = locateUserEvt({
|
||||
event: "voiceChannelJoin",
|
||||
|
||||
async listener(meta) {
|
||||
|
@ -12,7 +12,7 @@ export const ChannelJoinAlertsEvt = locateUserEvent({
|
|||
},
|
||||
});
|
||||
|
||||
export const ChannelSwitchAlertsEvt = locateUserEvent({
|
||||
export const ChannelSwitchAlertsEvt = locateUserEvt({
|
||||
event: "voiceChannelSwitch",
|
||||
|
||||
async listener(meta) {
|
||||
|
@ -22,7 +22,7 @@ export const ChannelSwitchAlertsEvt = locateUserEvent({
|
|||
},
|
||||
});
|
||||
|
||||
export const ChannelLeaveAlertsEvt = locateUserEvent({
|
||||
export const ChannelLeaveAlertsEvt = locateUserEvt({
|
||||
event: "voiceChannelLeave",
|
||||
|
||||
async listener(meta) {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import * as t from "io-ts";
|
||||
import { BasePluginType, command, eventListener } from "knub";
|
||||
import { BasePluginType, guildCommand, guildEventListener } from "knub";
|
||||
import { GuildVCAlerts } from "../../data/GuildVCAlerts";
|
||||
import Timeout = NodeJS.Timeout;
|
||||
|
||||
export const ConfigSchema = t.type({
|
||||
can_where: t.boolean,
|
||||
|
@ -9,7 +11,13 @@ export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
|||
|
||||
export interface LocateUserPluginType extends BasePluginType {
|
||||
config: TConfigSchema;
|
||||
state: {
|
||||
alerts: GuildVCAlerts;
|
||||
outdatedAlertsTimeout: Timeout;
|
||||
usersWithAlerts: string[];
|
||||
unloaded: boolean;
|
||||
};
|
||||
}
|
||||
|
||||
export const locateUserCommand = command<LocateUserPluginType>();
|
||||
export const locateUserEvent = eventListener<LocateUserPluginType>();
|
||||
export const locateUserCmd = guildCommand<LocateUserPluginType>();
|
||||
export const locateUserEvt = guildEventListener<LocateUserPluginType>();
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
export async function fillActiveAlertsList(pluginData) {
|
||||
import { GuildPluginData } from "knub";
|
||||
import { LocateUserPluginType } from "../types";
|
||||
|
||||
export async function fillActiveAlertsList(pluginData: GuildPluginData<LocateUserPluginType>) {
|
||||
const allAlerts = await pluginData.state.alerts.getAllGuildAlerts();
|
||||
|
||||
allAlerts.forEach(alert => {
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import { Member, TextableChannel } from "eris";
|
||||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { LocateUserPluginType } from "../types";
|
||||
import { sendErrorMessage } from "src/pluginUtils";
|
||||
import { sendErrorMessage } from "../../../pluginUtils";
|
||||
|
||||
export async function moveMember(
|
||||
pluginData: PluginData<LocateUserPluginType>,
|
||||
pluginData: GuildPluginData<LocateUserPluginType>,
|
||||
toMoveID: string,
|
||||
target: Member,
|
||||
errorChannel: TextableChannel,
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import { SECONDS } from "src/utils";
|
||||
import { SECONDS } from "../../../utils";
|
||||
import { removeUserIdFromActiveAlerts } from "./removeUserIdFromActiveAlerts";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { LocateUserPluginType } from "../types";
|
||||
|
||||
const ALERT_LOOP_TIME = 30 * SECONDS;
|
||||
|
||||
export async function outdatedAlertsLoop(pluginData) {
|
||||
export async function outdatedAlertsLoop(pluginData: GuildPluginData<LocateUserPluginType>) {
|
||||
const outdatedAlerts = await pluginData.state.alerts.getOutdatedAlerts();
|
||||
|
||||
for (const alert of outdatedAlerts) {
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
export async function removeUserIdFromActiveAlerts(pluginData, userId: string) {
|
||||
import { GuildPluginData } from "knub";
|
||||
import { LocateUserPluginType } from "../types";
|
||||
|
||||
export async function removeUserIdFromActiveAlerts(pluginData: GuildPluginData<LocateUserPluginType>, userId: string) {
|
||||
const index = pluginData.state.usersWithAlerts.indexOf(userId);
|
||||
if (index > -1) {
|
||||
pluginData.state.usersWithAlerts.splice(index, 1);
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { LocateUserPluginType } from "../types";
|
||||
import { resolveMember } from "src/utils";
|
||||
import { resolveMember } from "../../../utils";
|
||||
import { sendWhere } from "./sendWhere";
|
||||
import { TextableChannel } from "eris";
|
||||
import { moveMember } from "./moveMember";
|
||||
|
||||
export async function sendAlerts(pluginData: PluginData<LocateUserPluginType>, userId: string) {
|
||||
export async function sendAlerts(pluginData: GuildPluginData<LocateUserPluginType>, userId: string) {
|
||||
const triggeredAlerts = await pluginData.state.alerts.getAlertsByUserId(userId);
|
||||
const member = await resolveMember(pluginData.client, pluginData.guild, userId);
|
||||
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
import { Member, TextableChannel, VoiceChannel } from "eris";
|
||||
import { getInviteLink } from "knub/dist/helpers";
|
||||
import { createOrReuseInvite } from "./createOrReuseInvite";
|
||||
import { PluginData } from "knub";
|
||||
import { GuildPluginData } from "knub";
|
||||
import { LocateUserPluginType } from "../types";
|
||||
import { sendErrorMessage } from "../../../pluginUtils";
|
||||
|
||||
export async function sendWhere(
|
||||
pluginData: PluginData<LocateUserPluginType>,
|
||||
pluginData: GuildPluginData<LocateUserPluginType>,
|
||||
member: Member,
|
||||
channel: TextableChannel,
|
||||
prepend: string,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue