Skip to content

Commit

Permalink
title: fix issue of title data being shared across bot objects
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharthvp committed Oct 30, 2020
1 parent 0487cd6 commit 1e700bf
Show file tree
Hide file tree
Showing 5 changed files with 1,259 additions and 1,254 deletions.
96 changes: 48 additions & 48 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
{
"name": "mwn",
"version": "0.7.1",
"description": "MediaWiki bot framework for Node.js",
"main": "./src/bot.js",
"scripts": {
"bump": "node bump-version.js",
"test": "nyc --reporter=lcov --reporter=text mocha tests/",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},
"repository": {
"type": "git",
"url": "https://github.com/siddharthvp/mwn"
},
"keywords": [
"wikipedia-bot"
],
"author": "Siddharth VP",
"license": "GPL-3.0-or-later",
"bugs": {
"url": "https://github.com/siddharthvp/mwn/issues"
},
"homepage": "https://github.com/siddharthvp/mwn#readme",
"files": [
"src/"
],
"dependencies": {
"axios": "^0.19.2",
"axios-cookiejar-support": "^1.0.0",
"eventsource": "^1.0.7",
"form-data": "^3.0.0",
"oauth-1.0a": "^2.2.6",
"semlog": "^0.6.10",
"tough-cookie": "^4.0.0"
},
"devDependencies": {
"@types/node": "^14.11.10",
"chai": "^4.2.0",
"coveralls": "^3.1.0",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"mocha": "^7.1.1",
"nyc": "^15.1.0"
}
}
"name": "mwn",
"version": "0.7.2",
"description": "MediaWiki bot framework for Node.js",
"main": "./src/bot.js",
"scripts": {
"bump": "node bump-version.js",
"test": "nyc --reporter=lcov --reporter=text mocha tests/",
"coverage": "nyc report --reporter=text-lcov | coveralls"
},
"repository": {
"type": "git",
"url": "https://github.com/siddharthvp/mwn"
},
"keywords": [
"wikipedia-bot"
],
"author": "Siddharth VP",
"license": "GPL-3.0-or-later",
"bugs": {
"url": "https://github.com/siddharthvp/mwn/issues"
},
"homepage": "https://github.com/siddharthvp/mwn#readme",
"files": [
"src/"
],
"dependencies": {
"axios": "^0.19.2",
"axios-cookiejar-support": "^1.0.0",
"eventsource": "^1.0.7",
"form-data": "^3.0.0",
"oauth-1.0a": "^2.2.6",
"semlog": "^0.6.10",
"tough-cookie": "^4.0.0"
},
"devDependencies": {
"@types/node": "^14.11.10",
"chai": "^4.2.0",
"coveralls": "^3.1.0",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.1",
"eslint-plugin-import": "^2.20.2",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"mocha": "^7.1.1",
"nyc": "^15.1.0"
}
}
12 changes: 6 additions & 6 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class mwn {
/**
* Title class associated with the bot instance
*/
this.title = Title;
this.title = Title(this);

/**
* Date class
Expand Down Expand Up @@ -710,7 +710,7 @@ class mwn {
}
this.state = merge(this.state, response.query.tokens);

Title.processNamespaceData(response);
this.title.processNamespaceData(response);

return this.request({
action: 'login',
Expand Down Expand Up @@ -774,7 +774,7 @@ class mwn {
meta: 'siteinfo',
siprop: 'general|namespaces|namespacealiases'
}).then(result => {
Title.processNamespaceData(result);
this.title.processNamespaceData(result);
});
}

Expand Down Expand Up @@ -824,7 +824,7 @@ class mwn {
siprop: 'general|namespaces|namespacealiases',
type: 'csrf|createaccount|login|patrol|rollback|userrights|watch'
}).then(response => {
Title.processNamespaceData(response);
this.title.processNamespaceData(response);
if (response.query && response.query.tokens) {
this.csrfToken = response.query.tokens.csrftoken;
this.state = merge(this.state, response.query.tokens);
Expand Down Expand Up @@ -1402,7 +1402,7 @@ class mwn {
* @returns {Promise<string[]>} - array of page titles (upto 5000 or 500)
*/
getPagesByPrefix(prefix, otherParams) {
const title = Title.newFromText(prefix);
const title = this.title.newFromText(prefix);
if (!title) {
throw new Error('invalid prefix for getPagesByPrefix');
}
Expand All @@ -1424,7 +1424,7 @@ class mwn {
* @returns {Promise<string[]>}
*/
getPagesInCategory(category, otherParams) {
const title = Title.newFromText(category, 14);
const title = this.title.newFromText(category, 14);
return this.request(merge({
"action": "query",
"list": "categorymembers",
Expand Down
2 changes: 1 addition & 1 deletion src/eventstream.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = function (mwn, bot) {
let since = config.since ? `?since=${new bot.date(config.since).format('YYYYMMDDHHmmss')}` : '';
super(`https://stream.wikimedia.org/v2/stream/${streams}${since}`, {
headers: {
'User-Agent': bot.userAgent
'User-Agent': bot.options.userAgent
}
});

Expand Down
Loading

0 comments on commit 1e700bf

Please sign in to comment.