Jump to content

User:DannyS712 test/remind bot.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by DannyS712 test (talk | contribs) at 04:22, 1 February 2019 (better names). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
RemindBot_config = {
	name: "[[User:DannyS712/Remind Bot.js|Remind Bot]]",
	version: 1.0,
	debug: false
};

mw.loader.using( 'mediawiki.util', function () {
    importScript('User:DannyS712 test/get JSON.js');
    importScript('User:DannyS712 test/set JSON.js');
    $(document).ready( function () { 
        var link = mw.util.addPortletLink( 'p-cactions', null, 'Remind BOT', 'ca-BOT-reminder', 'Check reminders'); 
        $( link ).click( function ( event ) {
            event.preventDefault();
            check_reminders();
        } );
    } );
} );
function check_reminders(){
	var current_reminders = get_JSON( 'User:DannyS712 test/reminders.json' );
	if (RemindBot_config.debug) console.log( current_reminders );
	var pages = get_page_list();
	console.log( pages );
	var new_reminders = all_reminders( pages );
	console.log( new_reminders );
}
function get_page_list(){
	/**
	var get_pages = {
        action: 'query',
        list: 'categorymembers',
        cmlimit: 'max',
        cmtitle: 'Category:Wikipedians recieving reminders',
        cmprop: 'title',
        format: 'json'
    };
    var result = null;
	var scriptUrl = mw.config.get( 'wgScriptPath' ) + '/api.php';
	$.ajax({
		url: scriptUrl,
		type: 'get',
		data: get_pages,
		dataType: 'json',
		async: false,
		success: function(catResponse) {
	    	console.log( catResponse );
			var pages = catResponse.query.categorymembers;
			var listed = [];
			for (var i = 0; i < pages.length; i++) {
				if ( pages[i].ns === 2 ) {
					listed.push(pages[i].title + "/remind.json");
				}
			}
			console.log( listed );
			if ( listed.length <= 0 ) {
				alert( "There are no users recieving reminders." );
			}
			else {
		    	result = listed;
			}
		} 
	});
	return result;
	***/
	return (['User:DannyS712 test/remind.json', 'User:DannyS712 test/remind 2.json']);
}
function all_reminders( pages ){
	var all_reminders = [];
	for (var iii = 0; iii < pages.length; iii++){
		var user_reminders = get_JSON(pages[iii]);
		//console.log( user_reminders );
		for (var jjj = 0; jjj < user_reminders.length; jjj++){
			var reminder = user_reminders[jjj];
			if (reminder.page == "demo") continue;
			else {
				//console.log( reminder );
				all_reminders.push( {user: pages[iii], start: reminder.start, id: reminder.id, reminded: false} );
			}
		}
	}
	return all_reminders;
}