3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-03-15 05:41:51 +00:00

Merge branch 'master' of github.com:Dragory/ZeppelinBot

This commit is contained in:
Dragory 2021-08-15 00:08:43 +03:00
commit 3ddfb3b65a
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
19 changed files with 72 additions and 35 deletions

View file

@ -65,6 +65,8 @@ These instructions are intended for bot development only.
Configuration is stored in the database in the `configs` table
```yml
prefix: '!'
# role id: level
levels:
"12345678": 100 # Example admin

View file

@ -37,7 +37,7 @@ export function initDocs(app: express.Express) {
app.get("/docs/plugins", (req: express.Request, res: express.Response) => {
res.json(
docsPlugins.map(plugin => {
const thinInfo = plugin.info ? { prettyName: plugin.info.prettyName } : {};
const thinInfo = plugin.info ? { prettyName: plugin.info.prettyName, legacy: plugin.info.legacy ?? false } : {};
return {
name: plugin.name,
info: thinInfo,

View file

@ -73,6 +73,10 @@ const configPreprocessor: ConfigPreprocessorFn<AutomodPluginType> = options => {
rule["enabled"] = true;
}
if (rule["allow_further_rules"] == null) {
rule["allow_further_rules"] = false;
}
if (rule["affects_bots"] == null) {
rule["affects_bots"] = false;
}

View file

@ -72,7 +72,7 @@ export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>,
matchResult.fullSummary = `Triggered automod rule **${ruleName}**\n${matchResult.summary}`.trim();
break triggerLoop;
if (!rule.allow_further_rules) break triggerLoop;
}
}
}
@ -94,7 +94,7 @@ export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>,
});
}
break;
if (!rule.allow_further_rules) break;
}
}
}

View file

@ -26,6 +26,7 @@ export const Rule = t.type({
triggers: t.array(t.partial(AvailableTriggers.props)),
actions: t.partial(AvailableActions.props),
cooldown: tNullable(t.string),
allow_further_rules: t.boolean,
});
export type TRule = t.TypeOf<typeof Rule>;

View file

@ -52,6 +52,7 @@ export const CensorPlugin = zeppelinGuildPlugin<CensorPluginType>()({
Censor words, tokens, links, regex, etc.
For more advanced filtering, check out the Automod plugin!
`),
legacy: true,
},
dependencies: [LogsPlugin],

View file

@ -43,6 +43,7 @@ export const RoleAddCmd = selfGrantableRolesCmd({
pluginData,
msg.channel,
`<@!${msg.author.id}> Unknown ${args.roleNames.length === 1 ? "role" : "roles"}`,
{ users: [msg.author.id] },
);
lock.unlock();
return;
@ -87,6 +88,7 @@ export const RoleAddCmd = selfGrantableRolesCmd({
pluginData,
msg.channel,
`<@!${msg.author.id}> Got an error while trying to grant you the roles`,
{ users: [msg.author.id] },
);
return;
}
@ -118,7 +120,9 @@ export const RoleAddCmd = selfGrantableRolesCmd({
messageParts.push("couldn't recognize some of the roles");
}
sendSuccessMessage(pluginData, msg.channel, `<@!${msg.author.id}> ${messageParts.join("; ")}`);
sendSuccessMessage(pluginData, msg.channel, `<@!${msg.author.id}> ${messageParts.join("; ")}`, {
users: [msg.author.id],
});
lock.unlock();
},

View file

@ -51,12 +51,14 @@ export const RoleRemoveCmd = selfGrantableRolesCmd({
msg.channel,
`<@!${msg.author.id}> Removed ${removedRolesStr.join(", ")} ${removedRolesWord};` +
` couldn't recognize the other roles you mentioned`,
{ users: [msg.author.id] },
);
} else {
sendSuccessMessage(
pluginData,
msg.channel,
`<@!${msg.author.id}> Removed ${removedRolesStr.join(", ")} ${removedRolesWord}`,
{ users: [msg.author.id] },
);
}
} catch {
@ -64,6 +66,7 @@ export const RoleRemoveCmd = selfGrantableRolesCmd({
pluginData,
msg.channel,
`<@!${msg.author.id}> Got an error while trying to remove the roles`,
{ users: [msg.author.id] },
);
}
} else {
@ -71,6 +74,7 @@ export const RoleRemoveCmd = selfGrantableRolesCmd({
pluginData,
msg.channel,
`<@!${msg.author.id}> Unknown ${args.roleNames.length === 1 ? "role" : "roles"}`,
{ users: [msg.author.id] },
);
}

View file

@ -51,6 +51,7 @@ export const SpamPlugin = zeppelinGuildPlugin<SpamPluginType>()({
Basic spam detection and auto-muting.
For more advanced spam filtering, check out the Automod plugin!
`),
legacy: true,
},
dependencies: [LogsPlugin],

View file

@ -1,7 +1,7 @@
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import { customEmojiRegex } from "../../../utils";
import { getEmojiInfoEmbed } from "../functions/getEmojiInfoEmbed";
import { getCustomEmojiId } from "../functions/getCustomEmojiId";
import { utilityCmd } from "../types";
export const EmojiInfoCmd = utilityCmd({
@ -11,17 +11,17 @@ export const EmojiInfoCmd = utilityCmd({
permission: "can_emojiinfo",
signature: {
emoji: ct.string({ required: false }),
emoji: ct.string({ required: true }),
},
async run({ message, args, pluginData }) {
const emojiIdMatch = args.emoji.match(customEmojiRegex);
if (!emojiIdMatch?.[2]) {
const emojiId = getCustomEmojiId(args.emoji);
if (!emojiId) {
sendErrorMessage(pluginData, message.channel, "Emoji not found");
return;
}
const embed = await getEmojiInfoEmbed(pluginData, emojiIdMatch[2]);
const embed = await getEmojiInfoEmbed(pluginData, emojiId);
if (!embed) {
sendErrorMessage(pluginData, message.channel, "Emoji not found");
return;

View file

@ -2,26 +2,20 @@ import { Snowflake } from "discord.js";
import { getChannelId, getRoleId } from "knub/dist/utils";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { sendErrorMessage } from "../../../pluginUtils";
import {
customEmojiRegex,
isValidSnowflake,
noop,
parseInviteCodeInput,
resolveInvite,
resolveUser,
} from "../../../utils";
import { isValidSnowflake, noop, parseInviteCodeInput, resolveInvite, resolveUser } from "../../../utils";
import { getUserInfoEmbed } from "../functions/getUserInfoEmbed";
import { canReadChannel } from "../../../utils/canReadChannel";
import { resolveMessageTarget } from "../../../utils/resolveMessageTarget";
import { getChannelInfoEmbed } from "../functions/getChannelInfoEmbed";
import { getEmojiInfoEmbed } from "../functions/getEmojiInfoEmbed";
import { getGuildPreview } from "../functions/getGuildPreview";
import { getInviteInfoEmbed } from "../functions/getInviteInfoEmbed";
import { getMessageInfoEmbed } from "../functions/getMessageInfoEmbed";
import { getRoleInfoEmbed } from "../functions/getRoleInfoEmbed";
import { getEmojiInfoEmbed } from "../functions/getEmojiInfoEmbed";
import { getCustomEmojiId } from "../functions/getCustomEmojiId";
import { utilityCmd } from "../types";
import { getServerInfoEmbed } from "../functions/getServerInfoEmbed";
import { getSnowflakeInfoEmbed } from "../functions/getSnowflakeInfoEmbed";
import { getUserInfoEmbed } from "../functions/getUserInfoEmbed";
import { utilityCmd } from "../types";
export const InfoCmd = utilityCmd({
trigger: "info",
@ -139,9 +133,9 @@ export const InfoCmd = utilityCmd({
// 8. Emoji
if (userCfg.can_emojiinfo) {
const emojiIdMatch = value.match(customEmojiRegex);
if (emojiIdMatch?.[2]) {
const embed = await getEmojiInfoEmbed(pluginData, emojiIdMatch[2]);
const emojiId = getCustomEmojiId(value);
if (emojiId) {
const embed = await getEmojiInfoEmbed(pluginData, emojiId);
if (embed) {
message.channel.send({ embeds: [embed] });
return;

View file

@ -1,6 +1,7 @@
import { Util } from "discord.js";
import { commandTypeHelpers as ct } from "../../../commandTypes";
import { canActOn, sendSuccessMessage } from "../../../pluginUtils";
import { errorMessage } from "../../../utils";
import { canActOn, sendSuccessMessage } from "../../../pluginUtils";
import { utilityCmd } from "../types";
export const NicknameCmd = utilityCmd({
@ -11,10 +12,19 @@ export const NicknameCmd = utilityCmd({
signature: {
member: ct.resolvedMember(),
nickname: ct.string({ catchAll: true }),
nickname: ct.string({ catchAll: true, required: false }),
},
async run({ message: msg, args, pluginData }) {
if (!args.nickname) {
if (!args.member.nickname) {
msg.channel.send(`<@!${args.member.id}> does not have a nickname`);
} else {
msg.channel.send(`The nickname of <@!${args.member.id}> is **${Util.escapeBold(args.nickname)}**`);
}
return;
}
if (msg.member.id !== args.member.id && !canActOn(pluginData, msg.member, args.member)) {
msg.channel.send(errorMessage("Cannot change nickname: insufficient permissions"));
return;
@ -29,9 +39,7 @@ export const NicknameCmd = utilityCmd({
const oldNickname = args.member.nickname || "<none>";
try {
await args.member.edit({
nick: args.nickname,
});
await args.member.setNickname(args.nickname ?? null);
} catch {
msg.channel.send(errorMessage("Failed to change nickname"));
return;

View file

@ -19,10 +19,13 @@ export const NicknameResetCmd = utilityCmd({
return;
}
if (!args.member.nickname) {
msg.channel.send(errorMessage("User does not have a nickname"));
return;
}
try {
await args.member.edit({
nick: "",
});
await args.member.setNickname(null);
} catch {
msg.channel.send(errorMessage("Failed to reset nickname"));
return;

View file

@ -5,7 +5,7 @@ import { utilityCmd } from "../types";
const { performance } = require("perf_hooks");
export const PingCmd = utilityCmd({
trigger: "ping",
trigger: ["ping", "pong"],
description: "Test the bot's ping to the Discord API",
permission: "can_ping",

View file

@ -0,0 +1,6 @@
const customEmojiRegex = /(?:<a?:[a-z0-9_]{2,32}:)?([1-9]\d+)>?/i;
export function getCustomEmojiId(str: string): string | null {
const emojiIdMatch = str.match(customEmojiRegex);
return emojiIdMatch?.[1] ?? null;
}

View file

@ -27,6 +27,7 @@ export interface ZeppelinGuildPluginBlueprint<TPluginData extends GuildPluginDat
description?: TMarkdown;
usageGuide?: TMarkdown;
configurationGuide?: TMarkdown;
legacy?: boolean;
};
configPreprocessor?: (

View file

@ -49,6 +49,7 @@ export interface ZeppelinPluginInfo {
description?: TMarkdown;
usageGuide?: TMarkdown;
configurationGuide?: TMarkdown;
legacy?: boolean;
}
export interface CommandInfo {

View file

@ -321,7 +321,7 @@
actions:
set_counter:
counter: "antiraid_decay"
amount: 10 # "Disable after 10min"
value: 10 # "Disable after 10min"
start_antiraid_timer_high:
triggers:
@ -330,7 +330,7 @@
actions:
set_counter:
counter: "antiraid_decay"
amount: 20 # "Disable after 20min"
value: 20 # "Disable after 20min"
disable_antiraid_after_timer:
triggers:

View file

@ -155,7 +155,14 @@
...menu,
{
label: 'Plugins',
items: this.plugins.map(plugin => ({
items: this.plugins.filter(plugin => !plugin.info.legacy).map(plugin => ({
label: plugin.info.prettyName || plugin.name,
to: `/docs/plugins/${plugin.name}`,
})),
},
{
label: "Legacy Plugins",
items: this.plugins.filter(plugin => plugin.info.legacy).map(plugin => ({
label: plugin.info.prettyName || plugin.name,
to: `/docs/plugins/${plugin.name}`,
})),