Last active
March 5, 2018 13:51
-
-
Save benluxford/6352dba27f3da520150857dc0d665f48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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