Skip to main content

Bot

Struct Bot 

Source
pub struct Bot { /* private fields */ }
Expand description

Main bot class

Implementations§

Source§

impl Bot

Source

pub fn builder(wiki_url: String) -> Builder

Build a Bot instance programmatically.

The wiki’s URL should be the path where api.php and rest.php can be found (aka the “script path”). By default it is usually something like https://wiki.example.org/w/.

Source

pub fn builder_with_legacy_rest(api_url: String, rest_url: String) -> Builder

For older wikis (pre-1.42) that use RESTBase or the old Parsoid rest.php API.

Source

pub async fn from_default_config() -> Result<Self, ConfigError>

Load Bot configuration from a default location, first look at mwbot.toml in the current directory, otherwise look in the platform’s config directory:

  • Linux: $XDG_CONFIG_HOME or $HOME/.config
  • macOS: $HOME/Library/Application Support
  • Windows: {FOLDERID_RoamingAppData}

Under UNIX-like systems, the configuration file must only be readable by its owner!

Source

pub async fn from_path(path: &Path) -> Result<Self, ConfigError>

Load Bot configuration from the specified path.

Under UNIX-like systems, the configuration file must only be readable by its owner!

Source

pub async fn clone_for_family( &self, wiki_url: &str, ) -> Result<Self, ConfigError>

Clone this bot for another wiki in the same family.

This allows you to use the Bot to connect to another wiki in the same family. For example, if you have a bot for en.wikipedia.org, you can clone it to use with de.wikipedia.org.

Behind the scenes, this will copy over the username, authentication info, as well as internal HTTP connection pools and save state. Rate limits like edit speed will apply across both instances.

Source

pub async fn clone_for_family_via_dbname( &self, dbname: &str, ) -> Result<Self, ConfigError>

Available on crate feature sitematrix only.
Source

pub fn api(&self) -> &ApiClient

Get a reference to the underlying mwapi::Client to make arbitrary API requests

Source

pub fn parsoid(&self) -> &ParsoidClient

Get a reference to the underlying parsoid::Client to make arbitrary Parsoid API requests

Source

pub fn title_codec(&self) -> &TitleCodec

Get a reference to the internal mwtitle::TitleCodec to parse and construct arbitrary titles.

Source

pub fn page(&self, title: &str) -> Result<Page>

Get a Page on this wiki. The specified title should be a full title, including namespace. This does some validation on the provided input.

Source

pub fn page_from_database(&self, namespace: i32, dbkey: &str) -> Result<Page>

Get a Page on this wiki using information from a database row.

The provided input will be validated and may return an error if invalid.

Source

pub fn page_from_title(&self, title: Title) -> Result<Page>

Get a Page for a given Title

Source

pub async fn page_from_id(&self, page_id: u64) -> Result<Page>

Get a Page on this wiki using page id.

The provided input will be validated and may return an error if invalid.

Source

pub fn server_name(&self) -> &str

Get the site’s server name, which is usually the domain name, e.g. "en.wikipedia.org"

Source

pub fn wiki_id(&self) -> &str

Get the site’s “wikiid”, which is usually the internal database name, e.g. "enwiki"

Source

pub fn mediawiki_version(&self) -> &str

Get the version of MediaWiki that the site is using, e.g. "1.45.0"

Source

pub fn namespace_id<'a, N: Into<Namespace<'a>>>( &self, namespace: N, ) -> Option<i32>

Get the numeric id of a Namespace.

Source

pub fn namespace_name<'a, N: Into<Namespace<'a>>>( &self, namespace: N, ) -> Option<&str>

Get the name of a Namespace.

Trait Implementations§

Source§

impl Clone for Bot

Source§

fn clone(&self) -> Bot

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Bot

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Bot

§

impl !UnwindSafe for Bot

§

impl Freeze for Bot

§

impl Send for Bot

§

impl Sync for Bot

§

impl Unpin for Bot

§

impl UnsafeUnpin for Bot

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more