mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-03-16 14:11:50 +00:00
Tags: allow access to the tag user's user/member data
This commit is contained in:
parent
e0f85ec0ee
commit
91363dbc97
1 changed files with 8 additions and 4 deletions
|
@ -1,6 +1,6 @@
|
||||||
import { decorators as d, IPluginOptions, logger } from "knub";
|
import { decorators as d, IPluginOptions, logger } from "knub";
|
||||||
import { Message, TextChannel } from "eris";
|
import { Message, TextChannel } from "eris";
|
||||||
import { errorMessage, successMessage } from "../utils";
|
import { errorMessage, successMessage, stripObjectToScalars } from "../utils";
|
||||||
import { GuildTags } from "../data/GuildTags";
|
import { GuildTags } from "../data/GuildTags";
|
||||||
import { GuildSavedMessages } from "../data/GuildSavedMessages";
|
import { GuildSavedMessages } from "../data/GuildSavedMessages";
|
||||||
import { SavedMessage } from "../data/entities/SavedMessage";
|
import { SavedMessage } from "../data/entities/SavedMessage";
|
||||||
|
@ -174,13 +174,14 @@ export class TagsPlugin extends ZeppelinPlugin<ITagsPluginConfig> {
|
||||||
msg.channel.createMessage(`Tag source:\n${url}`);
|
msg.channel.createMessage(`Tag source:\n${url}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async renderTag(body, args = []) {
|
async renderTag(body, args = [], extraData = {}) {
|
||||||
const dynamicVars = {};
|
const dynamicVars = {};
|
||||||
const maxTagFnCalls = 25;
|
const maxTagFnCalls = 25;
|
||||||
let tagFnCalls = 0;
|
let tagFnCalls = 0;
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
args,
|
args,
|
||||||
|
...extraData,
|
||||||
...this.tagFunctions,
|
...this.tagFunctions,
|
||||||
set(name, val) {
|
set(name, val) {
|
||||||
if (typeof name !== "string") return;
|
if (typeof name !== "string") return;
|
||||||
|
@ -206,7 +207,7 @@ export class TagsPlugin extends ZeppelinPlugin<ITagsPluginConfig> {
|
||||||
if (msg.is_bot) return;
|
if (msg.is_bot) return;
|
||||||
|
|
||||||
const member = await this.getMember(msg.user_id);
|
const member = await this.getMember(msg.user_id);
|
||||||
if (!this.hasPermission("can_use", { member, channelId: msg.channel_id })) return;
|
if (!member || !this.hasPermission("can_use", { member, channelId: msg.channel_id })) return;
|
||||||
|
|
||||||
if (!msg.data.content) return;
|
if (!msg.data.content) return;
|
||||||
if (msg.is_bot) return;
|
if (msg.is_bot) return;
|
||||||
|
@ -229,7 +230,10 @@ export class TagsPlugin extends ZeppelinPlugin<ITagsPluginConfig> {
|
||||||
|
|
||||||
// Format the string
|
// Format the string
|
||||||
try {
|
try {
|
||||||
body = await this.renderTag(body, tagArgs);
|
body = await this.renderTag(body, tagArgs, {
|
||||||
|
member: stripObjectToScalars(member, ["user"]),
|
||||||
|
user: stripObjectToScalars(member.user),
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof TemplateParseError) {
|
if (e instanceof TemplateParseError) {
|
||||||
logger.warn(`Invalid tag format!\nError: ${e.message}\nFormat: ${tag.body}`);
|
logger.warn(`Invalid tag format!\nError: ${e.message}\nFormat: ${tag.body}`);
|
||||||
|
|
Loading…
Add table
Reference in a new issue