Skip to content

Commit

Permalink
Validate json before saving to db
Browse files Browse the repository at this point in the history
  • Loading branch information
l7ssha committed Nov 18, 2024
1 parent 339955c commit e9e896b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/src/commands/feature_settings.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:convert';

import 'package:collection/collection.dart';
import 'package:injector/injector.dart';
import 'package:nyxx/nyxx.dart';
Expand Down Expand Up @@ -27,8 +29,16 @@ final featureSettings = ChatGroup(
description: 'The setting `${setting.name}` requires the `data` argument to be specified.'
' Please re-run the command and specify the additional data required, or contact a developer for more details.');

await context.respond(MessageBuilder(embeds: [embed]));
return;
return context.respond(MessageBuilder(embeds: [embed]));
}

if (setting.type == DataType.json) {
try {
final decodedData = jsonDecode(data!);
data = jsonEncode(decodedData);
} on FormatException {
return context.respond(MessageBuilder(content: 'Setting requires valid json as data'));
}
}

final featureSetting = FeatureSetting(
Expand All @@ -41,7 +51,7 @@ final featureSettings = ChatGroup(

await Injector.appInstance.get<FeatureSettingsModule>().enable(featureSetting);

await context.respond(MessageBuilder(content: 'Successfully enabled setting!'));
return context.respond(MessageBuilder(content: 'Successfully enabled setting!'));
}),
),
ChatCommand(
Expand Down

0 comments on commit e9e896b

Please sign in to comment.