mirror of
https://github.com/ZeppelinBot/Zeppelin.git
synced 2025-05-10 12:25:02 +00:00
!source: don't show source of messages you don't have access to; allow mods to use the command by default
This commit is contained in:
parent
14af94e7a3
commit
60aff76ebe
6 changed files with 137 additions and 12 deletions
|
@ -71,6 +71,7 @@ const defaultOptions: PluginOptions<UtilityPluginType> = {
|
|||
can_context: true,
|
||||
can_jumbo: true,
|
||||
can_avatar: true,
|
||||
can_source: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -78,7 +79,6 @@ const defaultOptions: PluginOptions<UtilityPluginType> = {
|
|||
config: {
|
||||
can_reload_guild: true,
|
||||
can_ping: true,
|
||||
can_source: true,
|
||||
can_about: true,
|
||||
},
|
||||
},
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
import { utilityCmd } from "../types";
|
||||
import { commandTypeHelpers as ct } from "../../../commandTypes";
|
||||
import { errorMessage } from "../../../utils";
|
||||
import { getBaseUrl } from "../../../pluginUtils";
|
||||
import { getBaseUrl, sendErrorMessage } from "../../../pluginUtils";
|
||||
import moment from "moment-timezone";
|
||||
import { Constants, TextChannel } from "eris";
|
||||
import { hasPermissions } from "../../../utils/hasPermissions";
|
||||
import { canReadChannel } from "../../../utils/canReadChannel";
|
||||
|
||||
export const SourceCmd = utilityCmd({
|
||||
trigger: "source",
|
||||
|
@ -11,22 +14,36 @@ export const SourceCmd = utilityCmd({
|
|||
permission: "can_source",
|
||||
|
||||
signature: {
|
||||
messageId: ct.string(),
|
||||
message: ct.messageTarget(),
|
||||
},
|
||||
|
||||
async run({ message: msg, args, pluginData }) {
|
||||
const savedMessage = await pluginData.state.savedMessages.find(args.messageId);
|
||||
if (!savedMessage) {
|
||||
msg.channel.createMessage(errorMessage("Unknown message"));
|
||||
async run({ message: cmdMessage, args, pluginData }) {
|
||||
if (!canReadChannel(args.message.channel, cmdMessage.member.id)) {
|
||||
sendErrorMessage(pluginData, cmdMessage.channel, "Unknown message");
|
||||
return;
|
||||
}
|
||||
|
||||
const source =
|
||||
(savedMessage.data.content || "<no text content>") + "\n\nSource:\n\n" + JSON.stringify(savedMessage.data);
|
||||
const message = await pluginData.client
|
||||
.getMessage(args.message.channel.id, args.message.messageId)
|
||||
.catch(() => null);
|
||||
if (!message) {
|
||||
sendErrorMessage(pluginData, cmdMessage.channel, "Unknown message");
|
||||
return;
|
||||
}
|
||||
|
||||
const textSource = message.content || "<no text content>";
|
||||
const fullSource = JSON.stringify({
|
||||
id: message.id,
|
||||
content: message.content,
|
||||
attachments: message.attachments,
|
||||
embeds: message.embeds,
|
||||
});
|
||||
|
||||
const source = `${textSource}\n\nSource:\n\n${fullSource}`;
|
||||
|
||||
const archiveId = await pluginData.state.archives.create(source, moment().add(1, "hour"));
|
||||
const baseUrl = getBaseUrl(pluginData);
|
||||
const url = pluginData.state.archives.getUrl(baseUrl, archiveId);
|
||||
msg.channel.createMessage(`Message source: ${url}`);
|
||||
cmdMessage.channel.createMessage(`Message source: ${url}`);
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue