Skip to content

Commit

Permalink
fix: client id missing (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomassasovsky authored Oct 27, 2024
1 parent 554645e commit febb50f
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 44 deletions.
31 changes: 16 additions & 15 deletions bin/radio_horizon_production.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ Future<void> main() async {
},
);

final commands = CommandsPlugin(
prefix: null,
guild: devGuildId,
options: CommandsOptions(logErrors: dev),
);

final lavalinkClient = await LavalinkClient.connect(
Uri(
host: lavalinkAddress,
Expand All @@ -47,22 +53,17 @@ Future<void> main() async {

final lavalinkPlugin = LavalinkPlugin.usingClient(lavalinkClient);

final commands = CommandsPlugin(
prefix: mentionOr((_) => prefix),
options: const CommandsOptions(
logErrors: false,
),
)
commands
..addCommand(info)
// ..addCommand(skip)
// ..addCommand(stop)
// ..addCommand(join)
// ..addCommand(leave)
// ..addCommand(pause)
// ..addCommand(resume)
// ..addCommand(volume)
..addCommand(music);
// ..addCommand(radio);
..addCommand(skip)
..addCommand(stop)
..addCommand(join)
..addCommand(leave)
..addCommand(pause)
..addCommand(resume)
..addCommand(volume)
..addCommand(music)
..addCommand(radio);

commands.onCommandError.listen(commandErrorHandler);

Expand Down
15 changes: 0 additions & 15 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ services:
- 2333
volumes:
- ./output.lavalink.yml:/opt/Lavalink/application.yml
depends_on:
update_lavalink_config:
condition: service_completed_successfully

shazam_api:
build:
Expand All @@ -35,15 +32,3 @@ services:
- 5000
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"]
8 changes: 1 addition & 7 deletions lib/src/settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ final bool dev = getEnvBool('RG_DEV');
final devGuildId = dev ? Snowflake.parse(getEnv('RG_DEV_GUILD_ID')) : null;

/// The bot's app id.
final clientId = dev ? Snowflake.parse(getEnv('CLIENT_ID')) : null;
final clientId = Snowflake.parse(getEnv('CLIENT_ID'));

/// The address of the lavalink running server to connect to.
String lavalinkAddress = getEnv('LAVALINK_ADDRESS');
Expand All @@ -82,12 +82,6 @@ String lavalinkPassword = getEnv('LAVALINK_PASSWORD');
/// Whether to use or not ssl to establish a connection.
bool lavalinkUseSSL = getEnvBool('LAVALINK_USE_SSL', def: false);

/// The api key for the song recognition service, in Rapid Api.
///
/// Find yours in https://rapidapi.com/mirzahadjaevaguzal/api/shazam-song-recognizer
String rapidapiShazamSongRecognizerKey =
getEnv('RAPIDAPI_SHAZAM_SONG_RECOGNIZER_KEY');

/// The Sentry DSN to use for this instance.
String sentryDsn = getEnv('SENTRY_DSN');

Expand Down
8 changes: 4 additions & 4 deletions portainer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ services:
depends_on:
- lavalink
- shazam_api
# mount a volume for the .env file
volumes:
- /server/docker/radiohorizon/config/.env:/app/.env

Expand All @@ -20,9 +19,10 @@ services:
container_name: update_lavalink_config
restart: no
volumes:
- /server/docker/radiohorizon/config/:/output-dir
- /server/docker/radiohorizon/config/.env:/app/.env
- /server/docker/radiohorizon/config:/output-dir
command:
["--input", "lavalink.yml", "--output", "/output-dir/output.lavalink.yml"]
["--input", "/output-dir/lavalink.yml", "--output", "/output-dir/output.lavalink.yml", "--env", "production"]

lavalink:
image: ghcr.io/lavalink-devs/lavalink:4
Expand All @@ -31,7 +31,7 @@ services:
expose:
- 2333
volumes:
- /server/docker/radiohorizon/config/lavalink.yml:/opt/Lavalink/application.yml
- /server/docker/radiohorizon/config/output.lavalink.yml:/opt/Lavalink/application.yml
depends_on:
update_lavalink_config:
condition: service_completed_successfully
Expand Down
2 changes: 1 addition & 1 deletion update_lavalink_config/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ COPY . /app
RUN dart pub get

# Compile the Dart script to a native executable (optional but recommended)
RUN dart compile exe update_lavalink_config.dart -o update_lavalink_config
RUN dart compile exe bin/update_lavalink_config.dart -o update_lavalink_config

# Set the entrypoint to the compiled executable
ENTRYPOINT ["./update_lavalink_config"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:io';

import 'package:args/args.dart';
import 'package:custom_lavalink/dotenv.dart';
import 'package:yaml_edit/yaml_edit.dart';

// A tool that automatically edits the lavalink.yml file to populate the
Expand Down Expand Up @@ -46,6 +47,13 @@ void main(List<String> args) {
help: 'Deezer master decryption key. Will default to the '
'DEEZER_MASTER_DECRYPTION_KEY environment variable.',
)
..addOption(
'env',
abbr: 'e',
defaultsTo: 'none',
allowed: ['development', 'production', 'none'],
help: 'Environment to use. Defaults to "development"',
)
..addFlag(
'clear',
negatable: false,
Expand Down Expand Up @@ -73,10 +81,28 @@ void main(List<String> args) {
final inputFilePath = argResults['input'] as String;
final outputFilePath = argResults['output'] as String? ?? inputFilePath;

final env = argResults['env'] as String;

// Load the environment variables
if (env != 'none') {
if (env == 'development') {
dotEnvFlavour = DotEnvFlavour.development;
stdout.writeln('Loading environment variables from .env.development');
} else if (env == 'production') {
dotEnvFlavour = DotEnvFlavour.production;
stdout.writeln('Loading environment variables from .env.production');
}

dotEnvFlavour.initialize();
}

// Helper function to get environment variable or command-line argument
String? getEnvOrArg(String argName, String envName) {
if (clear) return null;
return argResults[argName] as String? ?? Platform.environment[envName];
return argResults[argName] as String? ??
dotEnvFlavour.dotenv[envName] ??
Platform.environment[envName] ??
String.fromEnvironment(envName);
}

// Retrieve the environment variables
Expand All @@ -89,6 +115,8 @@ void main(List<String> args) {
'DEEZER_MASTER_DECRYPTION_KEY',
);

stdout.writeln('Updating lavalink.yml file...');

// Ensure required variables are not null
if ((lavalinkPassword == null ||
youtubeOAuthRefreshToken == null ||
Expand Down Expand Up @@ -149,7 +177,10 @@ void main(List<String> args) {
final newContent = editor.toString();

final outputFile = File(outputFilePath);
outputFile.deleteSync(recursive: true);
if (outputFile.existsSync()) {
outputFile.deleteSync(recursive: true);
}

outputFile.createSync(recursive: true);

outputFile.writeAsStringSync(newContent);
Expand Down
29 changes: 29 additions & 0 deletions update_lavalink_config/lib/dotenv.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (c) 2022, 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:dotenv/dotenv.dart';
import 'package:logging/logging.dart';

enum DotEnvFlavour {
development('.env/.env.development'),
production('.env/.env.production');

const DotEnvFlavour(this.path);

final String path;
void initialize() {
try {
dotenv.load([path]);
} catch (_) {
Logger('DotEnv').warning('Failed to load $path');
}
}

DotEnv get dotenv => _dotEnv;
}

var _dotEnv = DotEnv(includePlatformEnvironment: true);
late DotEnvFlavour dotEnvFlavour;
2 changes: 2 additions & 0 deletions update_lavalink_config/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ environment:

dependencies:
args: ^2.6.0
dotenv: ^4.2.0
logging: ^1.3.0
yaml_edit: ^2.2.1

0 comments on commit febb50f

Please sign in to comment.