Remove clutter

This commit is contained in:
2020-06-14 18:45:04 +05:30
parent 1451a4c5bd
commit d6212fac59
6 changed files with 25 additions and 14 deletions

3
.gitignore vendored
View File

@@ -1,4 +1,5 @@
start.sh
test.sh
out/ out/
api-token.json api-token.json
# Logs # Logs

View File

@@ -28,16 +28,17 @@ async function loop(args:envVars) {
throw new Error('Cannot get initial details: '+(e.msg||e.message||e.code||'General Error')); throw new Error('Cannot get initial details: '+(e.msg||e.message||e.code||'General Error'));
} }
const selfName = await getName(name); const selfName = await getName(name);
console.info(`NAME:${selfName}`); console.info(`Name: ${selfName}`);
let lastUpdate = 0; let lastUpdate = 0;
const timeout = 50;
try { try {
while (true) { while (true) {
//basically, check every second at max //basically, check every second at max
let x = delay(1000); let x = delay(1000);
//while we await, we can do other stuff //while we await, we can do other stuff
lastUpdate = await main({name:selfName,token,requestURL,lastUpdate}); lastUpdate = await main({name:selfName,token,requestURL,lastUpdate,timeout});
await x; await x;
} }
}catch(e){ }catch(e){
@@ -57,10 +58,12 @@ async function main(args:teleargs) {
const body = actions.body as unknown as getUpdateBody; const body = actions.body as unknown as getUpdateBody;
assert(body.ok); assert(body.ok);
assert(body.result instanceof Array); assert(body.result instanceof Array);
//Do something
console.debug(body.result); console.debug(body.result);
//assert(actions.body.ok);
// const update_id = actions.body. // const update_id = actions.body.
// return the update number // return the update number
const getMaxMsgUpdateID:number = body.result.reduce((acc,curr)=>{ const getMaxMsgUpdateID:number = body.result.reduce((acc,curr)=>{

View File

@@ -4,7 +4,8 @@ export interface teleargs{
name:string, name:string,
token:string, token:string,
requestURL:string, requestURL:string,
lastUpdate:number lastUpdate:number,
timeout:number
} }
export interface envVars{ export interface envVars{
token:string, token:string,

View File

@@ -2,7 +2,6 @@ import { assert } from "console";
export default async function getName(name:string){ export default async function getName(name:string){
const nameSplit = name.split(/\s+/); const nameSplit = name.split(/\s+/);
console.debug(nameSplit);
assert(nameSplit.length>0); assert(nameSplit.length>0);
if(nameSplit.length===1){ if(nameSplit.length===1){
return name; return name;

View File

@@ -2,9 +2,12 @@ import assert from 'assert';
import got from 'got'; import got from 'got';
import { teleargs, initBody } from '../misc/defs'; import { teleargs, initBody } from '../misc/defs';
/**
* Use the lastUpdate to fetch updates, based on the timeout
* @param args Config arguments
*/
export async function getMessage(args: teleargs) { export async function getMessage(args: teleargs) {
const timeout = 50; const {timeout} = args;
console.log("Timeout",timeout);
return got(args.requestURL + '/getUpdates', { return got(args.requestURL + '/getUpdates', {
responseType: 'json' , responseType: 'json' ,
searchParams: { searchParams: {
@@ -14,6 +17,10 @@ export async function getMessage(args: teleargs) {
}); });
} }
/**
* Get the about page for the bot and run some assertions, returning the name
* @param requestURL request URL for the bot
*/
export async function getInit(requestURL: string): Promise<string> { export async function getInit(requestURL: string): Promise<string> {
const response = await got(requestURL + "/getMe", { responseType: 'json' }); const response = await got(requestURL + "/getMe", { responseType: 'json' });
const body = response.body as unknown as initBody; const body = response.body as unknown as initBody;

View File

@@ -172,12 +172,12 @@
"affectsGlobalScope": false "affectsGlobalScope": false
}, },
"./src/misc/defs.ts": { "./src/misc/defs.ts": {
"version": "9ad55bdafc44ffa2fddff87ca5d73e30bea45b488b4e0a919c9451216314ca89", "version": "2e683b112029ff633341c735e68b85f53b81a43aff2bd403d670f305679e2299",
"signature": "4f3f3fa6f98ebd8edbde568924f43d46dc8543d15985c21f1b6bb559e1e87aa1", "signature": "942df93292b36560f22acbbd704337c37892d9146406e42f67378c5bf5964aa6",
"affectsGlobalScope": false "affectsGlobalScope": false
}, },
"./src/misc/getName.ts": { "./src/misc/getName.ts": {
"version": "6781ba5ea24a074465d581b1eac877340cfd5dde6ec0549ce361a03d67b96076", "version": "93f3d2f4dbe03ce53f042782e9dfe5c481b7546564de33dd3514923afc17e806",
"signature": "b791a0a7b15ce7d3dcda9ab7413064c319b6715cdf4b6077bc4259889a2d89d0", "signature": "b791a0a7b15ce7d3dcda9ab7413064c319b6715cdf4b6077bc4259889a2d89d0",
"affectsGlobalScope": false "affectsGlobalScope": false
}, },
@@ -522,12 +522,12 @@
"affectsGlobalScope": false "affectsGlobalScope": false
}, },
"./src/tg/getWrapper.ts": { "./src/tg/getWrapper.ts": {
"version": "1dfb416a546b6255674ae57cbed3518fb0858a2c9ba444f7c52ad0e6153c50fe", "version": "7dea84e01a4fd33b140bc21b28a7cd5730f1c1ef8898fd113e2879ac528a12a4",
"signature": "f441d45667d0c06a19f51eca34a3a16bc6d844cb653731683c5937b0f645601f", "signature": "f441d45667d0c06a19f51eca34a3a16bc6d844cb653731683c5937b0f645601f",
"affectsGlobalScope": false "affectsGlobalScope": false
}, },
"./src/index.ts": { "./src/index.ts": {
"version": "392953e0e221acdfbd58512760ad64b6955af1ddb7bea06955df5d904bb691cf", "version": "65da7d42deb33bc2aa9698c416e8291dc70a100bed35729291470e2f03d6a833",
"signature": "f667f6b1d66ba55f0dcd27f5ff050063fecfe289bad00e8c5d48344a775c1439", "signature": "f667f6b1d66ba55f0dcd27f5ff050063fecfe289bad00e8c5d48344a775c1439",
"affectsGlobalScope": false "affectsGlobalScope": false
}, },