Skip to content

Instantly share code, notes, and snippets.

@benluxford
Last active March 5, 2018 13:51
Show Gist options
  • Save benluxford/6352dba27f3da520150857dc0d665f48 to your computer and use it in GitHub Desktop.
Save benluxford/6352dba27f3da520150857dc0d665f48 to your computer and use it in GitHub Desktop.
module.exports = {
request(message, copyId) {
this.op = message.author;
this.channel = message.channel;
this.copyID = copyId;
// Delete the trigger message from the channel
message.delete().then(this.getMessage()).catch(console.error);
},
// Get the requested message
getMessage() {
this.channel.fetchMessage(this.copyID)
.then(message => {
this.author = message.author;
this.content = message.content;
this.createdAt = creationDate(message.createdTimestamp);
this.send();
})
.catch(err => {
this.content = `**ERROR**: Message ${err.message}`;
this.sendPm();
});
},
// Send the message to the channel it was requested in
send() {
this.channel.sendMessage(`By: <@${this.author.id}>, ${this.createdAt}\n\n${this.content}`)
.then(() => {
this.content = `I have reposted the message:\n\n ${this.content}`;
this.sendPm();
})
.catch(console.error);
},
// Send a pm to the user that requested the copy - status update
sendPm() {
this.op.sendMessage(`**Hi ${this.op.username}** - ${this.content}`)
.then(res => {
// Do something aka notify/persist/make a pizza/call your mother
})
.catch(console.error);
},
};
// Helper/s
// Format the created timestamp
let creationDate = timestamp => new Date(timestamp).toUTCString();
@benluxford
Copy link
Author

Usage = require the module e.g.
const echo = require('./echo') echo.request(DiscordMessageObject, IdOfTheMessageToBeCloned)

You will have to write your own regex pattern.. Ideally there would be a -s option to save as a name for easy future cloning aka
!echo someName

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment