Skip to content

Commit

Permalink
Merge pull request #348 from macbre/typing/more
Browse files Browse the repository at this point in the history
Add more types: SearchResult and UserContribution
  • Loading branch information
macbre committed Jul 5, 2022
2 parents fde63f2 + 1253373 commit 332966e
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 18 deletions.
12 changes: 7 additions & 5 deletions examples/getUserContribs.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
// @ts-check
/**
* Example script getting contributions done by Pyrabot
*/
'use strict';

const Bot = require( '..' ),
client = new Bot( {
server: 'poznan.wikia.com'
} );
const Bot = require( '..' );
const client = new Bot( {
server: 'poznan.wikia.com'
} );

client.getUserContribs( {
user: 'Pyrabot'
}, function ( err, data ) {
if ( err ) {
console.error( err );
} else {
console.log( data );
const contrib = data[ 0 ];
console.log( `${contrib.user} made an edit to ${contrib.title} on ${contrib.timestamp} (${contrib.comment}).` );
}
} );
2 changes: 1 addition & 1 deletion examples/parseWikitext.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node
/**
* Example script that parser given wikitext
* Example script that parses given wikitext
*/
'use strict';

Expand Down
30 changes: 23 additions & 7 deletions examples/search.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
// @ts-check
/**
* Example script getting MW version
*/
'use strict';

const Bot = require( '..' ),
wikipedia = new Bot( {
server: 'pl.wikipedia.org',
path: '/w',
debug: true
} );
const Bot = require( '..' );

const wikipedia = new Bot( {
server: 'pl.wikipedia.org',
path: '/w'
// debug: true
} );

wikipedia.search( 'Tórshavn', ( err, results ) => {
wikipedia.log( 'Search results:', results );
if ( err ) {
console.error( err );
return;
}

console.log( `Got ${results.length} results:` );

results.slice( 0, 25 ).forEach( ( res ) => {
console.log( `* ${res.title}` );
} );

// wikipedia.log( 'Search results:', results.slice(0, 5) );

// const { dumpObjectTypes } = require( '../lib/utils');
// dumpObjectTypes('SearchResult', results[0]);
} );
12 changes: 7 additions & 5 deletions lib/bot.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ import {
PageEditedResult,
PageInCategory,
RedirectInfo,
SearchResult,
SiteInfo,
SiteStatistics,
UserContribution,
UserInfo,
WikiaUserInfo,
WikiaWikiVariables,
Expand All @@ -44,12 +46,17 @@ declare class Bot {
edit( title: string, content: string, summary: string, minor: boolean, callback: NodeJSCallback<PageEditedResult> ): void;
getArticle( article: string, callback: NodeJSCallback<string> ): void;
getArticle( article: string, followRedirect: boolean, callback: NodeJSCallbackDouble<string, RedirectInfo> ): void;
getArticleInfo( title: any, options: any, callback: NodeJSCallback<ArticleInfo[]> ) : void;
getArticleProperties(title: string, callback: NodeJSCallback<ArticleProperties>): void;
getMediaWikiVersion( callback: NodeJSCallback<string> ): void;
getPagesInCategory( category: string, callback: NodeJSCallback<PageInCategory[]>): void;
getSiteInfo( props: string[], callback: NodeJSCallback<SiteInfo> ) : void;
getSiteStats( callback: NodeJSCallback<SiteStatistics> ) : void;
getUserContribs( options: {user: string}, callback: NodeJSCallback<UserContribution[]> ) : void;
logIn( callback: NodeJSCallback<any>): void;
logIn( username: string, password: string, callback: NodeJSCallback<any>): void;
prepend( title: string, content: string, summary: string, callback: NodeJSCallback<PageEditedResult> ): void;
search( keyword: string, callback: NodeJSCallback<SearchResult[]> ) : void;
whois( username: string, callback: NodeJSCallback<UserInfo> ): void;

// TODO: add proper types for the rest of the methods
Expand All @@ -62,7 +69,6 @@ declare class Bot {
getAll( params: any, key: any, callback: NodeJSCallback<any> ) : void;
getAllPages( callback: NodeJSCallback<any> ) : void;
getArticleCategories( title: any, callback: NodeJSCallback<any> ) : void;
getArticleInfo( title: any, options: any, callback: NodeJSCallback<ArticleInfo[]> ) : void;
getArticleRevisions( title: any, callback: NodeJSCallback<any> ) : void;
getBacklinks( title: any, callback: NodeJSCallback<any> ) : void;
getCategories( prefix: any, callback: NodeJSCallback<any> ) : void;
Expand All @@ -79,17 +85,13 @@ declare class Bot {
getQueryPage( queryPage: any, callback: NodeJSCallback<any> ) : void;
getRand() : void;
getRecentChanges( start: any, callback: NodeJSCallback<any> ) : void;
getSiteInfo( props: string[], callback: NodeJSCallback<SiteInfo> ) : void;
getSiteStats( callback: NodeJSCallback<SiteStatistics> ) : void;
getTemplateParamFromXml( tmplXml: any, paramName: any ) : void;
getToken( title: any, action: any, callback: NodeJSCallback<any> ) : void;
getUserContribs( options: any, callback: NodeJSCallback<any> ) : void;
getUsers( data: any, callback: NodeJSCallback<any> ) : void;
move( from: any, to: any, summary: any, callback: NodeJSCallback<any> ) : void;
parse( text: any, title: any, callback: NodeJSCallback<any> ) : void;
protect( title: any, protections: any, options: any, callback: NodeJSCallback<any> ) : void;
purge( titles: any, callback: NodeJSCallback<any> ) : void;
search( keyword: any, callback: NodeJSCallback<any> ) : void;
sendEmail( username: any, subject: any, text: any, callback: NodeJSCallback<any> ) : void;
setConfig( key: any, val: any ) : void;
upload( filename: any, content: any, extraParams: any, callback: NodeJSCallback<any> ) : void;
Expand Down
21 changes: 21 additions & 0 deletions lib/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,24 @@ export interface ArticleProperties {
'wikibase-shortdesc': string;
wikibase_item: string;
}

export interface UserContribution {
userid: number;
user: string;
pageid: number;
revid: number;
parentid: number;
ns: number;
title: string;
timestamp: string;
top: string;
comment: string;
size: number;
}

export interface SearchResult {
ns: number;
title: string;
pageid: number;
timestamp: string;
}

0 comments on commit 332966e

Please sign in to comment.