Passed
Push — master ( 96aa6d...96a38e )
by Daimona
01:37
created

run.php (1 issue)

1
<?php
2
3
require __DIR__ . '/vendor/autoload.php';
4
5
use BotRiconferme\Config;
6
use BotRiconferme\Bot;
7
8
if ( PHP_SAPI !== 'cli' ) {
9
	exit( 'CLI only!' );
10
}
11
12
/** MAIN PARAMS */
13
14
/*
15
	Example
16
17
	'url' => 'https://it.wikipedia.org/w/api.php',
18
	'username' => 'BotRiconferme'
19
	'list-title' => 'Utente:BotRiconferme/List.json',
20
	'config-title' => 'Utente:BotRiconferme/Config.json',
21
*/
22
23
$params = [
24
	'url:',
25
	'username:',
26
	'list-title:',
27
	'config-title:'
28
];
29
30
$vals = getopt( '', $params );
31
if ( count( $vals ) !== count( $params ) ) {
32
	exit( 'Not enough params!' );
33
}
34
35
/* PASSWORD */
36
37
$PWFILE = './password.txt';
38
/*
39
 * Either
40
 * --password=(BotPassword)
41
 * or
42
 * --use-password-file
43
 * which will look for a $PWFILE file in the current directory containing only the plain password
44
 */
45
$pwParams = getopt( '', [
46
	'password:',
47
	'use-password-file'
48
] );
49
50
if ( isset( $pwParams[ 'password' ] ) ) {
51
	$pw = $pwParams[ 'password' ];
52
} elseif ( isset( $pwParams[ 'use-password-file' ] ) ) {
53
	if ( file_exists( $PWFILE ) ) {
54
		$pw = trim( file_get_contents( $PWFILE ) );
55
	} else {
56
		exit( 'Please create a password.txt file to use with use-password-file' );
57
	}
58
} else {
59
	exit( 'Please provide a password or use a password file' );
60
}
61
62
$vals[ 'password' ] = $pw;
63
64
/* START */
65
66
Config::init( $vals );
67
68
$bot = new Bot();
69
70
/*
71
 * E.g. --task=update-list
72
 */
73
$taskOpts = getopt( '', [ 'task:' ] );
74
75
if ( $taskOpts ) {
1 ignored issue
show
Bug Best Practice introduced by
The expression $taskOpts of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
76
	$bot->runSingle( $taskOpts[ 'task' ] );
77
} else {
78
	$bot->run();
79
}
80