new(all): Twitter API.
This commit is contained in:
parent
6a1e454afd
commit
2cd56801c3
4 changed files with 53 additions and 2 deletions
23
package-lock.json
generated
23
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "botserver",
|
||||
"version": "2.0.173",
|
||||
"version": "2.0.175",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
@ -25546,6 +25546,27 @@
|
|||
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
|
||||
"integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q="
|
||||
},
|
||||
"twitter": {
|
||||
"version": "1.7.1",
|
||||
"resolved": "https://registry.npmjs.org/twitter/-/twitter-1.7.1.tgz",
|
||||
"integrity": "sha512-Do7l/WzFnUZC14ABtZfDiOHKl6M9Ft5tE4YF0ev9XLm4yh7m8R98D82rzeDAMjbjMZk2R/tb6sgXXb3sPKoaVw==",
|
||||
"requires": {
|
||||
"deep-extend": "^0.5.0",
|
||||
"request": "^2.72.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"deep-extend": {
|
||||
"version": "0.5.1",
|
||||
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.5.1.tgz",
|
||||
"integrity": "sha512-N8vBdOa+DF7zkRrDCsaOXoCs/E2fJfx9B9MrKnnSiHNh4ws7eSys6YQE4KvT1cecKmOASYQBhbKjeuDD9lT81w=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"twitter-api-v2": {
|
||||
"version": "1.12.7",
|
||||
"resolved": "https://registry.npmjs.org/twitter-api-v2/-/twitter-api-v2-1.12.7.tgz",
|
||||
"integrity": "sha512-kz0/algmi49xejjrKoEJEpXCa1Y0d2MHHhjJZS55ORcqzs8RHxvLO1oWeJNvFz/o+FQW+sFCpmM/5DyYy+QBXw=="
|
||||
},
|
||||
"type": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/type/-/type-1.2.0.tgz",
|
||||
|
|
|
@ -139,6 +139,7 @@
|
|||
"tabulator-tables": "^5.2.6",
|
||||
"tedious": "14.0.0",
|
||||
"textract": "2.5.0",
|
||||
"twitter-api-v2": "1.12.7",
|
||||
"typescript": "3.6.4",
|
||||
"url-join": "4.0.1",
|
||||
"vbscript-to-typescript": "1.0.8",
|
||||
|
|
|
@ -52,7 +52,7 @@ const walkPromise = require('walk-promise');
|
|||
const Path = require('path');
|
||||
/**
|
||||
* @fileoverview Virtualization services for emulation of BASIC.
|
||||
* This alpha version is using a hack in form of converter to
|
||||
* This alpha version is using a antipattern hack in form of converter to
|
||||
* translate BASIC to TS and string replacements to emulate await code.
|
||||
* See https://github.com/uweg/vbscript-to-typescript for more info on vb2ts, so
|
||||
* http://stevehanov.ca/blog/index.php?id=92 should be used to run it without
|
||||
|
@ -518,6 +518,10 @@ export class GBVMService extends GBService {
|
|||
return `screenshot(step, ${$1})\n`;
|
||||
});
|
||||
|
||||
code = code.replace(/TWEET\s(.*)/gi, ($0, $1, $2) => {
|
||||
return `sys().tweet(step, ${$1})\n`;
|
||||
});
|
||||
|
||||
code = code.replace(/(\w+)\s*\=\s*(.*)\s*as image/gi, ($0, $1, $2) => {
|
||||
return `${$1} = sys().asImage(${$2})\n`;
|
||||
});
|
||||
|
|
|
@ -48,6 +48,7 @@ const urlJoin = require('url-join');
|
|||
const url = require('url');
|
||||
const puppeteer = require('puppeteer')
|
||||
const pluginStealth = require('puppeteer-extra-plugin-stealth');
|
||||
const { TwitterApi } = require('twitter-api-v2');
|
||||
|
||||
|
||||
const Path = require('path');
|
||||
|
@ -1682,4 +1683,28 @@ export class SystemKeywords {
|
|||
return table;
|
||||
}
|
||||
}
|
||||
|
||||
public async tweet(step, text: string) {
|
||||
|
||||
const consumer_key = this.min.core.getParam(this.min.instance, 'Twitter Consumer Key', null);
|
||||
const consumer_secret = this.min.core.getParam(this.min.instance, 'Twitter Consumer Key Secret', null);
|
||||
const access_token_key = this.min.core.getParam(this.min.instance, 'Twitter Access Token', null);
|
||||
const access_token_secret = this.min.core.getParam(this.min.instance, 'Twitter Access Token Secret', null);
|
||||
|
||||
if (!consumer_key || !consumer_secret || !access_token_key || !access_token_secret) {
|
||||
GBLog.info('Twitter not configured in .gbot.');
|
||||
}
|
||||
|
||||
const client = new TwitterApi({
|
||||
appKey: consumer_key,
|
||||
appSecret: consumer_secret,
|
||||
accessToken: access_token_key,
|
||||
accessSecret: access_token_secret
|
||||
});
|
||||
|
||||
await client.v2.tweet(text);
|
||||
GBLog.info(`Twitter Automation: ${text}.`);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue