View difference between Paste ID: f8487006 and
SHOW: | | - or go back to the newest paste.
1-
1+
<?php
2
/* NewsBot - A "really sweeeet newsletter delivering" bot for Addshore
3
   Copyright (C) 2008  Chris Grant - http://en.wikipedia.org/wiki/User:Chris_G
4
 
5
   This program is free software; you can redistribute it and/or modify
6
   it under the terms of the GNU General Public License as published by
7
   the Free Software Foundation; either version 2 of the License, or
8
   (at your option) any later version.
9
 
10
   This program is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
   GNU General Public License for more details.
14
 
15
   You should have received a copy of the GNU General Public License
16
   along with this program; if not, write to the Free Software
17
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
    
19
   Developers (add your self here if you worked on the code):
20
        Chris    - [[User:Chris_G]]  - Wrote up the main code
21
        Cobi     - [[User:Cobi]]     - Wrote wikibot.classes.php
22
        Addshore - [[User:Addshore]] - Edited for own use
23
*/
24
 
25
//Includes
26
include("wikibot.classes.php"); //Use Cobi's classes - see [[User:Cobi]] and [[User:ClueBot/Source]]
27
include("bot.config.php"); //Includes bot username and password
28
 
29
//Setup the classes
30
$wpapi  = new wikipediaapi;
31
$wpq    = new wikipediaquery;
32
$wpi    = new wikipediaindex;
33
 
34
//Config Vars for the delivery
35
$delivery['type']  = 'links'; //cat, list, links
36
$delivery['page']  = 'Wikipedia:WikiProject_Puerto_Rico/Participants';
37
$delivery['text']  = "\n\r{{subst:Wikipedia:WikiProject_Puerto_Rico/Newsletter/Current}}\n\r~~~~";
38
$delivery['sum']   = 'WikiProject Puerto Rico Newsletter Issue 1 - Summer 2008 ([[User:'.$user.'|BOT]])';
39
$delivery['sleep'] = 10000; //Wait micro seconds (1000000 = 1s)
40
 
41
//Login
42
$wpapi->login($user,$pass);
43
echo "Now logged in\n";
44
 
45
//Posting Source
46
$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');
47
echo "Source Code Posted!\n";
48
 
49
if ($delivery['type'] == 'cat') {
50
        $x = $wpapi->categorymembers('Category:'.$delivery['page'],500);
51
        foreach ($x as $p) {
52
                deliver($p['title']);
53
        }
54
}
55
elseif ($delivery['type'] == 'list') {
56
        $pages = explode(chr(10), $wpq->getpage($delivery['page']));
57
        foreach ($pages as $p) {
58
                deliver($p);
59
        }
60
}
61
elseif ($delivery['type'] == 'links') {
62
        preg_match_all('/\[\[(User|User_talk):.+\]\]/i',$wpq->getpage($delivery['page']),$pages);
63
        foreach ($pages[0] as $p) {
64
                $temp = explode('|',$p);
65
                $p = preg_replace(array('/.*\[\[(User|User_talk):/i','/\]\].*/i'),'',$temp[0]);
66
                deliver($p);
67
        }
68
}
69
else {
70
        die('Unsupported Delivery Type Chosen *dies*');
71
}
72
73
function deliver($page) {
74
	//Delivers the newsletter to $page
75
	global $wpi, $wpq, $delivery;
76
	$page = "User_Talk:".trim($page);
77
	if (preg_match('/#REDIRECT \[\[.+\]\]/i',$wpq->getpage($page),$new_page)) {
78
		$page = str_replace(array('#REDIRECT [[',']]'),'',$new_page[0]);
79
	}
80
	echo "Sending to $page\n";
81
        $wpi->post($page,$wpq->getpage($page).$delivery['text'],$delivery['sum']);
82
        usleep($delivery['sleep']);
83
}