mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-21 00:35:02 +00:00
feat: Custom status limit and multiple mention support
This commit is contained in:
parent
7e8ffb9ee3
commit
e8f1ea024b
6 changed files with 75 additions and 22 deletions
|
@ -28,4 +28,9 @@ export class AFK extends BaseRepository {
|
||||||
|
|
||||||
return await this.afk.delete({ user_id });
|
return await this.afk.delete({ user_id });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async isAfk(user_id: string) {
|
||||||
|
const afk = await this.afk.findOne({ user_id });
|
||||||
|
return !!afk?.status;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,15 @@ import { AFK } from "src/data/AFK";
|
||||||
|
|
||||||
import { AfkSetCmd } from "./commands/AFKCmd";
|
import { AfkSetCmd } from "./commands/AFKCmd";
|
||||||
import { AFKNotificationEvt } from "./events/AFKNotificationEvt";
|
import { AFKNotificationEvt } from "./events/AFKNotificationEvt";
|
||||||
|
import { ConfigPreprocessorFn } from "knub/dist/config/configTypes";
|
||||||
|
import { StrictValidationError } from "../../validatorUtils";
|
||||||
|
|
||||||
const defaultOptions: PluginOptions<AFKPluginType> = {
|
const defaultOptions: PluginOptions<AFKPluginType> = {
|
||||||
config: {
|
config: {
|
||||||
can_afk: false,
|
can_afk: false,
|
||||||
allow_links: false,
|
allow_links: false,
|
||||||
allow_invites: false,
|
allow_invites: false,
|
||||||
|
max_status_limit: 12
|
||||||
},
|
},
|
||||||
overrides: [
|
overrides: [
|
||||||
{
|
{
|
||||||
|
@ -19,11 +22,22 @@ const defaultOptions: PluginOptions<AFKPluginType> = {
|
||||||
can_afk: true,
|
can_afk: true,
|
||||||
allow_links: true,
|
allow_links: true,
|
||||||
allow_invites: true,
|
allow_invites: true,
|
||||||
|
max_status_limit: 12,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const configPreprocessor: ConfigPreprocessorFn<AFKPluginType> = options => {
|
||||||
|
if (options.config.max_status_limit) {
|
||||||
|
const max_limit = options.config.max_status_limit;
|
||||||
|
if (max_limit > 24) throw new StrictValidationError([
|
||||||
|
`max_status_limit needs to be under 24 characters.`
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
export const AFKPlugin = zeppelinGuildPlugin<AFKPluginType>()("afk", {
|
export const AFKPlugin = zeppelinGuildPlugin<AFKPluginType>()("afk", {
|
||||||
showInDocs: true,
|
showInDocs: true,
|
||||||
info: {
|
info: {
|
||||||
|
@ -33,6 +47,7 @@ export const AFKPlugin = zeppelinGuildPlugin<AFKPluginType>()("afk", {
|
||||||
|
|
||||||
configSchema: ConfigSchema,
|
configSchema: ConfigSchema,
|
||||||
defaultOptions,
|
defaultOptions,
|
||||||
|
configPreprocessor,
|
||||||
|
|
||||||
commands: [AfkSetCmd],
|
commands: [AfkSetCmd],
|
||||||
events: [AFKNotificationEvt],
|
events: [AFKNotificationEvt],
|
||||||
|
|
|
@ -19,8 +19,9 @@ export const AfkSetCmd = afkCmd({
|
||||||
const status = args.status.join(" ");
|
const status = args.status.join(" ");
|
||||||
|
|
||||||
// Check status length
|
// Check status length
|
||||||
if (status.length > 124) {
|
const maxStatusLength = pluginData.config.getForMember(msg.member).max_status_limit ?? 12;
|
||||||
sendErrorMessage(pluginData, msg.channel, "Status length is above **124** characters.");
|
if (status.length > maxStatusLength) {
|
||||||
|
sendErrorMessage(pluginData, msg.channel, `Status length is above **${maxStatusLength}** characters.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,22 +7,34 @@ export const AFKNotificationEvt = afkEvt({
|
||||||
listener: async ({ pluginData, args: { message } }) => {
|
listener: async ({ pluginData, args: { message } }) => {
|
||||||
// Mention Check (if someone mentions the AFK user)
|
// Mention Check (if someone mentions the AFK user)
|
||||||
if (message.mentions.length) {
|
if (message.mentions.length) {
|
||||||
const afk = await pluginData.state.afkUsers.getUserAFKStatus(message.mentions[0].id);
|
const mentionedMembers: Array<{ id: string, status: string }> = [];
|
||||||
if (!afk) return;
|
for (const user of message.mentions) {
|
||||||
|
const isAfk = await pluginData.state.afkUsers.isAfk(user.id);
|
||||||
|
if (isAfk) {
|
||||||
|
const afk = (await pluginData.state.afkUsers.getUserAFKStatus(user.id))!;
|
||||||
|
mentionedMembers.push({
|
||||||
|
id: afk.user_id,
|
||||||
|
status: afk.status,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sendUserMentionMessage(message, afk.status);
|
const user = mentionedMembers.length > 1
|
||||||
|
? mentionedMembers.map((u) => `<@!${u.id}>: **${u.status}**`)
|
||||||
|
: mentionedMembers[0];
|
||||||
|
await sendUserMentionMessage(message, user);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Self AFK Check (if user is the one that's AFK)
|
// Self AFK Check (if user is the one that's AFK)
|
||||||
const afk = await pluginData.state.afkUsers.getUserAFKStatus(message.author.id);
|
const user = await pluginData.state.afkUsers.getUserAFKStatus(message.author.id);
|
||||||
if (!afk) return;
|
if (!user) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await pluginData.state.afkUsers.clearAFKStatus(message.author.id);
|
await pluginData.state.afkUsers.clearAFKStatus(message.author.id);
|
||||||
} catch (err) {}
|
} catch (err) {}
|
||||||
|
|
||||||
sendWelcomeBackMessage(message);
|
await sendWelcomeBackMessage(message);
|
||||||
}
|
}
|
||||||
});
|
});
|
|
@ -1,14 +1,33 @@
|
||||||
import { Message } from "eris";
|
import { Message } from "eris";
|
||||||
|
|
||||||
export function sendUserMentionMessage(message: Message, status: string) {
|
export function sendUserMentionMessage(message: Message, mentionedMembers: string[] | { id: string, status: string }) {
|
||||||
return message.channel.createMessage({
|
if (!(mentionedMembers instanceof Array)) {
|
||||||
|
const member = mentionedMembers as { id: string, status: string };
|
||||||
|
return message.channel.createMessage({
|
||||||
allowedMentions: {
|
allowedMentions: {
|
||||||
users: [message.author.id],
|
users: [message.author.id],
|
||||||
everyone: false,
|
everyone: false,
|
||||||
roles: false,
|
roles: false,
|
||||||
},
|
},
|
||||||
content: `<@!${message.author.id}>, the user mentioned is currently AFK: **${status}**`,
|
content: `<@!${message.author.id}>, <@!${member.id}> is currently AFK: **${member.status}**`,
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
const deliveredLength = mentionedMembers.length;
|
||||||
|
const arr = mentionedMembers.length > 3 ? mentionedMembers.splice(3) : mentionedMembers;
|
||||||
|
|
||||||
|
return message.channel.createMessage({
|
||||||
|
allowedMentions: {
|
||||||
|
users: [message.author.id],
|
||||||
|
everyone: false,
|
||||||
|
roles: false,
|
||||||
|
},
|
||||||
|
content: `<@!${message.author.id}>, the following users mentioned are AFK:\n\n${mentionedMembers.join('\n')}${
|
||||||
|
deliveredLength > 3
|
||||||
|
? `\n*+${arr.length} more...*`
|
||||||
|
: ''
|
||||||
|
}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function sendWelcomeBackMessage(message: Message) {
|
export function sendWelcomeBackMessage(message: Message) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ export const ConfigSchema = t.type({
|
||||||
can_afk: t.boolean,
|
can_afk: t.boolean,
|
||||||
allow_links: t.boolean,
|
allow_links: t.boolean,
|
||||||
allow_invites: t.boolean,
|
allow_invites: t.boolean,
|
||||||
|
max_status_limit: t.number,
|
||||||
});
|
});
|
||||||
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
export type TConfigSchema = t.TypeOf<typeof ConfigSchema>;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue