Remove clutter
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,4 +1,5 @@
|
||||
|
||||
start.sh
|
||||
test.sh
|
||||
out/
|
||||
api-token.json
|
||||
# Logs
|
||||
|
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;
|
||||
|
@@ -172,12 +172,12 @@
|
||||
"affectsGlobalScope": false
|
||||
},
|
||||
"./src/misc/defs.ts": {
|
||||
"version": "9ad55bdafc44ffa2fddff87ca5d73e30bea45b488b4e0a919c9451216314ca89",
|
||||
"signature": "4f3f3fa6f98ebd8edbde568924f43d46dc8543d15985c21f1b6bb559e1e87aa1",
|
||||
"version": "2e683b112029ff633341c735e68b85f53b81a43aff2bd403d670f305679e2299",
|
||||
"signature": "942df93292b36560f22acbbd704337c37892d9146406e42f67378c5bf5964aa6",
|
||||
"affectsGlobalScope": false
|
||||
},
|
||||
"./src/misc/getName.ts": {
|
||||
"version": "6781ba5ea24a074465d581b1eac877340cfd5dde6ec0549ce361a03d67b96076",
|
||||
"version": "93f3d2f4dbe03ce53f042782e9dfe5c481b7546564de33dd3514923afc17e806",
|
||||
"signature": "b791a0a7b15ce7d3dcda9ab7413064c319b6715cdf4b6077bc4259889a2d89d0",
|
||||
"affectsGlobalScope": false
|
||||
},
|
||||
@@ -522,12 +522,12 @@
|
||||
"affectsGlobalScope": false
|
||||
},
|
||||
"./src/tg/getWrapper.ts": {
|
||||
"version": "1dfb416a546b6255674ae57cbed3518fb0858a2c9ba444f7c52ad0e6153c50fe",
|
||||
"version": "7dea84e01a4fd33b140bc21b28a7cd5730f1c1ef8898fd113e2879ac528a12a4",
|
||||
"signature": "f441d45667d0c06a19f51eca34a3a16bc6d844cb653731683c5937b0f645601f",
|
||||
"affectsGlobalScope": false
|
||||
},
|
||||
"./src/index.ts": {
|
||||
"version": "392953e0e221acdfbd58512760ad64b6955af1ddb7bea06955df5d904bb691cf",
|
||||
"version": "65da7d42deb33bc2aa9698c416e8291dc70a100bed35729291470e2f03d6a833",
|
||||
"signature": "f667f6b1d66ba55f0dcd27f5ff050063fecfe289bad00e8c5d48344a775c1439",
|
||||
"affectsGlobalScope": false
|
||||
},
|
||||
|
Reference in New Issue
Block a user