diff --git a/build/bot.d.ts b/build/bot.d.ts index 994579b..cdbfbc7 100644 --- a/build/bot.d.ts +++ b/build/bot.d.ts @@ -300,6 +300,13 @@ export declare class mwn { * @returns {Promise} */ logout(): Promise; + /** + * Create an account. Only works on wikis without extensions like + * ConfirmEdit enabled (hence doesn't work on WMF wikis). + * @param username + * @param password + */ + createAccount(username: string, password: string): Promise; /** * Get basic info about the logged-in user * @param [options] diff --git a/build/bot.js b/build/bot.js index 76b2ad0..b806387 100644 --- a/build/bot.js +++ b/build/bot.js @@ -673,6 +673,33 @@ class mwn { this.csrfToken = '%notoken%'; }); } + /** + * Create an account. Only works on wikis without extensions like + * ConfirmEdit enabled (hence doesn't work on WMF wikis). + * @param username + * @param password + */ + async createAccount(username, password) { + if (!this.state.createaccounttoken) { // not logged in + await this.getTokens(); + } + return this.request({ + action: 'createaccount', + createreturnurl: 'https://example.com', + createtoken: this.state.createaccounttoken, + username: username, + password: password, + retype: password + }).then(json => { + let data = json.createaccount; + if (data.status === 'FAIL') { + return Promise.reject(data); + } + else { // status === 'PASS' or other value + return data; + } + }); + } /** * Get basic info about the logged-in user * @param [options] diff --git a/src/bot.ts b/src/bot.ts index 157bdba..8cdde29 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -883,6 +883,33 @@ export class mwn { }); } + /** + * Create an account. Only works on wikis without extensions like + * ConfirmEdit enabled (hence doesn't work on WMF wikis). + * @param username + * @param password + */ + async createAccount(username: string, password: string): Promise { + if (!this.state.createaccounttoken) { // not logged in + await this.getTokens(); + } + return this.request({ + action: 'createaccount', + createreturnurl: 'https://example.com', + createtoken: this.state.createaccounttoken, + username: username, + password: password, + retype: password + }).then(json => { + let data = json.createaccount; + if (data.status === 'FAIL') { + return Promise.reject(data); + } else { // status === 'PASS' or other value + return data; + } + }); + } + /** * Get basic info about the logged-in user * @param [options]