1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 01:02:42 +01:00

Add a lipsum generator for Badges

Summary: Ref T12319. Ref T12270. Allow badges to be generated with `bin/lipsum`. These aren't hugely sophisticated but I'm not sure about the fate of T9010 yet or what's happening with the quality levels, and didn't want to make those changes more difficult.

Test Plan:
  - Used `bin/lipsum generate badges --force --quickly` to generate badges.
  - Made some coffee and came back to 20K badges.

{F3422200}

Reviewers: chad

Reviewed By: chad

Subscribers: cspeckmim

Maniphest Tasks: T12319, T12270

Differential Revision: https://secure.phabricator.com/D17422
This commit is contained in:
epriestley 2017-02-27 05:10:30 -08:00
parent 3b8ccb0b78
commit 5cb4c76bef
3 changed files with 163 additions and 0 deletions

View file

@ -2021,6 +2021,7 @@ phutil_register_library_map(array(
'PhabricatorBadgesBadgeQualityTransaction' => 'applications/badges/xaction/PhabricatorBadgesBadgeQualityTransaction.php', 'PhabricatorBadgesBadgeQualityTransaction' => 'applications/badges/xaction/PhabricatorBadgesBadgeQualityTransaction.php',
'PhabricatorBadgesBadgeRevokeTransaction' => 'applications/badges/xaction/PhabricatorBadgesBadgeRevokeTransaction.php', 'PhabricatorBadgesBadgeRevokeTransaction' => 'applications/badges/xaction/PhabricatorBadgesBadgeRevokeTransaction.php',
'PhabricatorBadgesBadgeStatusTransaction' => 'applications/badges/xaction/PhabricatorBadgesBadgeStatusTransaction.php', 'PhabricatorBadgesBadgeStatusTransaction' => 'applications/badges/xaction/PhabricatorBadgesBadgeStatusTransaction.php',
'PhabricatorBadgesBadgeTestDataGenerator' => 'applications/badges/lipsum/PhabricatorBadgesBadgeTestDataGenerator.php',
'PhabricatorBadgesBadgeTransactionType' => 'applications/badges/xaction/PhabricatorBadgesBadgeTransactionType.php', 'PhabricatorBadgesBadgeTransactionType' => 'applications/badges/xaction/PhabricatorBadgesBadgeTransactionType.php',
'PhabricatorBadgesCommentController' => 'applications/badges/controller/PhabricatorBadgesCommentController.php', 'PhabricatorBadgesCommentController' => 'applications/badges/controller/PhabricatorBadgesCommentController.php',
'PhabricatorBadgesController' => 'applications/badges/controller/PhabricatorBadgesController.php', 'PhabricatorBadgesController' => 'applications/badges/controller/PhabricatorBadgesController.php',
@ -2035,6 +2036,7 @@ phutil_register_library_map(array(
'PhabricatorBadgesEditor' => 'applications/badges/editor/PhabricatorBadgesEditor.php', 'PhabricatorBadgesEditor' => 'applications/badges/editor/PhabricatorBadgesEditor.php',
'PhabricatorBadgesIconSet' => 'applications/badges/icon/PhabricatorBadgesIconSet.php', 'PhabricatorBadgesIconSet' => 'applications/badges/icon/PhabricatorBadgesIconSet.php',
'PhabricatorBadgesListController' => 'applications/badges/controller/PhabricatorBadgesListController.php', 'PhabricatorBadgesListController' => 'applications/badges/controller/PhabricatorBadgesListController.php',
'PhabricatorBadgesLootContextFreeGrammar' => 'applications/badges/lipsum/PhabricatorBadgesLootContextFreeGrammar.php',
'PhabricatorBadgesMailReceiver' => 'applications/badges/mail/PhabricatorBadgesMailReceiver.php', 'PhabricatorBadgesMailReceiver' => 'applications/badges/mail/PhabricatorBadgesMailReceiver.php',
'PhabricatorBadgesPHIDType' => 'applications/badges/phid/PhabricatorBadgesPHIDType.php', 'PhabricatorBadgesPHIDType' => 'applications/badges/phid/PhabricatorBadgesPHIDType.php',
'PhabricatorBadgesProfileController' => 'applications/badges/controller/PhabricatorBadgesProfileController.php', 'PhabricatorBadgesProfileController' => 'applications/badges/controller/PhabricatorBadgesProfileController.php',
@ -6979,6 +6981,7 @@ phutil_register_library_map(array(
'PhabricatorBadgesBadgeQualityTransaction' => 'PhabricatorBadgesBadgeTransactionType', 'PhabricatorBadgesBadgeQualityTransaction' => 'PhabricatorBadgesBadgeTransactionType',
'PhabricatorBadgesBadgeRevokeTransaction' => 'PhabricatorBadgesBadgeTransactionType', 'PhabricatorBadgesBadgeRevokeTransaction' => 'PhabricatorBadgesBadgeTransactionType',
'PhabricatorBadgesBadgeStatusTransaction' => 'PhabricatorBadgesBadgeTransactionType', 'PhabricatorBadgesBadgeStatusTransaction' => 'PhabricatorBadgesBadgeTransactionType',
'PhabricatorBadgesBadgeTestDataGenerator' => 'PhabricatorTestDataGenerator',
'PhabricatorBadgesBadgeTransactionType' => 'PhabricatorModularTransactionType', 'PhabricatorBadgesBadgeTransactionType' => 'PhabricatorModularTransactionType',
'PhabricatorBadgesCommentController' => 'PhabricatorBadgesController', 'PhabricatorBadgesCommentController' => 'PhabricatorBadgesController',
'PhabricatorBadgesController' => 'PhabricatorController', 'PhabricatorBadgesController' => 'PhabricatorController',
@ -6993,6 +6996,7 @@ phutil_register_library_map(array(
'PhabricatorBadgesEditor' => 'PhabricatorApplicationTransactionEditor', 'PhabricatorBadgesEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorBadgesIconSet' => 'PhabricatorIconSet', 'PhabricatorBadgesIconSet' => 'PhabricatorIconSet',
'PhabricatorBadgesListController' => 'PhabricatorBadgesController', 'PhabricatorBadgesListController' => 'PhabricatorBadgesController',
'PhabricatorBadgesLootContextFreeGrammar' => 'PhutilContextFreeGrammar',
'PhabricatorBadgesMailReceiver' => 'PhabricatorObjectMailReceiver', 'PhabricatorBadgesMailReceiver' => 'PhabricatorObjectMailReceiver',
'PhabricatorBadgesPHIDType' => 'PhabricatorPHIDType', 'PhabricatorBadgesPHIDType' => 'PhabricatorPHIDType',
'PhabricatorBadgesProfileController' => 'PhabricatorController', 'PhabricatorBadgesProfileController' => 'PhabricatorController',

View file

@ -0,0 +1,71 @@
<?php
final class PhabricatorBadgesBadgeTestDataGenerator
extends PhabricatorTestDataGenerator {
const GENERATORKEY = 'badges';
public function getGeneratorName() {
return pht('Badges');
}
public function generateObject() {
$author = $this->loadRandomUser();
list($name, $description) = $this->newLoot();
$xactions = array();
$xactions[] = array(
'type' => 'name',
'value' => $name,
);
$xactions[] = array(
'type' => 'description',
'value' => $description,
);
$params = array(
'transactions' => $xactions,
);
$result = id(new ConduitCall('badges.edit', $params))
->setUser($author)
->execute();
return $result['object']['phid'];
}
private function newLoot() {
$drop = id(new PhabricatorBadgesLootContextFreeGrammar())
->generate();
$drop = preg_replace_callback(
'/<(\d+)-(\d+)>/',
array($this, 'rollDropValue'),
$drop);
$effect_pattern = '/\s*\(([^)]+)\)/';
$matches = null;
if (preg_match_all($effect_pattern, $drop, $matches)) {
$description = $matches[1];
$description = implode("\n", $description);
} else {
$description = '';
}
$drop = preg_replace($effect_pattern, '', $drop);
return array($drop, $description);
}
public function rollDropValue($matches) {
$min = (int)$matches[1];
$max = (int)$matches[2];
return mt_rand($min, $max);
}
}

View file

@ -0,0 +1,88 @@
<?php
final class PhabricatorBadgesLootContextFreeGrammar
extends PhutilContextFreeGrammar {
protected function getRules() {
return array(
'start' => array(
'[jewelry]',
),
'jewelry' => array(
'Ring [jewelry-suffix]',
'Ring [jewelry-suffix]',
'[jewelry-prefix] Ring',
'[jewelry-prefix] Ring',
'Amulet [jewelry-suffix]',
'Amulet [jewelry-suffix]',
'[jewelry-prefix] Amulet',
'[jewelry-prefix] Amulet',
'[jewelry-prefix] Ring [jewelry-suffix]',
'[jewelry-prefix] Amulet [jewelry-suffix]',
'[unique-jewelry]',
),
'jewelry-prefix' => array(
'[mana-prefix]',
),
'jewelry-suffix' => array(
'[dexterity-suffix]',
'[dexterity-suffix-jewelry]',
),
'mana-prefix' => array(
'Hyena\'s (-<11-25> Mana)',
'Frog\'s (-<1-10> Mana)',
'Spider\'s (+<10-15> Mana)',
'Raven\'s (+<15-20> Mana)',
'Snake\'s (+<21-30> Mana)',
'Serpent\'s (+<31-40> Mana)',
'Drake\'s (+<41-50> Mana)',
'Dragon\'s (+<51-60> Mana)',
),
'dexterity-suffix' => array(
'of Paralysis (-<6-10> Dexterity)',
'of Atrophy (-<1-5> Dexterity)',
'of Dexterity (+<1-5> Dexterity)',
'of Skill (+<6-10> Dexterity)',
'of Accuracy (+<11-15> Dexterity)',
'of Precision (+<16-20> Dexterity)',
),
'dexterity-suffix-jewelry' => array(
'[dexterity-suffix]',
'[dexterity-suffix]',
'[dexterity-suffix]',
'[dexterity-suffix]',
'[dexterity-suffix]',
'[dexterity-suffix]',
'[dexterity-suffix]',
'[dexterity-suffix]',
'[dexterity-suffix]',
'of Perfection (+<21-30> Dexterity)',
),
'unique-jewelry' => array(
'[jewelry]',
'[jewelry]',
'[jewelry]',
'[jewelry]',
'[jewelry]',
'[jewelry]',
'[jewelry]',
'[jewelry]',
'[unique-ring]',
'[unique-amulet]',
),
'unique-ring' => array(
'The Bleeder',
'The Bramble',
'Constricting Ring',
'Empyrean Band',
'Ring of Engagement',
'Ring of Regha',
),
'unique-amulet' => array(
'Optic Amulet',
),
);
}
}