cleanup. handle some potential undefined values
This commit is contained in:
parent
83da290741
commit
85128f389a
11
index.js
11
index.js
|
@ -8,7 +8,6 @@ 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 || "";
|
||||||
|
|
||||||
console.log(process.env);
|
|
||||||
const sessionStore = new StoreSession("tg_session");
|
const sessionStore = new StoreSession("tg_session");
|
||||||
|
|
||||||
async function getCurrentSong() {
|
async function getCurrentSong() {
|
||||||
|
@ -35,7 +34,8 @@ 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}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +72,6 @@ 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();
|
||||||
|
|
||||||
|
@ -80,13 +79,9 @@ async function initTelegram() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 = "";
|
||||||
|
@ -99,6 +94,8 @@ 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