Compare commits
No commits in common. "0acef577a33930aa06fabf5bc8705505adfbdbdb" and "83da290741df4ac03b478ca850036cd4833c5629" have entirely different histories.
0acef577a3
...
83da290741
33
index.js
33
index.js
@ -1,30 +1,15 @@
|
|||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
import { TelegramClient, Api as TgApi } from 'telegram';
|
import { TelegramClient, Api as TgApi } from 'telegram';
|
||||||
import { StringSession } from 'telegram/sessions/index.js';
|
import { StoreSession } from 'telegram/sessions/index.js';
|
||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
import prompt from 'prompt';
|
import prompt from 'prompt';
|
||||||
import fs from 'fs/promises';
|
|
||||||
import path from 'path';
|
|
||||||
import { fileURLToPath } from 'url';
|
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
|
||||||
const __dirname = path.dirname(__filename);
|
|
||||||
|
|
||||||
const apiId = parseInt(process.env.API_ID);
|
const apiId = parseInt(process.env.API_ID);
|
||||||
const apiHash = process.env.API_HASH;
|
const apiHash = process.env.API_HASH;
|
||||||
const songPrefix = process.env.SONG_PREFIX || "";
|
const songPrefix = process.env.SONG_PREFIX || "";
|
||||||
|
|
||||||
const sessionFile = path.join(__dirname, 'tg_session', 'session');
|
console.log(process.env);
|
||||||
|
const sessionStore = new StoreSession("tg_session");
|
||||||
let sessionStore = new StringSession("");
|
|
||||||
try {
|
|
||||||
const readSession = await fs.readFile(sessionFile, "utf8");
|
|
||||||
if (readSession) {
|
|
||||||
sessionStore = new StringSession(readSession);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.error(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getCurrentSong() {
|
async function getCurrentSong() {
|
||||||
return fetch('https://multi-scrobbler.riksolo.com/api/status').then((data) => {
|
return fetch('https://multi-scrobbler.riksolo.com/api/status').then((data) => {
|
||||||
@ -50,8 +35,7 @@ async function getCurrentSong() {
|
|||||||
|
|
||||||
// if a player exists, get it's song
|
// if a player exists, get it's song
|
||||||
if (sortedPlayers.length !== 0) {
|
if (sortedPlayers.length !== 0) {
|
||||||
const playData = sortedPlayers[0]?.play?.data;
|
const playData = sortedPlayers[0].play.data;
|
||||||
if (!playData) return "";
|
|
||||||
nowPlaying = `${playData.artists.join(', ')} - ${playData.track}`;
|
nowPlaying = `${playData.artists.join(', ')} - ${playData.track}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -88,18 +72,21 @@ async function initTelegram() {
|
|||||||
onError: (err) => console.error(err)
|
onError: (err) => console.error(err)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// save the session so we don't have to log in every time
|
// save the session so we don't have to log in every time
|
||||||
client.session.save();
|
client.session.save();
|
||||||
|
|
||||||
await fs.writeFile(sessionFile, sessionStore.save());
|
|
||||||
|
|
||||||
return client;
|
return client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
prompt.start();
|
||||||
|
|
||||||
|
|
||||||
// store client here
|
// store client here
|
||||||
const tg = await initTelegram();
|
const tg = await initTelegram();
|
||||||
|
|
||||||
|
|
||||||
// do we actually have a client?
|
// do we actually have a client?
|
||||||
if (!!tg) {
|
if (!!tg) {
|
||||||
let song = "";
|
let song = "";
|
||||||
@ -112,8 +99,6 @@ if (!!tg) {
|
|||||||
|
|
||||||
console.log(`new song: ${song}`);
|
console.log(`new song: ${song}`);
|
||||||
|
|
||||||
const ytURL = await getYoutube(song);
|
|
||||||
|
|
||||||
// update bio with new song
|
// update bio with new song
|
||||||
tg.invoke(new TgApi.account.UpdateProfile({
|
tg.invoke(new TgApi.account.UpdateProfile({
|
||||||
about: songPrefix + song
|
about: songPrefix + song
|
||||||
|
Loading…
Reference in New Issue
Block a user