Remove clutter
This commit is contained in:
11
src/index.ts
11
src/index.ts
@@ -28,16 +28,17 @@ async function loop(args:envVars) {
|
||||
throw new Error('Cannot get initial details: '+(e.msg||e.message||e.code||'General Error'));
|
||||
}
|
||||
const selfName = await getName(name);
|
||||
console.info(`NAME:${selfName}`);
|
||||
console.info(`Name: ${selfName}`);
|
||||
|
||||
let lastUpdate = 0;
|
||||
|
||||
const timeout = 50;
|
||||
try {
|
||||
while (true) {
|
||||
//basically, check every second at max
|
||||
let x = delay(1000);
|
||||
|
||||
//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;
|
||||
}
|
||||
}catch(e){
|
||||
@@ -57,10 +58,12 @@ async function main(args:teleargs) {
|
||||
const body = actions.body as unknown as getUpdateBody;
|
||||
assert(body.ok);
|
||||
assert(body.result instanceof Array);
|
||||
|
||||
//Do something
|
||||
|
||||
console.debug(body.result);
|
||||
|
||||
|
||||
//assert(actions.body.ok);
|
||||
// const update_id = actions.body.
|
||||
// return the update number
|
||||
const getMaxMsgUpdateID:number = body.result.reduce((acc,curr)=>{
|
||||
|
||||
@@ -4,7 +4,8 @@ export interface teleargs{
|
||||
name:string,
|
||||
token:string,
|
||||
requestURL:string,
|
||||
lastUpdate:number
|
||||
lastUpdate:number,
|
||||
timeout:number
|
||||
}
|
||||
export interface envVars{
|
||||
token:string,
|
||||
|
||||
@@ -2,7 +2,6 @@ import { assert } from "console";
|
||||
|
||||
export default async function getName(name:string){
|
||||
const nameSplit = name.split(/\s+/);
|
||||
console.debug(nameSplit);
|
||||
assert(nameSplit.length>0);
|
||||
if(nameSplit.length===1){
|
||||
return name;
|
||||
|
||||
@@ -2,9 +2,12 @@ import assert from 'assert';
|
||||
import got from 'got';
|
||||
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) {
|
||||
const timeout = 50;
|
||||
console.log("Timeout",timeout);
|
||||
const {timeout} = args;
|
||||
return got(args.requestURL + '/getUpdates', {
|
||||
responseType: 'json' ,
|
||||
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> {
|
||||
const response = await got(requestURL + "/getMe", { responseType: 'json' });
|
||||
const body = response.body as unknown as initBody;
|
||||
|
||||
Reference in New Issue
Block a user