Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
l7ssha committed Oct 17, 2024
1 parent 6d0689b commit eb18dba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion lib/src/checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
);
15 changes: 0 additions & 15 deletions lib/src/commands/jellyfin.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -18,20 +17,6 @@ import 'package:tentacle/tentacle.dart';

final taskProgressFormat = NumberFormat("0.00");

Iterable<MessageBuilder> spliceEmbedsForMessageBuilders(Iterable<EmbedBuilder> 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;
Expand Down
16 changes: 16 additions & 0 deletions lib/src/util/util.dart
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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<MessageBuilder> spliceEmbedsForMessageBuilders(Iterable<EmbedBuilder> 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;
}

0 comments on commit eb18dba

Please sign in to comment.