Skip to content
This repository has been archived by the owner on Oct 20, 2021. It is now read-only.

Commit

Permalink
Merge pull request #201 from Spudnik-Group/hotfix/v0.6.3
Browse files Browse the repository at this point in the history
fix move command
  • Loading branch information
naterchrdsn committed Dec 8, 2018
2 parents 94e6abd + 244a558 commit 85591d1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "spudnik",
"description": "An awesome chat bot for Discord.",
"version": "0.6.2",
"version": "0.6.3",
"license": "Apache-2.0",
"readme": "README.md",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/spudnik.ts
@@ -1,5 +1,5 @@
import chalk from 'chalk';
import { Channel, Guild, GuildChannel, GuildMember, Message, MessageAttachment, MessageEmbed, MessageReaction, PresenceData, TextChannel } from 'discord.js';
import { Channel, Guild, GuildChannel, GuildMember, Message, MessageEmbed, MessageReaction, PresenceData, TextChannel } from 'discord.js';
import { CommandoClient } from 'discord.js-commando';
import * as http from 'http';
import Mongoose = require('mongoose');
Expand Down
69 changes: 39 additions & 30 deletions src/modules/mod/move.ts
@@ -1,4 +1,4 @@
import { Channel, GuildMember, Message, MessageEmbed, TextChannel } from 'discord.js';
import { Channel, GuildMember, Message, MessageEmbed, TextChannel, MessageAttachment } from 'discord.js';
import { Command, CommandMessage, CommandoClient } from 'discord.js-commando';
import { getEmbedColor } from '../../lib/custom-helpers';
import { sendSimpleEmbeddedError } from '../../lib/helpers';
Expand Down Expand Up @@ -82,48 +82,57 @@ export default class MoveCommand extends Command {
if (originalMessage !== undefined) {
const destinationChannel = args.channel;

if (originalMessage.embeds.length === 0) {
if (destinationChannel && destinationChannel.type === 'text') {
const moveMessage = new MessageEmbed({
author: {
icon_url: `${originalMessage.author.displayAvatarURL()}`,
name: `${originalMessageAuthor.displayName}`
},
color: getEmbedColor(msg),
description: `${originalMessage.content}`,
footer: {
text: `Originally posted at ${originalMessage.createdAt}`
}
});
if (destinationChannel && destinationChannel.type === 'text') {
const moveMessage = new MessageEmbed({
author: {
icon_url: `${originalMessage.author.displayAvatarURL()}`,
name: `${originalMessageAuthor.displayName}`
},
color: getEmbedColor(msg),
description: `${originalMessage.content}`,
footer: {
text: `Originally posted at ${originalMessage.createdAt}`
}
});

const fields: any = [];

const fields: any = [];
fields.push({
inline: true,
name: 'Original post by:',
value: `<@${originalMessageAuthor.id}> in <#${originalChannel.id}>`
});

if (args.reason) {
fields.push({
inline: true,
name: 'Original post by:',
value: `<@${originalMessageAuthor.id}> in <#${originalChannel.id}>`
name: 'Moved for:',
value: `${args.reason}`
});
}

if (args.reason) {
fields.push({
inline: true,
name: 'Moved for:',
value: `${args.reason}`
});
}
if (fields !== []) {
moveMessage.fields = fields;
}

if (fields !== []) {
moveMessage.fields = fields;
}
moveMessage.attachFiles(originalMessage.attachments.map(a => a.attachment.toString()));

(destinationChannel as TextChannel).send(moveMessage);
if (originalMessage.embeds.length === 0) {
await (destinationChannel as TextChannel).send(moveMessage);

return originalMessage.delete();
} else {
return sendSimpleEmbeddedError(msg, 'Cannot move a text message to a non-text channel.');
const messages: MessageEmbed[] = new Array();

messages.push(moveMessage);
messages.concat(originalMessage.embeds);

await (destinationChannel as TextChannel).send(messages);

return originalMessage.delete();
}
} else {
return sendSimpleEmbeddedError(msg, 'Cannot move a message that contains an embed to a different channel.');
return sendSimpleEmbeddedError(msg, 'Cannot move a text message to a non-text channel.');
}

} else {
Expand Down

0 comments on commit 85591d1

Please sign in to comment.