begin setting up telegram side of things
This commit is contained in:
parent
73e2dfd793
commit
1e5d72a376
|
@ -1 +1,2 @@
|
||||||
node_modules
|
node_modules
|
||||||
|
.env
|
40
index.js
40
index.js
|
@ -1,6 +1,20 @@
|
||||||
import fetch from 'node-fetch';
|
import fetch from 'node-fetch';
|
||||||
|
import readline from "readline";
|
||||||
|
import { TelegramClient } from 'telegram';
|
||||||
|
import { StoreSession } from 'telegram/sessions/index.js';
|
||||||
|
import 'dotenv/config';
|
||||||
|
|
||||||
function getCurrentSong() {
|
const rl = readline.createInterface({
|
||||||
|
input: process.stdin,
|
||||||
|
output: process.stdout
|
||||||
|
});
|
||||||
|
|
||||||
|
const apiId = process.env.API_ID;
|
||||||
|
const apiHash = process.env.API_HASH;
|
||||||
|
|
||||||
|
const sessionStore = new StoreSession("tg_session");
|
||||||
|
|
||||||
|
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) => {
|
||||||
return data.json();
|
return data.json();
|
||||||
}).then(data => {
|
}).then(data => {
|
||||||
|
@ -20,7 +34,7 @@ function getCurrentSong() {
|
||||||
const sortedPlayers = players.sort((a, b) => new Date(a.playFirstSeenAt).getTime() - new Date(b.playFirstSeenAt).getTime());
|
const sortedPlayers = players.sort((a, b) => new Date(a.playFirstSeenAt).getTime() - new Date(b.playFirstSeenAt).getTime());
|
||||||
|
|
||||||
// default string
|
// default string
|
||||||
let nowPlaying = "Nothing Playing";
|
let nowPlaying = "";
|
||||||
|
|
||||||
// if a player exists, get it's song
|
// if a player exists, get it's song
|
||||||
if (sortedPlayers.length !== 0) {
|
if (sortedPlayers.length !== 0) {
|
||||||
|
@ -32,9 +46,21 @@ function getCurrentSong() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function initTelegram() {
|
||||||
|
if (!apiId) { console.error("missing env var API_ID"); return; };
|
||||||
|
if (!apiHash) { console.error("missing env var API_HASH"); return; };
|
||||||
|
const client = new TelegramClient(sessionStore, apiId, apiHash, {
|
||||||
|
connectionRetries: 5
|
||||||
|
});
|
||||||
|
|
||||||
setInterval(async () => {
|
await client.start({
|
||||||
process.stdout.cursorTo(0);
|
phoneNumber: async (res) => { rl.question("Phone number: ", res); },
|
||||||
process.stdout.clearLine(0);
|
password: async (res) => { rl.question("password: ", res); },
|
||||||
process.stdout.write(await getCurrentSong());
|
phoneCode: async (res) => { rl.question("code: ", res); },
|
||||||
}, 2000);
|
onError: (err) => console.error(err)
|
||||||
|
});
|
||||||
|
console.log(client.session.save());
|
||||||
|
await CloseEvent.sendMessage("me", { message: "hi" });
|
||||||
|
}
|
||||||
|
|
||||||
|
initTelegram();
|
|
@ -9,7 +9,9 @@
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"dotenv": "^16.4.7",
|
||||||
"node-fetch": "^3.3.2",
|
"node-fetch": "^3.3.2",
|
||||||
|
"readline": "^1.3.0",
|
||||||
"telegram": "^2.26.16"
|
"telegram": "^2.26.16"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -180,6 +182,17 @@
|
||||||
"url": "https://github.com/fb55/domutils?sponsor=1"
|
"url": "https://github.com/fb55/domutils?sponsor=1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/dotenv": {
|
||||||
|
"version": "16.4.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz",
|
||||||
|
"integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://dotenvx.com"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/entities": {
|
"node_modules/entities": {
|
||||||
"version": "2.2.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/entities/-/entities-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/entities/-/entities-2.2.0.tgz",
|
||||||
|
@ -473,6 +486,11 @@
|
||||||
"integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==",
|
"integrity": "sha512-b7uo2UCUOYZcnF/3ID0lulOJi/bafxa1xPe7ZPsammBSpjSWQkjNxlt635YGS2MiR9GjvuXCtz2emr3jbsz98g==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
"node_modules/readline": {
|
||||||
|
"version": "1.3.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/readline/-/readline-1.3.0.tgz",
|
||||||
|
"integrity": "sha512-k2d6ACCkiNYz222Fs/iNze30rRJ1iIicW7JuX/7/cozvih6YCkFZH+J6mAFDVgv0dRBaAyr4jDqC95R2y4IADg=="
|
||||||
|
},
|
||||||
"node_modules/real-cancellable-promise": {
|
"node_modules/real-cancellable-promise": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/real-cancellable-promise/-/real-cancellable-promise-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/real-cancellable-promise/-/real-cancellable-promise-1.2.0.tgz",
|
||||||
|
|
|
@ -10,7 +10,9 @@
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"description": "",
|
"description": "",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"dotenv": "^16.4.7",
|
||||||
"node-fetch": "^3.3.2",
|
"node-fetch": "^3.3.2",
|
||||||
|
"readline": "^1.3.0",
|
||||||
"telegram": "^2.26.16"
|
"telegram": "^2.26.16"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue