diff --git a/build/bot.d.ts b/build/bot.d.ts index 1507770..97dfe11 100644 --- a/build/bot.d.ts +++ b/build/bot.d.ts @@ -35,6 +35,7 @@ import { MwnError, MwnErrorConfig } from "./error"; import type { Link, CategoryLink, FileLink, PageLink, Template, TemplateConfig, Section } from "./wikitext"; import type { ApiDeleteParams, ApiEditPageParams, ApiMoveParams, ApiParseParams, ApiPurgeParams, ApiQueryAllPagesParams, ApiQueryCategoryMembersParams, ApiQuerySearchParams, ApiRollbackParams, ApiUndeleteParams, ApiUploadParams, ApiEmailUserParams, ApiQueryRevisionsParams, ApiQueryLogEventsParams, ApiQueryBacklinkspropParams, ApiQueryCategoriesParams, ApiQueryUserContribsParams, ApiBlockParams, ApiUnblockParams } from "./api_params"; import type { recentchangeProps } from "./eventstream"; +import type { LogEvent, UserContribution } from "./user"; export declare type revisionprop = "content" | "timestamp" | "user" | "comment" | "parsedcomment" | "ids" | "flags" | "size" | "tags" | "userid" | "contentmodel"; export declare type logprop = "type" | "user" | "comment" | "details" | "timestamp" | "title" | "parsedcomment" | "ids" | "tags" | "userid"; export interface RawRequestParams extends AxiosRequestConfig { @@ -143,8 +144,10 @@ export interface MwnUser extends MwnTitle { username: string; userpage: MwnPage; talkpage: MwnPage; - contribs(options?: ApiQueryUserContribsParams): Promise; - logs(options?: ApiQueryLogEventsParams): Promise; + contribs(options?: ApiQueryUserContribsParams): Promise; + contribsGen(options?: ApiQueryUserContribsParams): AsyncGenerator; + logs(options?: ApiQueryLogEventsParams): Promise; + logsGen(options?: ApiQueryLogEventsParams): AsyncGenerator; info(props?: string | string[]): Promise; globalinfo(props?: ("groups" | "rights" | "merged" | "unattached" | "editcount")[]): Promise; sendMessage(header: string, message: string): Promise; diff --git a/build/user.d.ts b/build/user.d.ts index cb0ff5c..6706b20 100644 --- a/build/user.d.ts +++ b/build/user.d.ts @@ -1 +1,28 @@ -export {}; +export declare type UserContribution = { + userid: number; + user: string; + pageid: number; + revid: number; + parentid: number; + ns: number; + title: string; + timestamp: string; + new: boolean; + minor: boolean; + top: boolean; + comment: string; + size: number; +}; +export declare type LogEvent = { + logid: number; + ns: number; + title: string; + pageid: number; + logpage: number; + params: any; + type: string; + action: string; + user: string; + timestamp: string; + comment: string; +}; diff --git a/build/user.js b/build/user.js index e100f21..b90441b 100644 --- a/build/user.js +++ b/build/user.js @@ -32,6 +32,20 @@ module.exports = function (bot) { ...options }).then(data => data.query.usercontribs); } + async *contribsGen(options) { + let continuedQuery = bot.continuedQueryGen({ + action: 'query', + list: 'usercontribs', + ucuser: this.username, + uclimit: 'max', + ...options + }); + for await (let json of continuedQuery) { + for (let edit of json.query.usercontribs) { + yield edit; + } + } + } /** * Get user's recent log actions * @param {Object} options - additional API options @@ -46,6 +60,20 @@ module.exports = function (bot) { ...options }).then(data => data.query.logevents); } + async *logsGen(options) { + let continuedQuery = bot.continuedQueryGen({ + action: 'query', + list: 'logevents', + leuser: this.username, + lelimit: 'max', + ...options + }); + for await (let json of continuedQuery) { + for (let action of json.query.logevents) { + yield action; + } + } + } /** * Get public information about the user * @param {Array} props - properties to fetch diff --git a/src/bot.ts b/src/bot.ts index 4a30674..66422bf 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -71,6 +71,7 @@ import type { ApiQueryUserContribsParams, ApiBlockParams, ApiUnblockParams } from "./api_params"; import type {recentchangeProps} from "./eventstream"; +import type {LogEvent, UserContribution} from "./user"; export type revisionprop = "content" | "timestamp" | "user" | "comment" | "parsedcomment" | "ids" | "flags" | "size" | "tags" | "userid" | "contentmodel" @@ -154,8 +155,10 @@ export interface MwnUser extends MwnTitle { talkpage: MwnPage // get userpage(): MwnPage // XXX // get talkpage(): MwnPage - contribs(options?: ApiQueryUserContribsParams): Promise - logs(options?: ApiQueryLogEventsParams): Promise + contribs(options?: ApiQueryUserContribsParams): Promise + contribsGen(options?: ApiQueryUserContribsParams): AsyncGenerator + logs(options?: ApiQueryLogEventsParams): Promise + logsGen(options?: ApiQueryLogEventsParams): AsyncGenerator info(props?: string | string[]): Promise globalinfo(props?: ("groups"|"rights"|"merged"|"unattached"|"editcount")[]): Promise sendMessage(header: string, message: string): Promise diff --git a/src/user.ts b/src/user.ts index 35e944a..91c8cf7 100644 --- a/src/user.ts +++ b/src/user.ts @@ -7,6 +7,36 @@ import type { ApiUnblockParams } from "./api_params"; +export type UserContribution = { + userid: number + user: string + pageid: number + revid: number + parentid: number + ns: number + title: string + timestamp: string + new: boolean + minor: boolean + top: boolean + comment: string + size: number +} + +export type LogEvent = { + logid: number + ns: number + title: string + pageid: number + logpage: number + params: any + type: string + action: string + user: string + timestamp: string + comment: string +} + module.exports = function(bot: mwn) { class User { @@ -37,7 +67,7 @@ module.exports = function(bot: mwn) { * @param {Object} options - additional API options * @returns {Promise} */ - contribs(options?: ApiQueryUserContribsParams): Promise { + contribs(options?: ApiQueryUserContribsParams): Promise { return bot.request({ action: 'query', list: 'usercontribs', @@ -47,13 +77,27 @@ module.exports = function(bot: mwn) { }).then(data => data.query.usercontribs); } + async *contribsGen(options?: ApiQueryUserContribsParams): AsyncGenerator { + let continuedQuery = bot.continuedQueryGen({ + action: 'query', + list: 'usercontribs', + ucuser: this.username, + uclimit: 'max', + ...options + }); + for await (let json of continuedQuery) { + for (let edit of json.query.usercontribs) { + yield edit; + } + } + } /** * Get user's recent log actions * @param {Object} options - additional API options * @returns {Promise} */ - logs(options?: ApiQueryLogEventsParams): Promise { + logs(options?: ApiQueryLogEventsParams): Promise { return bot.request({ action: 'query', list: 'logevents', @@ -63,6 +107,21 @@ module.exports = function(bot: mwn) { }).then(data => data.query.logevents); } + async *logsGen(options?: ApiQueryLogEventsParams): AsyncGenerator { + let continuedQuery = bot.continuedQueryGen({ + action: 'query', + list: 'logevents', + leuser: this.username, + lelimit: 'max', + ...options + }); + for await (let json of continuedQuery) { + for (let action of json.query.logevents) { + yield action; + } + } + } + /** * Get public information about the user * @param {Array} props - properties to fetch