This Snippet will take a Discord Message sent in a certain channel, and send it to Twitter. This bot removes the hassle of having to put greetings in your Tweets, as all Tweets will have a beginning and end greeting. Another advantage to this is not having to sign in to the same account, and instead you can easily use a private text channel.
const lib = require('lib')({token: process.env.STDLIB_SECRET_TOKEN});
const endGreetings = [
'Thanks',
'Sincerely',
'Thank You',
'Kind Regards',
'Regards',
'Cheers',
];
let endGreeting = endGreetings[Math.floor(Math.random() * 6)];
var today = new Date();
var hour = today.getHours();
var beginGreetings = null;
if (hour < 6) {
beginGreetings = 'Good Night';
} else if (hour < 12) {
beginGreetings = 'Good Morning';
} else if (hour < 18) {
beginGreetings = 'Good Afternoon';
} else {
beginGreetings = 'Good Evening';
}
if (context.params.event.channel_id == process.env.CHANNEL_ID) {
await lib.twitter.tweets['@1.1.2'].statuses.create({
status: `${beginGreetings}. ${context.params.event.content} \n \n${endGreeting}, ${context.params.event.author.username}`,
});
await lib.discord.channels['@0.3.2'].messages.create({
channel_id: process.env.CHANNEL_ID,
content: ``,
embed: {
type: `rich`,
title: `Successfully Sent`,
description: `${beginGreetings}. ${context.params.event.content} \n \n${endGreeting}, ${context.params.event.author.username}`,
color: 0x00fff,
},
});
await lib.discord.channels['@0.3.2'].messages.destroy({
message_id: `${context.params.event.id}`,
channel_id: process.env.CHANNEL_ID,
});
}