From eb18dba65484676c40ec50bcf12f4a1423ede9ff Mon Sep 17 00:00:00 2001 From: Szymon Uglis Date: Thu, 17 Oct 2024 21:59:50 +0200 Subject: [PATCH] Clean up code --- lib/src/checks.dart | 2 +- lib/src/commands/jellyfin.dart | 15 --------------- lib/src/util/util.dart | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/src/checks.dart b/lib/src/checks.dart index d57c26b..3c71280 100644 --- a/lib/src/checks.dart +++ b/lib/src/checks.dart @@ -46,6 +46,6 @@ final jellyfinFeatureCreateInstanceCommandCheck = Check( final roleId = Snowflake.parse(setting!.dataAsJson!['create_instance_role']); - return context.member!.roleIds.contains(roleId); + return (context.member?.permissions?.isAdministrator ?? false) || context.member!.roleIds.contains(roleId); }, ); diff --git a/lib/src/commands/jellyfin.dart b/lib/src/commands/jellyfin.dart index 38f7ec8..dafbb5f 100644 --- a/lib/src/commands/jellyfin.dart +++ b/lib/src/commands/jellyfin.dart @@ -1,7 +1,6 @@ import 'dart:async'; import 'package:collection/collection.dart'; -import 'package:human_duration_parser/human_duration_parser.dart'; import 'package:injector/injector.dart'; import 'package:intl/intl.dart'; import 'package:nyxx/nyxx.dart'; @@ -18,20 +17,6 @@ import 'package:tentacle/tentacle.dart'; final taskProgressFormat = NumberFormat("0.00"); -Iterable spliceEmbedsForMessageBuilders(Iterable embeds, [int sliceSize = 2]) sync* { - for (final splicedEmbeds in embeds.slices(sliceSize)) { - yield MessageBuilder(embeds: splicedEmbeds); - } -} - -Duration? getDurationFromStringOrDefault(String? durationString, Duration? defaultDuration) { - if (durationString == null) { - return defaultDuration; - } - - return parseStringToDuration(durationString) ?? defaultDuration; -} - String? valueOrNullIfNotDefault(String? value, [String ifNotDefault = 'Unlimited']) { if (value == ifNotDefault) { return null; diff --git a/lib/src/util/util.dart b/lib/src/util/util.dart index 81363b0..04e4fe3 100644 --- a/lib/src/util/util.dart +++ b/lib/src/util/util.dart @@ -1,6 +1,8 @@ import 'dart:io'; import 'dart:math'; +import 'package:collection/collection.dart'; +import 'package:human_duration_parser/human_duration_parser.dart'; import 'package:nyxx/nyxx.dart'; final random = Random(); @@ -42,3 +44,17 @@ String? valueOrNull(String? value) { String generateRandomString(int length) => String.fromCharCodes(Iterable.generate(length, (_) => _chars.codeUnitAt(random.nextInt(_chars.length)))) .toUpperCase(); + +Iterable spliceEmbedsForMessageBuilders(Iterable embeds, [int sliceSize = 2]) sync* { + for (final splicedEmbeds in embeds.slices(sliceSize)) { + yield MessageBuilder(embeds: splicedEmbeds); + } +} + +Duration? getDurationFromStringOrDefault(String? durationString, Duration? defaultDuration) { + if (durationString == null) { + return defaultDuration; + } + + return parseStringToDuration(durationString) ?? defaultDuration; +} \ No newline at end of file