From c69f62abf242f268a8b7bc1309456c81dcc59802 Mon Sep 17 00:00:00 2001 From: Szymon Uglis Date: Sun, 11 Jun 2023 10:27:21 +0200 Subject: [PATCH] Fix /reminder list command; Release 3.2.3 --- CHANGELOG.md | 4 ++ lib/src/commands/music.dart | 97 +++++++++++----------------------- lib/src/commands/reminder.dart | 61 +++++++++++---------- lib/src/settings.dart | 2 +- pubspec.yaml | 2 +- 5 files changed, 69 insertions(+), 97 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25023fe..fc53505 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 3.2.3 + +- Fix `/reminder list` command + ## 3.2.2 - Fixup build diff --git a/lib/src/commands/music.dart b/lib/src/commands/music.dart index a26facc..299d599 100644 --- a/lib/src/commands/music.dart +++ b/lib/src/commands/music.dart @@ -3,22 +3,15 @@ import 'package:nyxx_commands/nyxx_commands.dart'; import 'package:running_on_dart/src/checks.dart'; import 'package:running_on_dart/running_on_dart.dart'; -ChatGroup music = ChatGroup( - 'music', - 'Music related commands', - checks: [ - GuildCheck.all(), - userConnectedToVoiceChannelCheck, - sameVoiceChannelOrDisconnectedCheck, - ], - children: [ - ChatCommand( +ChatGroup music = ChatGroup('music', 'Music related commands', checks: [ + GuildCheck.all(), + userConnectedToVoiceChannelCheck, + sameVoiceChannelOrDisconnectedCheck, +], children: [ + ChatCommand( 'play', 'Plays music based on the given query', - id('music-play', ( - IChatContext context, - @Description('The name/url of the song/playlist to play') String query - ) async { + id('music-play', (IChatContext context, @Description('The name/url of the song/playlist to play') String query) async { final node = MusicService.instance.cluster.getOrCreatePlayerNode(context.guild!.id); connectIfNeeded(context); final result = await node.autoSearch(query); @@ -30,32 +23,16 @@ ChatGroup music = ChatGroup( if (result.playlistInfo.name != null) { for (final track in result.tracks) { - node.play( - context.guild!.id, - track, - requester: context.member!.id, - channelId: context.channel.id - ).queue(); + node.play(context.guild!.id, track, requester: context.member!.id, channelId: context.channel.id).queue(); } - await context.respond(MessageBuilder.content( - 'Playlist `${result.playlistInfo.name}`($query) enqueued' - )); - + await context.respond(MessageBuilder.content('Playlist `${result.playlistInfo.name}`($query) enqueued')); } else { - node.play( - context.guild!.id, - result.tracks[0], - requester: context.member!.id, - channelId: context.channel.id - ).queue(); - await context.respond(MessageBuilder.content( - 'Track `${result.tracks[0].info?.title}` enqueued' - )); + node.play(context.guild!.id, result.tracks[0], requester: context.member!.id, channelId: context.channel.id).queue(); + await context.respond(MessageBuilder.content('Track `${result.tracks[0].info?.title}` enqueued')); } - }) - ), - ChatCommand( + })), + ChatCommand( 'skip', 'Skips the currently playing track', checks: [connectedToAVoiceChannelCheck], @@ -70,9 +47,8 @@ ChatGroup music = ChatGroup( node.skip(context.guild!.id); await context.respond(MessageBuilder.content('Skipped current track')); - }) - ), - ChatCommand( + })), + ChatCommand( 'stop', 'Stops the current player and clears its track queue', checks: [connectedToAVoiceChannelCheck], @@ -80,9 +56,8 @@ ChatGroup music = ChatGroup( final node = MusicService.instance.cluster.getOrCreatePlayerNode(context.guild!.id); node.stop(context.guild!.id); await context.respond(MessageBuilder.content('Player stopped!')); - }) - ), - ChatCommand( + })), + ChatCommand( 'leave', 'Leaves the current voice channel', checks: [connectedToAVoiceChannelCheck], @@ -91,9 +66,8 @@ ChatGroup music = ChatGroup( node.destroy(context.guild!.id); context.guild!.shard.changeVoiceState(context.guild!.id, null); await context.respond(MessageBuilder.content('Channel left')); - }) - ), - ChatCommand( + })), + ChatCommand( 'join', 'Joins the voice channel you are in', checks: [notConnectedToAVoiceChannelCheck], @@ -101,49 +75,40 @@ ChatGroup music = ChatGroup( MusicService.instance.cluster.getOrCreatePlayerNode(context.guild!.id); await connectIfNeeded(context); await context.respond(MessageBuilder.content('Joined your voice channel')); - }) - ), - ChatCommand( + })), + ChatCommand( 'volume', 'Sets the volume for the player', checks: [connectedToAVoiceChannelCheck], - id('music-volume', ( - IChatContext context, - @Description('The new volume, this value must be contained between 0 and 1000') @UseConverter(IntConverter(min: 0, max: 1000)) int volume - ) async { + id('music-volume', (IChatContext context, + @Description('The new volume, this value must be contained between 0 and 1000') @UseConverter(IntConverter(min: 0, max: 1000)) int volume) async { final node = MusicService.instance.cluster.getOrCreatePlayerNode(context.guild!.id); node.volume(context.guild!.id, volume); await context.respond(MessageBuilder.content('Volume changed to $volume')); - }) - ), - ChatCommand( + })), + ChatCommand( 'pause', 'Pauses the player', id('music-pause', (IChatContext context) async { final node = MusicService.instance.cluster.getOrCreatePlayerNode(context.guild!.id); node.pause(context.guild!.id); await context.respond(MessageBuilder.content('Player paused')); - }) - ), - ChatCommand( + })), + ChatCommand( 'resume', 'Resumes the currently playing track', id('music-resume', (IChatContext context) async { final node = MusicService.instance.cluster.getOrCreatePlayerNode(context.guild!.id); node.resume(context.guild!.id); await context.respond(MessageBuilder.content('Player resumed')); - }) - ) - ] -); + })) +]); Future connectIfNeeded(IChatContext context) async { final selfMember = await context.guild!.selfMember.getOrDownload(); - if ( - (selfMember.voiceState == null || selfMember.voiceState!.channel == null) && - (context.member!.voiceState != null && context.member!.voiceState!.channel != null) - ) { + if ((selfMember.voiceState == null || selfMember.voiceState!.channel == null) && + (context.member!.voiceState != null && context.member!.voiceState!.channel != null)) { context.guild!.shard.changeVoiceState(context.guild!.id, context.member!.voiceState!.channel!.id); } } diff --git a/lib/src/commands/reminder.dart b/lib/src/commands/reminder.dart index f272918..832a819 100644 --- a/lib/src/commands/reminder.dart +++ b/lib/src/commands/reminder.dart @@ -19,14 +19,12 @@ ChatGroup reminder = ChatGroup( ) async { final triggerAt = DateTime.now().add(offset); - final replyMessage = await context.respond( - MessageBuilder.content('Alright ') - ..appendMention(context.user) - ..append(', Creating reminder: ') - ..appendTimestamp(triggerAt, style: TimeStampStyle.relativeTime) - ..append(': ') - ..append(message) - ); + final replyMessage = await context.respond(MessageBuilder.content('Alright ') + ..appendMention(context.user) + ..append(', Creating reminder: ') + ..appendTimestamp(triggerAt, style: TimeStampStyle.relativeTime) + ..append(': ') + ..append(message)); await ReminderService.instance.addReminder(Reminder( userId: context.user.id, @@ -37,14 +35,12 @@ ChatGroup reminder = ChatGroup( message: message, )); - await replyMessage.edit( - MessageBuilder.content('Alright ') - ..appendMention(context.user) - ..append(', ') - ..appendTimestamp(triggerAt, style: TimeStampStyle.relativeTime) - ..append(': ') - ..append(message) - ); + await replyMessage.edit(MessageBuilder.content('Alright ') + ..appendMention(context.user) + ..append(', ') + ..appendTimestamp(triggerAt, style: TimeStampStyle.relativeTime) + ..append(': ') + ..append(message)); }), ), ChatCommand( @@ -74,21 +70,28 @@ ChatGroup reminder = ChatGroup( id('reminder-list', (IChatContext context) async { final reminders = ReminderService.instance.getUserReminders(context.user.id).toList()..sort((a, b) => a.triggerAt.compareTo(b.triggerAt)); + final entries = reminders.asMap().entries.map((entry) { + final index = entry.key; + final reminder = entry.value; + + return EmbedBuilder() + ..color = getRandomColor() + ..title = 'Reminder ${index + 1} of ${reminders.length}' + ..addField( + name: 'Triggers at', + content: '${TimeStampStyle.longDateTime.format(reminder.triggerAt)} (${TimeStampStyle.relativeTime.format(reminder.triggerAt)})', + ) + ..addField(name: 'Content', content: reminder.message.length > 2048 ? reminder.message.substring(0, 2045) + '...' : reminder.message); + }).toList(); + + if (entries.isEmpty) { + await context.respond(MessageBuilder.content("No reminders!")); + return; + } + final paginator = EmbedComponentPagination( context.commands.interactions, - reminders.asMap().entries.map((entry) { - final index = entry.key; - final reminder = entry.value; - - return EmbedBuilder() - ..color = getRandomColor() - ..title = 'Reminder ${index + 1} of ${reminders.length}' - ..addField( - name: 'Triggers at', - content: '${TimeStampStyle.longDateTime.format(reminder.triggerAt)} (${TimeStampStyle.relativeTime.format(reminder.triggerAt)})', - ) - ..addField(name: 'Content', content: reminder.message.length > 2048 ? reminder.message.substring(0, 2045) + '...' : reminder.message); - }).toList(), + entries, ); await context.respond(paginator.initMessageBuilder()); diff --git a/lib/src/settings.dart b/lib/src/settings.dart index af8f3c8..dba3a9c 100644 --- a/lib/src/settings.dart +++ b/lib/src/settings.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:nyxx/nyxx.dart'; -String get version => '3.2.2'; +String get version => '3.2.3'; /// Get a [String] from an environment variable, throwing an exception if it is not set. /// diff --git a/pubspec.yaml b/pubspec.yaml index bba960c..b0659f8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: running_on_dart -version: 3.2.2 +version: 3.2.3 description: Discord Bot for nyxx development homepage: https://github.com/nyxx-discord/running_on_dart repository: https://github.com/nyxx-discord/running_on_dart