Skip to content

Commit

Permalink
Merge pull request #1 from PandaGuerrier/PandaGuerrier-bulkDelete
Browse files Browse the repository at this point in the history
🚀 Add bulkDelete method
  • Loading branch information
PandaGuerrier authored Jan 8, 2023
2 parents c0534d5 + 12f8924 commit 2bc8acc
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/src/api/channels/text_based_channel.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import 'package:mineral/core/api.dart';
import 'package:mineral/src/api/builders/channel_builder.dart';
import 'package:mineral/src/api/managers/webhook_manager.dart';
import 'package:http/http.dart';
import 'package:mineral_ioc/ioc.dart';
import 'package:mineral/core.dart';
import 'package:mineral_cli/mineral_cli.dart';

class TextBasedChannel extends PartialTextChannel {
final bool _nsfw;
Expand Down Expand Up @@ -31,4 +35,25 @@ class TextBasedChannel extends PartialTextChannel {
Future<void> setNsfw (bool value) async {
await update(ChannelBuilder({ 'nsfw': value }));
}

Future<void> bulkDelete(double number) async {
if (number > 200) {
return ioc.use<MineralCli>().console.error('The number $number is too high, and exceeds the limit of 200 maximum messages');
}

final Map<Snowflake, Message> messagesFetch = await messages.fetch();
List<Snowflake> msg = [];

int i = 0;
for (Message message in messagesFetch.values) {
if(i <= number - 1) {
msg.add(message.id);
i++;
}
}

await ioc.use<HttpService>().post(url: "/channels/${id}/messages/bulk-delete", payload: {
'messages': msg
});
}
}

0 comments on commit 2bc8acc

Please sign in to comment.