shouldSync method
- Iterable<
SlashCommandBuilder> commands
override
Should the commands & perms be synced?
Implementation
@override
FutureOr<bool> shouldSync(Iterable<SlashCommandBuilder> commands) async {
File lockFile = File('./nyxx_interactions.lock');
Map<String, String> hashes = {
for (final command in commands) command.name: generateBuilderHash(command).bytes.map((e) => e.toRadixString(16)).join(),
};
if (!lockFile.existsSync()) {
lockFile.writeAsStringSync(jsonEncode(hashes));
return true;
}
try {
Map<String, String> lockFileContents = (jsonDecode(lockFile.readAsStringSync()) as Map<dynamic, dynamic>).cast<String, String>();
for (final entry in hashes.entries) {
if (lockFileContents[entry.key] != entry.value) {
return false;
}
}
} on FormatException {
lockFile.writeAsStringSync(jsonEncode(hashes));
return true;
}
return false;
}