Skip to content

Commit

Permalink
feat: nyxx bump (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomassasovsky authored Oct 27, 2024
1 parent 1fa14d5 commit 554645e
Show file tree
Hide file tree
Showing 42 changed files with 2,581 additions and 3,037 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ coverage/
/shazam_api/__pycache__
/shazam_api/pyvenv.cfg
/shazam_api/pyvenv.cfg
.DS_Store
.DS_Store

output.lavalink.yml
2 changes: 2 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ linter:
public_member_api_docs: false

analyzer:
errors:
cascade_invocations: ignore
exclude:
- "**/*.g.dart"
- "**/*.freezed.dart"
90 changes: 47 additions & 43 deletions bin/radio_horizon_development.dart
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
// Copyright (c) 2022, Tomás Sasovsky
// Copyright (c) 2024, Tomás Sasovsky
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

import 'package:get_it/get_it.dart';
import 'package:injector/injector.dart';
import 'package:nyxx/nyxx.dart';
import 'package:nyxx_commands/nyxx_commands.dart';
import 'package:nyxx_lavalink/nyxx_lavalink.dart';
import 'package:radio_horizon/radio_horizon.dart';
import 'package:shazam_client/shazam_client.dart';

final getIt = GetIt.instance;

Future<void> main() async {
dotEnvFlavour = DotEnvFlavour.development;
dotEnvFlavour.initialize();

// Create nyxx client and nyxx_commands plugin
final client = NyxxFactory.createNyxxWebsocket(token, intents);

final commands = CommandsPlugin(
prefix: mentionOr((_) => prefix),
options: const CommandsOptions(
logErrors: false,
prefix: null,
guild: devGuildId,
options: CommandsOptions(logErrors: dev),
);

final lavalinkClient = await LavalinkClient.connect(
Uri(
host: lavalinkAddress,
port: lavalinkPort,
scheme: lavalinkUseSSL ? 'https' : 'http',
),
)
password: lavalinkPassword,
userId: clientId.toString(),
);

final lavalinkPlugin = LavalinkPlugin.usingClient(lavalinkClient);

commands
..addCommand(info)
..addCommand(skip)
..addCommand(stop)
Expand All @@ -34,40 +43,35 @@ Future<void> main() async {
..addCommand(resume)
..addCommand(volume)
..addCommand(music)
..addCommand(radio)
..onCommandError.listen(commandErrorHandler);

client
..registerPlugin(
Logging(
logLevel: Level.FINE,
truncateLogsAt: 10000,
),
)
..registerPlugin(CliIntegration())
..registerPlugin(IgnoreExceptions())
..registerPlugin(commands);
..addCommand(radio);

final databaseService = DatabaseService(client);
await databaseService.initialize();
commands.onCommandError.listen(commandErrorHandler);

final musicService = MusicService(client);
final bootupService =
BootUpService(client: client, databaseService: databaseService);
final songRecognitionService =
SongRecognitionService(ShazamClient.dockerized());

getIt
..registerSingleton<MusicService>(musicService)
..registerSingleton<DatabaseService>(databaseService)
..registerSingleton<BootUpService>(bootupService)
..registerSingleton<SongRecognitionService>(songRecognitionService);
final client = await Nyxx.connectGateway(
token,
intents,
options: GatewayClientOptions(
plugins: [
Logging(),
CliIntegration(),
IgnoreExceptions(),
commands,
lavalinkPlugin,
],
),
);

client.onReady.listen((_) async {
await musicService.initialize();
await bootupService.initialize(musicService.cluster);
});
Injector.appInstance
..registerSingleton(() => client)
..registerSingleton(DatabaseService.new)
..registerSingleton(BootUpService.new)
..registerSingleton(ShazamClient.dockerized)
..registerSingleton(SongRecognitionService.new)
..registerSingleton(BotStartDuration.new)
..registerSingleton(() => lavalinkClient)
..registerSingleton(() => lavalinkPlugin);

// Connect
await client.connect();
await Injector.appInstance.get<BotStartDuration>().init();
await Injector.appInstance.get<DatabaseService>().init();
await Injector.appInstance.get<BootUpService>().init();
}
88 changes: 48 additions & 40 deletions bin/radio_horizon_production.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@

import 'dart:async';

import 'package:get_it/get_it.dart';
import 'package:logging/logging.dart';
import 'package:injector/injector.dart';
import 'package:nyxx/nyxx.dart';
import 'package:nyxx_commands/nyxx_commands.dart';
import 'package:nyxx_lavalink/nyxx_lavalink.dart';
import 'package:radio_horizon/radio_horizon.dart';
import 'package:sentry/sentry.dart';
import 'package:sentry_logging/sentry_logging.dart';
import 'package:shazam_client/shazam_client.dart';

final getIt = GetIt.instance;

Future<void> main() async {
await runZonedGuarded(() async {
dotEnvFlavour = DotEnvFlavour.production;
Expand All @@ -37,8 +35,17 @@ Future<void> main() async {
},
);

// Create nyxx client and nyxx_commands plugin
final client = NyxxFactory.createNyxxWebsocket(token, intents);
final lavalinkClient = await LavalinkClient.connect(
Uri(
host: lavalinkAddress,
port: lavalinkPort,
scheme: lavalinkUseSSL ? 'https' : 'http',
),
password: lavalinkPassword,
userId: clientId.toString(),
);

final lavalinkPlugin = LavalinkPlugin.usingClient(lavalinkClient);

final commands = CommandsPlugin(
prefix: mentionOr((_) => prefix),
Expand All @@ -47,44 +54,45 @@ Future<void> main() async {
),
)
..addCommand(info)
..addCommand(skip)
..addCommand(stop)
..addCommand(join)
..addCommand(leave)
..addCommand(pause)
..addCommand(resume)
..addCommand(volume)
..addCommand(music)
..addCommand(radio)
..onCommandError.listen(commandErrorHandler);
// ..addCommand(skip)
// ..addCommand(stop)
// ..addCommand(join)
// ..addCommand(leave)
// ..addCommand(pause)
// ..addCommand(resume)
// ..addCommand(volume)
..addCommand(music);
// ..addCommand(radio);

client
..registerPlugin(CliIntegration())
..registerPlugin(IgnoreExceptions())
..registerPlugin(commands);
commands.onCommandError.listen(commandErrorHandler);

final databaseService = DatabaseService(client);
await databaseService.initialize();

final musicService = MusicService(client);
final bootupService =
BootUpService(client: client, databaseService: databaseService);
final songRecognitionService =
SongRecognitionService(ShazamClient.dockerized());

getIt
..registerSingleton<MusicService>(musicService)
..registerSingleton<DatabaseService>(databaseService)
..registerSingleton<BootUpService>(bootupService)
..registerSingleton<SongRecognitionService>(songRecognitionService);
final client = await Nyxx.connectGateway(
token,
intents,
options: GatewayClientOptions(
plugins: [
Logging(),
CliIntegration(),
IgnoreExceptions(),
commands,
lavalinkPlugin,
],
),
);

client.onReady.listen((_) async {
await musicService.initialize();
await bootupService.initialize(musicService.cluster);
});
Injector.appInstance
..registerSingleton(() => client)
..registerSingleton(DatabaseService.new)
..registerSingleton(BootUpService.new)
..registerSingleton(ShazamClient.dockerized)
..registerSingleton(SongRecognitionService.new)
..registerSingleton(BotStartDuration.new)
..registerSingleton(() => lavalinkClient)
..registerSingleton(() => lavalinkPlugin);

// Connect
await client.connect();
await Injector.appInstance.get<BotStartDuration>().init();
await Injector.appInstance.get<DatabaseService>().init();
await Injector.appInstance.get<BootUpService>().init();
}, (exception, stackTrace) async {
Logger('main').severe(
'Uncaught exception when initialising the bot',
Expand Down
30 changes: 22 additions & 8 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ services:
radio_horizon:
image: ghcr.io/tomassasovsky/radio-horizon.dart:latest
container_name: radio_horizon
restart: unless-stopped
expose:
- 8080
env_file:
- .env/.env.production
- .env/.env.development
links:
- lavalink
- shazam_api
Expand All @@ -14,20 +15,33 @@ services:
- shazam_api

lavalink:
image: ghcr.io/lavalink-devs/lavalink:3
image: ghcr.io/lavalink-devs/lavalink:4
container_name: lavalink
restart: always
restart: unless-stopped
expose:
- 2333
volumes:
- ./lavalink.yml:/opt/Lavalink/application.yml
- ./output.lavalink.yml:/opt/Lavalink/application.yml
depends_on:
update_lavalink_config:
condition: service_completed_successfully

shazam_api:
build:
context: ./shazam_api
image: ghcr.io/tomassasovsky/shazam_api:latest
container_name: shazam_api
restart: unless-stopped
expose:
- 5000
volumes:
- ./shazam_api:/app
environment:
FLASK_ENV: production

update_lavalink_config:
image: ghcr.io/tomassasovsky/update-lavalink-config:latest
container_name: update_lavalink_config
restart: no
volumes:
- ./lavalink.yml:/app/lavalink.yml
- ./:/output-dir
env_file:
- .env/.env.development
command: ["--input", "lavalink.yml", "--output", "/output-dir/output.lavalink.yml"]
21 changes: 17 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,33 @@ services:
- shazam_api

lavalink:
image: ghcr.io/lavalink-devs/lavalink:3
image: ghcr.io/lavalink-devs/lavalink:4
container_name: lavalink
restart: always
expose:
- 2333
volumes:
- ./lavalink.yml:/opt/Lavalink/application.yml
- ./output.lavalink.yml:/opt/Lavalink/application.yml
depends_on:
update_lavalink_config:
condition: service_completed_successfully

shazam_api:
build:
context: ./shazam_api
expose:
- 5000
volumes:
- ./shazam_api:/app
environment:
FLASK_ENV: development

update_lavalink_config:
build:
context: ./custom_lavalink
container_name: update_lavalink_config
restart: no
volumes:
- ./lavalink.yml:/app/lavalink.yml
- ./:/output-dir
env_file:
- .env/.env.development
command: ["--input", "lavalink.yml", "--output", "/output-dir/output.lavalink.yml"]
Loading

0 comments on commit 554645e

Please sign in to comment.