diff --git a/CHANGELOG.md b/CHANGELOG.md index ef892da..3d72fe0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## 2.0.0 -- Add `!join` command +- Add `!play` command (optional, needs Lavalink) - Use `youtube_poll` - Remove `!vids` (it requires custom youtube logic and wasn't used) - Poll for videos on the side channels diff --git a/Dockerfile b/Dockerfile index b43ccc2..bd07466 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,5 +11,7 @@ COPY --from=build /runtime/ / COPY --from=build /app/bin/app /app/bin/ ENV JANA_DISCORD_TOKEN= +ENV JANA_LAVALINK_BASE=http://localhost:2333 +ENV JANA_LAVALINK_PASSWORD= CMD ["/app/bin/app"] diff --git a/README.md b/README.md index 3e6ca90..4b23e94 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ # jana -A new Discord bot for [the official chrissx Media Server](https://chrissx.de/discord) +Discord bot for [the official chrissx Media Server](https://chrissx.de/discord). + +```sh +# Without Lavalink +docker run -d --restart=unless-stopped --pull=always -e JANA_DISCORD_TOKEN=XXX chrissx/jana:latest + +# With Lavalink running on Network lavalink on localhost:2333 +docker run -d --restart=unless-stopped --pull=always --network lavalink -e JANA_DISCORD_TOKEN=XXX -e JANA_LAVALINK_BASE=http://localhost:2333 -e JANA_LAVALINK_PASSWORD=XXX chrissx/jana:latest + +# Example Lavalink setup +docker run -d --restart=unless-stopped --pull=always --network lavalink -e SERVER_PORT=2333 -e LAVALINK_SERVER_PASSWORD=XXX -v$PWD/application.yml:/opt/Lavalink/application.yml ghcr.io/lavalink-devs/lavalink:4 +``` diff --git a/bin/jana.dart b/bin/jana.dart index 10cd222..d07edf4 100644 --- a/bin/jana.dart +++ b/bin/jana.dart @@ -5,6 +5,7 @@ import 'dart:io'; import 'package:mutex/mutex.dart'; import 'package:nyxx/nyxx.dart'; import 'package:nyxx_extensions/nyxx_extensions.dart'; +import 'package:nyxx_lavalink/nyxx_lavalink.dart'; import 'package:youtube_explode_dart/youtube_explode_dart.dart'; import 'package:youtube_poll/youtube_poll.dart'; @@ -57,9 +58,18 @@ void main(List argv) async { exit(1); } + final lavalink = Platform.environment.containsKey('JANA_LAVALINK_BASE') && + Platform.environment.containsKey('JANA_LAVALINK_PASSWORD') + ? LavalinkPlugin( + base: Uri.parse(Platform.environment['JANA_LAVALINK_BASE']!), + password: Platform.environment['JANA_LAVALINK_PASSWORD']!, + ) + : null; + final bot = await Nyxx.connectGateway( token, GatewayIntents.allUnprivileged | GatewayIntents.messageContent, - options: GatewayClientOptions(plugins: [Logging(), CliIntegration()])); + options: GatewayClientOptions( + plugins: [logging, cliIntegration, if (lavalink != null) lavalink])); final logMutex = Mutex(); Message? lastLog; @@ -107,17 +117,22 @@ void main(List argv) async { (v) => channel.sendJson(json.encode(videoToJson(v)), '$id.json')); } }, - '!join': () async { - if (!member.roleIds.any(priv.contains)) throw 'Not authorized'; - //final file = await msg.attachments - // .firstWhere((a) => a.url.path.endsWith('.mp3')) - // .fetch(); - final voice = - await bot.voice.fetchVoiceState(event.guildId!, member.id); - final myState = GatewayVoiceStateBuilder( - channelId: voice.channelId, isMuted: false, isDeafened: false); - bot.updateVoiceState(event.guildId!, myState); - }, + if (lavalink != null) + '!play': () async { + if (!member.roleIds.any(priv.contains)) throw 'Not authorized'; + //final file = await msg.attachments + // .firstWhere((a) => a.url.path.endsWith('.mp3')) + // .fetch(); + //final voice = + // await bot.voice.fetchVoiceState(event.guildId!, member.id); + final voice = event.guild!.voiceStates[member.id]!; + final vc = await voice.channel!.fetch() as VoiceChannel; + final player = await vc.connectLavalink(); + await player.play(await lavalink + .loadTrack('https://gock.dev/email_empfangen.flac') + .then((v) => v.data)); + player.onTrackEnd.listen((e) => player.disconnect()); + }, }; final handler = commands[cmd]; @@ -131,6 +146,10 @@ void main(List argv) async { } }); + if (lavalink == null) { + log.warning('No Lavalink configured'); + } + Duration interval() { final target = DateTime(2000, 1, 1, 1, 0, 45); final now = DateTime.now().copyWith(year: 2000, month: 1, day: 1, hour: 0); diff --git a/pubspec.yaml b/pubspec.yaml index 1ef035c..0993031 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: jana description: A Discord bot -version: 1.6.0-alpha.4 +version: 2.0.0-beta.1 homepage: https://github.com/chrissxMedia/jana environment: @@ -14,6 +14,7 @@ dependencies: mutex: ^3.0.0 nyxx: ^6.0.0 nyxx_extensions: ^4.0.0 + nyxx_lavalink: ^4.0.0-dev.1 youtube_explode_dart: ^2.0.0 youtube_poll: ^0.2.0