Compare commits

..

2 commits

Author SHA1 Message Date
ba42ef6f37 Plugging friend sound 2023-06-04 19:02:44 +02:00
b559edcd10 Use twitter-api-v2 instead of twit 2023-06-04 19:02:30 +02:00
5 changed files with 71 additions and 89 deletions

View file

@ -1,6 +1,6 @@
import { SlashCommandBuilder } from 'discord.js';
import { EmbedBuilder } from 'discord.js';
import Twit from 'twit';
import { TwitterApi } from 'twitter-api-v2';
import fetch from 'node-fetch';
import os from 'node:os';
import fs from 'node:fs';
@ -114,11 +114,11 @@ export default {
}
const T = new Twit({
consumer_key: twiConsumer,
consumer_secret: twiConsumerSecret,
access_token: twiToken,
access_token_secret: twiTokenSecret,
const userClient = new TwitterApi({
appKey: twiConsumer,
appSecret: twiConsumerSecret,
accessToken: twiToken,
accessSecret: twiTokenSecret,
});
try {
@ -140,7 +140,9 @@ export default {
return interaction.editReply({ content: 'Gifs can\'t be larger than 15 MB!' });
}
const b64Image = fs.readFileSync(`${os.tmpdir()}/${attachment.name}`, { encoding: 'base64' });
const image = await userClient.v1.uploadMedia(`${os.tmpdir()}/${attachment.name}`);
Tweet(image);
/*
T.post('media/upload', { media_data: b64Image }, function(err, data) {
if (err) {
console.log('OH NO AN ERROR!!!!!!!');
@ -151,6 +153,7 @@ export default {
Tweet(data);
}
});
*/
}
else {
await interaction.editReply({ content: 'File type not supported, you can only send jpg/png/gif' });
@ -167,74 +170,51 @@ export default {
return;
}
function Tweet(data) {
let options = {
status: tweet,
};
if (data && tweet) {
options = {
status: tweet,
media_ids: new Array(data.media_id_string),
};
async function Tweet(img) {
console.log(img);
let options = null;
if (img) {
options = { media: { media_ids: new Array(img) } };
}
else if (data) {
options = {
media_ids: new Array(data.media_id_string),
};
const tweeted = await userClient.v2.tweet(tweet, options);
console.log(tweeted);
const tweetid = tweeted.data.id;
const FunnyWords = ['oppaGangnamStyle', '69', '420', 'cum', 'funnyMan', 'GUCCISmartToilet', 'TwitterForClowns', 'fart', 'ok', 'hi', 'howAreYou', 'WhatsNinePlusTen', '21'];
const TweetLink = `https://twitter.com/${FunnyWords[Math.floor((Math.random() * FunnyWords.length))]}/status/${tweetid}`;
let channel = await client.channels.resolve(twiChannel);
channel.send(TweetLink);
const Embed = new EmbedBuilder()
.setAuthor({ name: interaction.user.username, iconURL: interaction.user.displayAvatarURL() })
.setDescription(tweet ? tweet : 'No content.')
.addFields(
{ name: 'Link', value: TweetLink, inline: true },
{ name: 'Tweet ID', value: tweetid, inline: true },
{ name: 'Channel ID', value: interaction.channel.id, inline: true },
{ name: 'Message ID', value: interaction.id, inline: true },
{ name: 'Author', value: `${interaction.user.username} (${interaction.user.id})`, inline: true },
)
.setTimestamp();
if (interaction.guild) {
Embed.addFields(
{ name: 'Guild', value: `${interaction.guild.name} (${interaction.guild.id})`, inline: true },
{ name: 'message link', value: `https://discord.com/channels/${interaction.guild.id}/${interaction.channel.id}/${interaction.id}`, inline: true },
);
}
else {
Embed.addFields({ name: 'message link', value: `https://discord.com/channels/@me/${interaction.channel.id}/${interaction.id}` });
}
T.post('statuses/update', options, function(err, response) {
if (err) {
// Rate limit exceeded
if (err.code == 88) return interaction.editReply({ content: err.interaction });
// Tweet needs to be a bit shorter.
if (err.code == 186) return interaction.editReply({ content: `${err.interaction} Your interaction was ${tweet.length} characters, you need to remove ${tweet.length - 280} characters (This count may be inaccurate if your interaction contained link)` });
// Status is a duplicate.
if (err.code == 187) return interaction.editReply({ content: err.interaction });
// To protect our users from spam and other malicious activity, this account is temporarily locked.
if (err.code == 326) return interaction.editReply({ content: err.interaction });
console.error('OH NO!!!!');
console.error(err);
return interaction.editReply({ content: 'OH NO!!! AN ERROR HAS occurred!!! please hold on while i find what\'s causing this issue!' });
}
if (attachment) Embed.setImage(attachment.url);
const tweetid = response.id_str;
const FunnyWords = ['oppaGangnamStyle', '69', '420', 'cum', 'funnyMan', 'GUCCISmartToilet', 'TwitterForClowns', 'fart', 'ok', 'hi', 'howAreYou', 'WhatsNinePlusTen', '21'];
const TweetLink = `https://twitter.com/${FunnyWords[Math.floor((Math.random() * FunnyWords.length))]}/status/${tweetid}`;
// Im too lazy for now to make an entry in config.json
let channel = client.channels.resolve(twiChannel);
channel.send(TweetLink);
const Embed = new EmbedBuilder()
.setAuthor({ name: interaction.user.username, iconURL: interaction.user.displayAvatarURL() })
.setDescription(tweet ? tweet : 'No content.')
.addFields(
{ name: 'Link', value: TweetLink, inline: true },
{ name: 'Tweet ID', value: tweetid, inline: true },
{ name: 'Channel ID', value: interaction.channel.id, inline: true },
{ name: 'Message ID', value: interaction.id, inline: true },
{ name: 'Author', value: `${interaction.user.username} (${interaction.user.id})`, inline: true },
)
.setTimestamp();
if (interaction.guild) {
Embed.addFields(
{ name: 'Guild', value: `${interaction.guild.name} (${interaction.guild.id})`, inline: true },
{ name: 'message link', value: `https://discord.com/channels/${interaction.guild.id}/${interaction.channel.id}/${interaction.id}`, inline: true },
);
}
else {
Embed.addFields({ name: 'message link', value: `https://discord.com/channels/@me/${interaction.channel.id}/${interaction.id}` });
}
if (attachment) Embed.setImage(attachment.url);
channel = client.channels.resolve(twiLogChannel);
channel.send({ embeds: [Embed] });
return interaction.editReply({ content: `Go see ur epic tweet ${TweetLink}` });
});
channel = await client.channels.resolve(twiLogChannel);
channel.send({ embeds: [Embed] });
return interaction.editReply({ content: `Go see ur epic tweet ${TweetLink}` });
}
},
};

View file

@ -1,5 +1,6 @@
import { ActivityType } from 'discord.js';
import game from '../../json/playing.json' assert {type: 'json'};
import music from '../../json/listening.json' assert {type: 'json'};
import watch from '../../json/watching.json' assert {type: 'json'};
export default {
@ -14,7 +15,7 @@ export default {
}, 1800000);
async function setStatus() {
const random = Math.floor((Math.random() * 2));
const random = Math.floor((Math.random() * 3));
let types, status;
// Random "Watching" status taken from json
if (random === 0) {
@ -35,6 +36,15 @@ export default {
console.log(`Setting status to: ${status}`);
types = [ ActivityType.Playing, ActivityType.Competing ];
}
else if (random === 2) {
console.log('Status type: \x1b[32mPlaying\x1b[0m');
status = music[Math.floor((Math.random() * music.length))];
status = status + ' | Now with slash commands!';
console.log(`Setting status to: ${status}`);
types = [ ActivityType.Listening ];
}
await client.user.setActivity(status, { type: types[Math.floor((Math.random() * types.length))] });
}
},

3
json/listening.json Normal file
View file

@ -0,0 +1,3 @@
[
"psychometricBussdown by oddballTheatre"
]

21
package-lock.json generated
View file

@ -19,7 +19,7 @@
"safe-regex": "github:davisjam/safe-regex",
"sequelize": "^6.21.3",
"turndown": "^7.1.1",
"twit": "^1.1.20",
"twitter-api-v2": "^1.15.0",
"ytpplus-node": "github:Supositware/ytpplus-node"
},
"devDependencies": {
@ -5159,11 +5159,6 @@
"set-blocking": "^2.0.0"
}
},
"node_modules/oauth": {
"version": "0.9.9",
"resolved": "https://registry.npmjs.org/oauth/-/oauth-0.9.9.tgz",
"integrity": "sha512-kjdfbdtIFcfvHTdvh+pbR5RMOxrihCmMtDjOCAieetr4NoUOuRjl1q9gyGnvpPNDOalH8moHqur150XYGPQFeA=="
},
"node_modules/object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
@ -6822,16 +6817,10 @@
"domino": "^2.1.6"
}
},
"node_modules/twit": {
"version": "1.1.20",
"resolved": "https://registry.npmjs.org/twit/-/twit-1.1.20.tgz",
"integrity": "sha512-5Wb4b+1mqSxOXGrTe5O4GIB6/IQnh5anAub34M+VfAdA1g+9QfUuod4C94xf9NNcaz+rNZ/3LRUSTpn8wLMnYA==",
"dependencies": {
"oauth": "0.9.9"
},
"engines": {
"node": ">=0.6.0"
}
"node_modules/twitter-api-v2": {
"version": "1.15.0",
"resolved": "https://registry.npmjs.org/twitter-api-v2/-/twitter-api-v2-1.15.0.tgz",
"integrity": "sha512-Cqg3pIGhSwPyFBndpBrucdeNXecNFnYcXy3ixQ4brJHd/3k1CAtBVcX0e3s6jRYl/QIx5BmyGXS/SHEGtYZ3gw=="
},
"node_modules/type": {
"version": "1.2.0",

View file

@ -27,7 +27,7 @@
"safe-regex": "github:davisjam/safe-regex",
"sequelize": "^6.21.3",
"turndown": "^7.1.1",
"twit": "^1.1.20",
"twitter-api-v2": "^1.15.0",
"ytpplus-node": "github:Supositware/ytpplus-node"
},
"devDependencies": {