Skip to content

Commit

Permalink
📝 can now tweet on x
Browse files Browse the repository at this point in the history
  • Loading branch information
Vivien Mouret committed May 27, 2024
1 parent 33f9874 commit 133752a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
12 changes: 6 additions & 6 deletions core/daftbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ class DaftBot {
if (fe == undefined) { continue; };

let fetched = await fe.text(),
published = fetched.split(new RegExp(`(\>[^.]*?\/)`, 'giu'))[37];
published = fetched.split(new RegExp(`(\>[^.]*?\/)`, 'giu'))[37];

if (published == undefined) { continue; };
let sliced = published.slice(15, -2), // slice fail some time ??
pubDate = new Date(sliced);
Expand Down Expand Up @@ -561,11 +561,11 @@ class DaftBot {
};

var reChan = '1068557736306024519',
reMsg = ['1077008507724890122', '1077008635865088110'],
messageIdReg = react.message.id,
messageReg = channel.messages.cache.get(messageIdReg);
reMsg = ['1077008507724890122', '1077008635865088110'],
messageIdReg = react.message.id,
messageReg = channel.messages.cache.get(messageIdReg);

if (messageReg.channelId == reChan && reMsg.includes(message.id)) {
if (messageReg.channelId == reChan && reMsg.includes(message.id)) {
await this.switchRoles(this.dbClient, guild, user.id, 2, false);
console.log(`[${getCurrentDatetime('comm')}] ${guild.name} / ${channel.name} # ${user.username} no longer accepts the reglement`);
};
Expand Down
27 changes: 24 additions & 3 deletions core/mobbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const { Client } = require('tmi.js'),
path = require('node:path'),
WebSocketClient = require('websocket').client,
webSocket = new WebSocketClient(),
{ clientId, identity, channels } = require('./config.json'),
{ TwitterApi } = require('twitter-api-v2'),
{ clientId, identity, channels, x } = require('./config.json'),
{ randomIntFromInterval, getCurrentDatetime, randomColor } = require('./utils.js'),
{ users: regular_users } = require('../resx/regular_users.json');

Expand All @@ -30,6 +31,13 @@ const params = {
'Client-ID': clientId
}
};
const xApi = new TwitterApi({
appKey: x.api_key,
appSecret: x.api_secret,
accessToken: x.atas,
accessSecret: x.atas_secret,
bearerToken: x.bearer
});

var dataToExport = [];

Expand Down Expand Up @@ -200,7 +208,7 @@ class MobBot {

this.mbClient.reply(channel, regulars_msg[randomIntFromInterval(0, regulars_msg.length - 1)], userstate.id)
.catch(e => console.log(e));

this._count++;
};

Expand Down Expand Up @@ -346,6 +354,19 @@ class MobBot {
console.log(`[${getCurrentDatetime('comm')}] LIVENOTIFRROR Can't get guid and dot : `, err);
};

// const mediaIds = await Promise.all([
// xApi.v1.uploadMedia('./styles/ai/pepe-diffuser.jpg')
// ]);

const rwClient = xApi.readWrite;
await rwClient.v2.tweet({
text: `${axios.data.data[0].title}\
\n
\n#${axios.data.data[0].game_name}
\n\nhttps://twitch.tv/${axios.data.data[0].user_name}`,
// media: { media_ids: mediaIds }
});

for (let chan in channelTwitch) {
var channelSend = client.channels.cache.find(channel => channel.name == channelTwitch[chan]);
if (channelSend == undefined) break;
Expand Down Expand Up @@ -464,7 +485,7 @@ class MobBot {
let fe = await fetch(`https://www.youtube.com/feeds/videos.xml?channel_id=UCreItrEewfO6IPZYPu4C7pA`)
.catch(err => { console.log(`[${getCurrentDatetime('comm')}] Error FETCH ${err}`); }),
fetched = await fe.text();
return String(fetched.split(new RegExp(`(\:[^.]*\<\/)`, 'giu'))[3].split(new RegExp(`(\<[^.]*?\>)`, 'giu'))[10]);
return String(fetched.split(new RegExp(`(\:[^.]*\<\/)`, 'giu'))[3].split(new RegExp(`(\<[^.]*?\>)`, 'giu'))[10]); // split doesn't work simetimes ?
};

async onTimeStamp() {
Expand Down

0 comments on commit 133752a

Please sign in to comment.