pub struct Bot { /* private fields */ }Expand description
Main bot class
Implementations§
Source§impl Bot
impl Bot
Sourcepub fn builder(wiki_url: String) -> Builder
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/.
Sourcepub fn builder_with_legacy_rest(api_url: String, rest_url: String) -> Builder
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.
Sourcepub async fn from_default_config() -> Result<Self, ConfigError>
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_HOMEor$HOME/.config - macOS:
$HOME/Library/Application Support - Windows:
{FOLDERID_RoamingAppData}
Under UNIX-like systems, the configuration file must only be readable by its owner!
Sourcepub async fn from_path(path: &Path) -> Result<Self, ConfigError>
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!
Sourcepub async fn clone_for_family(
&self,
wiki_url: &str,
) -> Result<Self, ConfigError>
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.
pub async fn clone_for_family_via_dbname( &self, dbname: &str, ) -> Result<Self, ConfigError>
sitematrix only.Sourcepub fn api(&self) -> &ApiClient
pub fn api(&self) -> &ApiClient
Get a reference to the underlying mwapi::Client
to make arbitrary API requests
Sourcepub fn parsoid(&self) -> &ParsoidClient
pub fn parsoid(&self) -> &ParsoidClient
Get a reference to the underlying parsoid::Client
to make arbitrary Parsoid API requests
Sourcepub fn title_codec(&self) -> &TitleCodec
pub fn title_codec(&self) -> &TitleCodec
Get a reference to the internal mwtitle::TitleCodec
to parse and construct arbitrary titles.
Sourcepub fn page(&self, title: &str) -> Result<Page>
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.
Sourcepub fn page_from_database(&self, namespace: i32, dbkey: &str) -> Result<Page>
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.
Sourcepub async fn page_from_id(&self, page_id: u64) -> Result<Page>
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.
Sourcepub fn server_name(&self) -> &str
pub fn server_name(&self) -> &str
Get the site’s server name, which is usually the domain name,
e.g. "en.wikipedia.org"
Sourcepub fn wiki_id(&self) -> &str
pub fn wiki_id(&self) -> &str
Get the site’s “wikiid”, which is usually the internal database name,
e.g. "enwiki"
Sourcepub fn mediawiki_version(&self) -> &str
pub fn mediawiki_version(&self) -> &str
Get the version of MediaWiki that the site is using, e.g. "1.45.0"