Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Commit

Permalink
Fixes '--fix-ssl-permissions' errors mistakenly parsed as blockchain …
Browse files Browse the repository at this point in the history
…version

farmrBot: splits messages every 4096 characters
  • Loading branch information
gilnobrega committed Jan 3, 2022
1 parent 0ff64a1 commit 9115b6d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion environment_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ environment_config:
fields: # set of fields for command
version: # key name
const: true # optional, default to TRUE
default: 1.7.7.3 # optional, default value for key, if not provided key will be required during command run
default: 1.7.7.4 # optional, default value for key, if not provided key will be required during command run
dotenv: true # optional, default to FALSE, if this field should be added to .env file

7 changes: 6 additions & 1 deletion lib/harvester/harvester.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ class Harvester
.stdout
.toString()
.trim();

if (_blockchainVersion.length > 32 && _blockchainVersion.contains("\n"))
_blockchainVersion = _blockchainVersion.split("\n").last;
} catch (error) {
log.warning("Failed to get ${blockchain.binaryName} version");
}
Expand Down Expand Up @@ -190,8 +193,10 @@ class Harvester
//loads version from json
if (object['version'] != null) _version = object['version'];

if (object['blockchainVersion'] != null)
if (object['blockchainVersion'] != null) {
_blockchainVersion = object['blockchainVersion'];
if (_blockchainVersion.length > 32) _blockchainVersion = "N/A";
}

loadDisksFromJson(object);

Expand Down
30 changes: 24 additions & 6 deletions server/farmr_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ Future<void> main(List<String> args) async {
.where((client) => (client is Farmer || client is HPool))
.first as Farmer; //Selects newest farm as main farm

List<String> lines = [];

if (args.contains("workers")) {
//Sorts workers by alphabetical order
harvesters.sort((harvester1, harvester2) =>
Expand All @@ -158,7 +160,7 @@ Future<void> main(List<String> args) async {
harvester.filterDuplicates(false);
harvester.sortPlots();

print(Stats.showHarvester(
lines.add(Stats.showHarvester(
harvester,
harvestersCount,
farmersCount,
Expand All @@ -170,8 +172,6 @@ Future<void> main(List<String> args) async {
(blockchain == "xch")
? price.rates[harvester.currency]
: Price().rates[harvester.currency]));

if (harvester != harvesters.last) print(';;');
}
} else {
//Sorts harvesters by farmer/harvester type
Expand All @@ -189,11 +189,10 @@ Future<void> main(List<String> args) async {

if (args.contains("wallets")) {
for (Wallet wallet in farm.wallets) {
print(Stats.showWalletInfo(wallet, blockchain));
if (wallet != farm.wallets.last) print(';;');
lines.add(Stats.showWalletInfo(wallet, blockchain));
}
} else
print(Stats.showHarvester(
lines.add(Stats.showHarvester(
farm,
harvestersCount,
farmersCount,
Expand All @@ -206,6 +205,25 @@ Future<void> main(List<String> args) async {
? price.rates[farm.currency]
: Price().rates[farm.currency]));
}

const discordLimit = 4000; //actually 4096

for (var line in lines) {
if (line.length < discordLimit) {
print(line);
if (line != lines.last) print(';;');
//splits line into two discord messages if longer than 4000 characters
} else {
RegExp exp = new RegExp(r"\d{" + "$discordLimit}");
var matches = exp.allMatches(line);
var list = matches.map((m) => m.group(0) ?? "");

for (String splitLine in list) {
print(splitLine);
if (splitLine != list.last) print(';;');
}
}
}
} catch (Exception) {
if (farmersCount == 0) print("Error: Farmer not found.");
if (harvesters.length > 0)
Expand Down

0 comments on commit 9115b6d

Please sign in to comment.