@ -1,6 +1,6 @@
import { SlashCommandBuilder } from 'discord.js' ;
import { SlashCommandBuilder } from 'discord.js' ;
import { EmbedBuilder } from 'discord.js' ;
import { EmbedBuilder } from 'discord.js' ;
import Twit from 'twit ';
import { Twit terApi } from 'twit ter-api-v2 ';
import fetch from 'node-fetch' ;
import fetch from 'node-fetch' ;
import os from 'node:os' ;
import os from 'node:os' ;
import fs from 'node:fs' ;
import fs from 'node:fs' ;
@ -114,11 +114,11 @@ export default {
}
}
const T = new Twit ( {
const userClient = new TwitterApi ( {
consumer_k ey: twiConsumer ,
appK ey: twiConsumer ,
consumer_s ecret: twiConsumerSecret ,
appS ecret: twiConsumerSecret ,
access _t oken: twiToken ,
access T oken: twiToken ,
access _token _s ecret: twiTokenSecret ,
access S ecret: twiTokenSecret ,
} ) ;
} ) ;
try {
try {
@ -140,7 +140,9 @@ export default {
return interaction . editReply ( { content : 'Gifs can\'t be larger than 15 MB!' } ) ;
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 ) {
T . post ( 'media/upload' , { media _data : b64Image } , function ( err , data ) {
if ( err ) {
if ( err ) {
console . log ( 'OH NO AN ERROR!!!!!!!' ) ;
console . log ( 'OH NO AN ERROR!!!!!!!' ) ;
@ -151,6 +153,7 @@ export default {
Tweet ( data ) ;
Tweet ( data ) ;
}
}
} ) ;
} ) ;
* /
}
}
else {
else {
await interaction . editReply ( { content : 'File type not supported, you can only send jpg/png/gif' } ) ;
await interaction . editReply ( { content : 'File type not supported, you can only send jpg/png/gif' } ) ;
@ -167,44 +170,22 @@ export default {
return ;
return ;
}
}
function Tweet ( data ) {
async function Tweet ( img ) {
let options = {
console . log ( img ) ;
status : tweet ,
let options = null ;
} ;
if ( img ) {
options = { media : { media _ids : new Array ( img ) } } ;
if ( data && tweet ) {
options = {
status : tweet ,
media _ids : new Array ( data . media _id _string ) ,
} ;
}
else if ( data ) {
options = {
media _ids : new Array ( data . media _id _string ) ,
} ;
}
}
const tweeted = await userClient . v2 . tweet ( tweet , options ) ;
console . log ( tweeted ) ;
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!' } ) ;
}
const tweetid = response . id _str ;
const tweetid = tweeted . data . id ;
const FunnyWords = [ 'oppaGangnamStyle' , '69' , '420' , 'cum' , 'funnyMan' , 'GUCCISmartToilet' , 'TwitterForClowns' , 'fart' , 'ok' , 'hi' , 'howAreYou' , 'WhatsNinePlusTen' , '21' ] ;
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 } ` ;
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 = await client . channels . resolve ( twiChannel ) ;
let channel = client . channels . resolve ( twiChannel ) ;
channel . send ( TweetLink ) ;
channel . send ( TweetLink ) ;
const Embed = new EmbedBuilder ( )
const Embed = new EmbedBuilder ( )
@ -231,10 +212,9 @@ export default {
if ( attachment ) Embed . setImage ( attachment . url ) ;
if ( attachment ) Embed . setImage ( attachment . url ) ;
channel = client . channels . resolve ( twiLogChannel ) ;
channel = await client . channels . resolve ( twiLogChannel ) ;
channel . send ( { embeds : [ Embed ] } ) ;
channel . send ( { embeds : [ Embed ] } ) ;
return interaction . editReply ( { content : ` Go see ur epic tweet ${ TweetLink } ` } ) ;
return interaction . editReply ( { content : ` Go see ur epic tweet ${ TweetLink } ` } ) ;
} ) ;
}
}
} ,
} ,
} ;
} ;