Skip to content

Commit

Permalink
Fix /reminder list command; Release 3.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
l7ssha committed Jun 11, 2023
1 parent caab494 commit c69f62a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 97 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.2.3

- Fix `/reminder list` command

## 3.2.2

- Fixup build
Expand Down
97 changes: 31 additions & 66 deletions lib/src/commands/music.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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],
Expand All @@ -70,19 +47,17 @@ 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],
id('music-stop', (IChatContext context) async {
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],
Expand All @@ -91,59 +66,49 @@ 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],
id('music-join', (IChatContext context) async {
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<void> 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);
}
}
61 changes: 32 additions & 29 deletions lib/src/commands/reminder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion lib/src/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit c69f62a

Please sign in to comment.