Last active
April 4, 2024 16:55
-
-
Save DamianZaremba/49f56b2f28427fd37923989046af5700 to your computer and use it in GitHub Desktop.
ClueBot Monitoring Scripts - Wikimedia API compatibility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+sub edit_page { | |
+ my $logger = shift; | |
+ my $wiki = shift; | |
+ my $title = shift; | |
+ my $text = shift; | |
+ my $summary = shift; | |
+ | |
+ my $ref = $wiki->api({action => 'query', meta => 'tokens', type => 'csrf'}); | |
+ if(!$ref) { | |
+ $logger->error("Could not retrieve CSRF token"); | |
+ return 0; | |
+ } | |
+ my $csrftoken = $ref->{'query'}->{'tokens'}->{'csrftoken'}; | |
+ return $wiki->api({action => 'edit', title => $title, text => $text, summary => $summary, token => $csrftoken}); | |
+} | |
- if(!$wiki->edit({ | |
- action => 'edit', | |
- title => 'User:' . $config->{'check_user'} . '/running', | |
- text => $message, | |
- summary => 'Bot not running', | |
- })) { | |
+ if(!edit_page($logger, $wiki, 'User:' . $config->{'check_user'} . '/running', $message, 'Bot not running')) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment