Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* NewsBot - A "really sweeeet newsletter delivering" bot for Addshore
- Copyright (C) 2008 Chris Grant - http://en.wikipedia.org/wiki/User:Chris_G
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- Developers (add your self here if you worked on the code):
- Chris - [[User:Chris_G]] - Wrote up the main code
- Cobi - [[User:Cobi]] - Wrote wikibot.classes.php
- Addshore - [[User:Addshore]] - Edited for own use
- */
- //Includes
- include("wikibot.classes.php"); //Use Cobi's classes - see [[User:Cobi]] and [[User:ClueBot/Source]]
- include("bot.config.php"); //Includes bot username and password
- //Setup the classes
- $wpapi = new wikipediaapi;
- $wpq = new wikipediaquery;
- $wpi = new wikipediaindex;
- //Config Vars for the delivery
- $delivery['type'] = 'links'; //cat, list, links
- $delivery['page'] = 'Wikipedia:WikiProject_Puerto_Rico/Participants';
- $delivery['text'] = "\n\r{{subst:Wikipedia:WikiProject_Puerto_Rico/Newsletter/Current}}\n\r~~~~";
- $delivery['sum'] = 'WikiProject Puerto Rico Newsletter Issue 1 - Summer 2008 ([[User:'.$user.'|BOT]])';
- $delivery['sleep'] = 10000; //Wait micro seconds (1000000 = 1s)
- //Login
- $wpapi->login($user,$pass);
- echo "Now logged in\n";
- //Posting Source
- $wpi->forcepost('User:'.$user.'/Source/Newsbot','The following post was automatically generated by [[User:'.$user.'|'.$user."]].\n\n<source lang='php'>" . file_get_contents('news.bot.php')."</source>",'Automatic source code upload');
- echo "Source Code Posted!\n";
- if ($delivery['type'] == 'cat') {
- $x = $wpapi->categorymembers('Category:'.$delivery['page'],500);
- foreach ($x as $p) {
- deliver($p['title']);
- }
- }
- elseif ($delivery['type'] == 'list') {
- $pages = explode(chr(10), $wpq->getpage($delivery['page']));
- foreach ($pages as $p) {
- deliver($p);
- }
- }
- elseif ($delivery['type'] == 'links') {
- preg_match_all('/\[\[(User|User_talk):.+\]\]/i',$wpq->getpage($delivery['page']),$pages);
- foreach ($pages[0] as $p) {
- $temp = explode('|',$p);
- $p = preg_replace(array('/.*\[\[(User|User_talk):/i','/\]\].*/i'),'',$temp[0]);
- deliver($p);
- }
- }
- else {
- die('Unsupported Delivery Type Chosen *dies*');
- }
- function deliver($page) {
- //Delivers the newsletter to $page
- global $wpi, $wpq, $delivery;
- $page = "User_Talk:".trim($page);
- if (preg_match('/#REDIRECT \[\[.+\]\]/i',$wpq->getpage($page),$new_page)) {
- $page = str_replace(array('#REDIRECT [[',']]'),'',$new_page[0]);
- }
- echo "Sending to $page\n";
- $wpi->post($page,$wpq->getpage($page).$delivery['text'],$delivery['sum']);
- usleep($delivery['sleep']);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement