├── CHANGELOG.md ├── Procfile ├── heroku.yml ├── .dockerignore ├── .github └── ISSUE_TEMPLATE │ └── custom.md ├── src ├── notifiers │ ├── time.notifier.dart │ ├── on_ready.notifier.dart │ ├── login.notifier.dart │ └── on_msg.notifier.dart ├── events │ ├── interations │ │ └── button.interation.dart │ └── music.event.dart ├── services │ ├── custom_print.util.dart │ ├── logs.dart │ └── load_env.util.dart ├── utils │ ├── constants.util.dart │ └── colors.util.dart └── commands │ └── commands.dart ├── Dockerfile ├── pubspec.yaml ├── .vscode └── launch.json ├── .gitpod.dockerfile ├── .markdownlint.json ├── .gitpod.yml ├── Makefile ├── LICENSE ├── bin └── flutter_bot.dart ├── .gitignore ├── analysis_options.yaml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md └── README.md /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.0 2 | 3 | - Initial version. 4 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | worker: ./dart-sdk/bin/dart ./bin/flutter_bot.dart -------------------------------------------------------------------------------- /heroku.yml: -------------------------------------------------------------------------------- 1 | build: 2 | docker: 3 | web: Dockerfile -------------------------------------------------------------------------------- /.dockerignore: -------------------------------------------------------------------------------- 1 | Dockerfile 2 | build/ 3 | .dart_tool/ 4 | .git/ 5 | .github/ 6 | .gitignore 7 | .packages 8 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/custom.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Custom issue template 3 | about: Describe this issue template's purpose here. 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 11 | -------------------------------------------------------------------------------- /src/notifiers/time.notifier.dart: -------------------------------------------------------------------------------- 1 | class Time { 2 | String msToMin(int millis) { 3 | int minutes = (millis / 60000).floor(); 4 | int seconds = ((millis % 60000) / 1000).floor(); 5 | return '$minutes : $seconds'; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM google/dart:latest as builder 2 | 3 | WORKDIR /app 4 | 5 | ADD pubspec.* /app/ 6 | RUN pub get 7 | 8 | ADD . /app/ 9 | RUN pub get --offline 10 | 11 | RUN dart compile exe bin/flutter_bot.dart 12 | 13 | FROM subfuzion/dart:slim 14 | 15 | WORKDIR /app 16 | COPY --from=builder /app/bin/flutter_bot.exe /app 17 | 18 | CMD [ "/app/bin/flutter_bot.exe" ] -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_bot 2 | description: A simple command-line application. 3 | version: 1.0.0 4 | # homepage: https://www.example.com 5 | environment: 6 | sdk: ">=2.15.0 <3.0.0" 7 | 8 | # dependencies: 9 | # path: ^1.8.0 10 | dev_dependencies: 11 | lints: ^2.0.1 12 | dependencies: 13 | dotenv: ^4.0.1 14 | http: ^0.13.5 15 | intl: ^0.17.0 16 | nyxx: ^4.3.0 17 | nyxx_interactions: ^4.4.0 18 | riverpod: ^2.1.1 19 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | "version": "0.2.0", 6 | "configurations": [ 7 | { 8 | "name": "flutter_bot", 9 | "request": "launch", 10 | "type": "dart", 11 | "program": "./bin/flutter_bot.dart", 12 | } 13 | ] 14 | } -------------------------------------------------------------------------------- /src/events/interations/button.interation.dart: -------------------------------------------------------------------------------- 1 | import 'package:nyxx_interactions/nyxx_interactions.dart'; 2 | 3 | import '../../services/logs.dart'; 4 | 5 | Future buttonInteraction(IButtonInteractionEvent event) async { 6 | try { 7 | /// Get the interaction ID 8 | // String id = event.interaction.customId; 9 | 10 | /// Get the Guild ID 11 | // IGuild? guild = event.interaction.message!.client.guilds.; 12 | 13 | } catch (e) { 14 | BotLogger.logln(LogType.error, e.toString()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /.gitpod.dockerfile: -------------------------------------------------------------------------------- 1 | ############################################################################################ 2 | # DO NOT EDIT THIS DOCKER FILE AND PUSH. THIS IS CUSTOM MADE DOCKER. # 3 | ############################################################################################ 4 | FROM gitpod/workspace-full 5 | 6 | ENV PATH=/usr/lib/dart/bin:$PATH 7 | 8 | USER root 9 | 10 | RUN curl -fsSL https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \ 11 | && curl -fsSL https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list \ 12 | && install-packages build-essential dart libkrb5-dev gcc make -------------------------------------------------------------------------------- /.markdownlint.json: -------------------------------------------------------------------------------- 1 | { 2 | "default": true, 3 | "MD003": { 4 | "style": "atx_closed" 5 | }, 6 | "MD007": { 7 | "indent": 4 8 | }, 9 | "MD013": { 10 | "line_length": 700 11 | }, 12 | "MD026": false, 13 | "MD033": { 14 | "allowed_elements": [ 15 | "a", 16 | "br", 17 | "div", 18 | "h1", 19 | "h2", 20 | "h3", 21 | "h4", 22 | "img", 23 | "p", 24 | "path", 25 | "svg" 26 | ] 27 | }, 28 | "MD034": false, 29 | "MD036": false, 30 | "MD041": false, 31 | "MD047": false, 32 | "no-hard-tabs": false 33 | } -------------------------------------------------------------------------------- /.gitpod.yml: -------------------------------------------------------------------------------- 1 | image: 2 | file: .gitpod.dockerfile 3 | 4 | github: 5 | prebuilds: 6 | # enable for the master/default branch 7 | master: true 8 | # enable for all branches in this repo 9 | branches: true 10 | # enable for pull requests coming from this repo 11 | pullRequests: true 12 | # enable for pull requests coming from forks 13 | pullRequestsFromForks: true 14 | # add a check to pull requests 15 | addCheck: true 16 | # add a "Review in Gitpod" button as a comment to pull requests 17 | addComment: true 18 | # add a "Review in Gitpod" button to the pull request's description 19 | addBadge: true 20 | # add a label once the prebuild is ready to pull requests 21 | addLabel: true -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: help 2 | help: 3 | @fgrep -h "##" $(MAKEFILE_LIST) | sed -e 's/\(\:.*\#\#\)/\:\ /' | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//' 4 | 5 | .PHONY: build 6 | build: ## build images 7 | docker build . 8 | 9 | .PHONY: build-no-cache 10 | build-no-cache: ## build images discarding cache 11 | docker build . 12 | 13 | .PHONY: stop 14 | stop: ## stop images 15 | docker compose down 16 | 17 | .PHONY: start 18 | start: ## start images from docker compose 19 | docker compose up 20 | 21 | .PHONY: clean 22 | clean: stop ## clean container created by docker compose 23 | docker compose rm 24 | 25 | .PHONY: clean-start 26 | clean-start: clean build-no-cache start ## cleans cache, build discarding cache and start dockers 27 | 28 | .PHONY: format 29 | format: ## Run dart format 30 | dart format --set-exit-if-changed -l 160 ./lib ./bin 31 | 32 | .PHONY: format-apply 33 | format-apply: ## Run dart format 34 | dart format --fix -l 160 ./lib ./bin 35 | 36 | .PHONY: analyze 37 | analyze: ## Run dart analyze 38 | dart analyze -------------------------------------------------------------------------------- /src/notifiers/on_ready.notifier.dart: -------------------------------------------------------------------------------- 1 | import 'package:riverpod/riverpod.dart'; 2 | 3 | import '../commands/commands.dart'; 4 | import './../services/logs.dart'; 5 | import 'package:nyxx/nyxx.dart'; 6 | 7 | class ClientReady { 8 | /// On bot ready Do what ever you want 😎. 9 | static Future onReadyEvent( 10 | INyxxWebsocket? client, ProviderContainer container) async { 11 | client!.eventsWs.onReady.listen((_) async { 12 | try { 13 | /// Set the bot activity to listening. 14 | client.setPresence( 15 | PresenceBuilder.of( 16 | status: UserStatus.online, 17 | activity: ActivityBuilder.listening('your commands') 18 | ..url = 'https://flutter.dev/', 19 | ), 20 | ); 21 | await Flutter.getData(container); 22 | BotLogger.logln( 23 | LogType.success, '${client.self.tag} is ready to go 🔥'); 24 | } catch (e) { 25 | /// Throw Exception if something goes wrong. 26 | BotLogger.logln(LogType.error, e.toString()); 27 | } 28 | }); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 minnu 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /bin/flutter_bot.dart: -------------------------------------------------------------------------------- 1 | import 'dart:async'; 2 | 3 | import 'package:nyxx/nyxx.dart'; 4 | import 'package:nyxx_interactions/nyxx_interactions.dart'; 5 | import 'package:riverpod/riverpod.dart'; 6 | 7 | import './../src/notifiers/login.notifier.dart'; 8 | import './../src/notifiers/on_msg.notifier.dart'; 9 | import './../src/notifiers/on_ready.notifier.dart'; 10 | import './../src/services/load_env.util.dart'; 11 | import '../src/events/interations/button.interation.dart'; 12 | import '../src/services/logs.dart'; 13 | 14 | Future main() async { 15 | try { 16 | ProviderContainer container = ProviderContainer(); 17 | container.read(atBotEnvProvider); 18 | INyxxWebsocket? client = await container.read(clientProvider.future); 19 | await client?.connect(); 20 | // await Flutter.getData(container); 21 | await ClientReady.onReadyEvent(client, container); 22 | await MessageNotifier.onMsgEvent(client, container); 23 | 24 | /// User interaction. 25 | IInteractions.create(WebsocketInteractionBackend(client!)) 26 | ..events.onButtonEvent.listen(buttonInteraction) 27 | ..syncOnReady(); 28 | } on Exception catch (e) { 29 | BotLogger.logln(LogType.error, e.toString()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig 2 | 3 | # Created by https://www.toptal.com/developers/gitignore/api/dart 4 | # Edit at https://www.toptal.com/developers/gitignore?templates=dart 5 | 6 | ### Dart ### 7 | # See https://www.dartlang.org/guides/libraries/private-files 8 | 9 | # Files and directories created by pub 10 | .dart_tool/ 11 | .packages 12 | build/ 13 | # If you're building an application, you may want to check-in your pubspec.lock 14 | pubspec.lock 15 | 16 | # Directory created by dartdoc 17 | # If you don't generate documentation locally you can remove this line. 18 | doc/api/ 19 | 20 | # dotenv environment variables file 21 | 22 | # Avoid committing generated Javascript files: 23 | *.dart.js 24 | *.info.json # Produced by the --dump-info flag. 25 | *.js # When generated by dart2js. Don't specify *.js if your 26 | # project includes source files written in JavaScript. 27 | *.js_ 28 | *.js.deps 29 | *.js.map 30 | .flutter-plugins 31 | .flutter-plugins-dependencies 32 | 33 | ### Dart Patch ### 34 | # dotenv environment variables file 35 | *.env 36 | # End of https://www.toptal.com/developers/gitignore/api/dart 37 | 38 | # Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) 39 | -------------------------------------------------------------------------------- /src/services/custom_print.util.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | /// Prints the given message to the console with a new line. 4 | // ignore_for_file: avoid_print 5 | 6 | void println(String text) { 7 | stdout.writeln(text); 8 | } 9 | 10 | /// Prints the given message to the console as ***`Warning`***. 11 | void log(String text) { 12 | stdout.write('\x1B[33m$text\x1B[0m'); 13 | } 14 | 15 | /// Prints the given message to the console as ***`Warning`*** with the new line. 16 | void logln(String text) { 17 | println(text); 18 | } 19 | 20 | /// Prints the given message to the console as ***`Error`***. 21 | void error(String text) { 22 | stderr.write('\x1B[31m$text\x1B[0m'); 23 | } 24 | 25 | /// Prints the given message to the console as ***`Error`*** with the new line. 26 | void errorln(String text) { 27 | stderr.writeln(text); 28 | } 29 | 30 | /// Prints the given message to the console as ***`Information`***. 31 | void info(String text) { 32 | stdout.write('\x1B[36m$text\x1B[0m'); 33 | } 34 | 35 | /// Prints the given message to the console as ***`Information`*** with the new line. 36 | void infoln(String text) { 37 | println(text); 38 | } 39 | 40 | /// Prints the given message to the console as ***`Information`***. 41 | void success(String text) { 42 | stdout.write('\x1B[32m$text\x1B[0m'); 43 | } 44 | 45 | /// Prints the given message to the console as ***`Information`*** with the new line. 46 | void successln(String text) { 47 | println('\x1B[32m$text\x1B[0m'); 48 | } 49 | -------------------------------------------------------------------------------- /src/notifiers/login.notifier.dart: -------------------------------------------------------------------------------- 1 | import '../services/load_env.util.dart'; 2 | import './../services/logs.dart'; 3 | import 'package:nyxx/nyxx.dart'; 4 | import 'package:riverpod/riverpod.dart'; 5 | 6 | final Provider _clientProvider = 7 | Provider((Ref ref) => Client()); 8 | final FutureProvider clientProvider = 9 | FutureProvider((Ref ref) { 10 | Client client = ref.read(_clientProvider); 11 | AtBotEnv env = ref.read(atBotEnvProvider); 12 | String? token = env.token; 13 | return client.login(token, GatewayIntents.all); 14 | }); 15 | 16 | class Client { 17 | /// Login the discord bot with the given token as parameter 18 | Future login(String? token, int? privilages) async { 19 | try { 20 | /// Check if [token] is null. If null, Throw [MissingTokenError]. 21 | if (token == null) throw MissingTokenError(); 22 | // return Nyxx( 23 | // token, 24 | // privilages!, 25 | // cacheOptions: CacheOptions() 26 | // ..memberCachePolicyLocation = CachePolicyLocation.all() 27 | // ..userCachePolicyLocation = CachePolicyLocation.all(), 28 | // ignoreExceptions: false, 29 | // ); 30 | return NyxxFactory.createNyxxWebsocket( 31 | token, 32 | privilages!, 33 | cacheOptions: CacheOptions() 34 | ..memberCachePolicyLocation = CachePolicyLocation.all() 35 | ..userCachePolicyLocation = CachePolicyLocation.all(), 36 | // ignoreExceptions: false, 37 | ); 38 | } catch (e) { 39 | BotLogger.logln(LogType.error, 'Login Exception : ${e.toString()}'); 40 | return null; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /analysis_options.yaml: -------------------------------------------------------------------------------- 1 | # This file configures the static analysis results for your project (errors, 2 | # warnings, and lints). 3 | # 4 | # This enables the 'recommended' set of lints from `package:lints`. 5 | # This set helps identify many issues that may lead to problems when running 6 | # or consuming Dart code, and enforces writing Dart using a single, idiomatic 7 | # style and format. 8 | # 9 | # If you want a smaller set of lints you can change this to specify 10 | # 'package:lints/core.yaml'. These are just the most critical lints 11 | # (the recommended set includes the core lints). 12 | # The core lints are also what is used by pub.dev for scoring packages. 13 | 14 | include: package:lints/recommended.yaml 15 | 16 | # Uncomment the following section to specify additional rules. 17 | 18 | analyzer: 19 | errors: 20 | unused_local_variable: warning 21 | invalid_assignment: warning 22 | missing_return: error 23 | annotate_overrides: error 24 | always_specify_types: error 25 | dead_code: warning 26 | todo: ignore 27 | 28 | linter: 29 | rules: 30 | hash_and_equals: true 31 | prefer_is_not_empty: true 32 | always_specify_types: true 33 | avoid_print: false 34 | constant_identifier_names: true 35 | non_constant_identifier_names: true 36 | avoid_type_to_string: true 37 | camel_case_types: true 38 | empty_constructor_bodies: true 39 | prefer_const_constructors: true 40 | sort_constructors_first: true 41 | prefer_single_quotes: true 42 | avoid_empty_else: true 43 | cancel_subscriptions: true 44 | close_sinks: true 45 | prefer_conditional_assignment: true 46 | cast_nullable_to_non_nullable: true 47 | omit_local_variable_types: false 48 | avoid_returning_null_for_future: true 49 | always_declare_return_types: true 50 | avoid_returning_null: true 51 | avoid_returning_null_for_void: true 52 | avoid_returning_this: true 53 | implementation_imports: false 54 | avoid_void_async: true 55 | unawaited_futures: true 56 | await_only_futures: true 57 | unnecessary_lambdas: true 58 | unnecessary_await_in_return: true 59 | unnecessary_final: true 60 | sort_pub_dependencies: true 61 | package_names: true -------------------------------------------------------------------------------- /src/services/logs.dart: -------------------------------------------------------------------------------- 1 | // 📦 Package imports: 2 | import 'package:intl/intl.dart'; 3 | import 'package:nyxx/nyxx.dart'; 4 | 5 | // 🌎 Project imports: 6 | import 'custom_print.util.dart' as console; 7 | 8 | /// LoggerType Enum 9 | enum LogType { success, info, warning, error } 10 | 11 | /// Logger class 12 | class BotLogger { 13 | /// Logger method to log depending on [LogType] 14 | static void log(LogType? tag, String? message) { 15 | /// Get the current date and time 16 | String time = DateFormat.yMEd().add_jms().format(DateTime.now()); 17 | switch (tag) { 18 | case LogType.success: 19 | console.success('SUCCESS [$time] - $message'); 20 | break; 21 | case LogType.info: 22 | console.info('INFORMATION [$time] - $message'); 23 | break; 24 | case LogType.warning: 25 | console.log('WARNING [$time] - $message'); 26 | break; 27 | case LogType.error: 28 | console.error('ERROR [$time] - $message\n[StackTraces] - ${StackTrace.current}'); 29 | break; 30 | default: 31 | // ignore: avoid_print 32 | print('LOG [$time] - $message'); 33 | } 34 | } 35 | 36 | static void logln(LogType? tag, String? message) { 37 | /// Get the current date and time 38 | String time = DateFormat.yMEd().add_jms().format(DateTime.now()); 39 | switch (tag) { 40 | case LogType.success: 41 | console.successln('SUCCESS [$time] - $message'); 42 | break; 43 | case LogType.info: 44 | console.infoln('INFORMATION [$time] - $message'); 45 | break; 46 | case LogType.warning: 47 | console.logln('WARNING [$time] - $message'); 48 | break; 49 | case LogType.error: 50 | console.errorln('ERROR [$time] - $message\n[StackTraces] - ${StackTrace.current}'); 51 | break; 52 | default: 53 | console.println('LOG [$time] - $message'); 54 | } 55 | } 56 | } 57 | 58 | /// Sends the message to the channel and logs it. 59 | Future logAndSendMessage( 60 | IMessageReceivedEvent event, MessageBuilder messageBuilder, LogType logType, String logMessage) async { 61 | await event.message.channel.sendMessage(messageBuilder); 62 | BotLogger.logln(logType, logMessage); 63 | } 64 | -------------------------------------------------------------------------------- /src/utils/constants.util.dart: -------------------------------------------------------------------------------- 1 | import 'package:nyxx/nyxx.dart'; 2 | 3 | class Commands { 4 | static const String music = 'music'; 5 | static const String rename = 'rename'; 6 | static const String role = 'role'; 7 | static const String node = 'node'; 8 | } 9 | 10 | /// Bot general constants 11 | class BotConstants { 12 | /// Enviroment variables file name 13 | static const String envFile = '.env'; 14 | 15 | /// Reg for finding role in user nickname 16 | static final RegExp _regExp = RegExp(r'\[\S*\] '); 17 | 18 | /// Base URL for flutter docs 19 | static String flutterBaseUrl = 'https://api.flutter.dev/flutter/'; 20 | 21 | static String pubAuthority = 'pub.dev'; 22 | 23 | /// Base URL for pub packages 24 | static String pubPackagesPath = '/packages/'; 25 | 26 | /// Base URL for pub docs 27 | static String pubDocsBaseUrl(String packageName) => 28 | 'https://pub.dev/documentation/$packageName/latest/index.html'; 29 | 30 | static String pubPoster = 31 | 'https://pub.dev/static/img/pub-dev-icon-cover-image.png?hash=vg86r2r3mbs62hiv4ldop0ife5um2g5g'; 32 | 33 | /// Remove that role from user nickname 34 | static String? removeStuff(String input) => input.replaceAll(_regExp, ''); 35 | 36 | /// Bot music buttons 37 | // static List musicComponents = [ 38 | // ButtonBuilder('⏮', 'seek', ComponentStyle.secondary), 39 | // ButtonBuilder('▶', 'resume', ComponentStyle.secondary), 40 | // ButtonBuilder('⏸', 'pause', ComponentStyle.secondary), 41 | // ButtonBuilder('⏭', 'skip', ComponentStyle.secondary), 42 | // ]; 43 | } 44 | 45 | /// Bot Message content constants 46 | class MessageContent { 47 | /// Private function returns message content builder. 48 | static MessageBuilder _messgaeContent(String message) { 49 | return MessageBuilder.content(message); 50 | } 51 | 52 | /// User need to be admin. 53 | static MessageBuilder get needToBeAdmin => 54 | _messgaeContent('You need to be an admin to use this command'); 55 | 56 | /// Exception message. 57 | static MessageBuilder exception(Object? e) => 58 | _messgaeContent('Something went wrong. \nException : ${e.toString()}'); 59 | 60 | /// Waiting message for long interactions. 61 | static MessageBuilder get waiting => _messgaeContent('waiting...'); 62 | 63 | /// Custom message. 64 | static MessageBuilder custom(String message) => _messgaeContent(message); 65 | 66 | /// Custom message with embed. 67 | static MessageBuilder embed(String message, EmbedBuilder embed) => 68 | _messgaeContent(message)..embeds?.add(embed); 69 | } 70 | -------------------------------------------------------------------------------- /src/services/load_env.util.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:dotenv/dotenv.dart'; 4 | import 'package:nyxx/nyxx.dart'; 5 | import 'package:riverpod/riverpod.dart'; 6 | 7 | import '../utils/constants.util.dart'; 8 | import 'logs.dart'; 9 | 10 | final Provider atBotEnvProvider = 11 | Provider((_) => AtBotEnv().._loadEnv()); 12 | 13 | class AtBotEnv { 14 | String? _prefix; 15 | String? get prefix => _prefix; 16 | 17 | /// Prefix provider 18 | String? _token; 19 | String? get token => _token; 20 | 21 | /// Bot ID private variable 22 | Snowflake? _clientID; 23 | Snowflake? get clientID => _clientID; 24 | 25 | /// Load all the env variables from `.env` file. 26 | /// If the file is not found, it will throw an exception. 27 | Future _loadEnv() async { 28 | try { 29 | /// Check if file exist in the current working directory. 30 | if (File(BotConstants.envFile).existsSync()) { 31 | /// Load the env variables from the file. 32 | DotEnv env = DotEnv(includePlatformEnvironment: true) 33 | ..load([BotConstants.envFile]); 34 | 35 | /// Set the prefix 36 | if (env['prefix'] == null || env['prefix']!.isEmpty) { 37 | BotLogger.logln(LogType.error, 'Missing token in `.env` file'); 38 | exit(-1); 39 | } else { 40 | _prefix = env['prefix']; 41 | } 42 | 43 | /// Set the token 44 | if (env['token'] == null || env['token']!.isEmpty) { 45 | BotLogger.logln(LogType.error, 'Missing token in `.env` file'); 46 | exit(-1); 47 | } else { 48 | _token = env['token']; 49 | } 50 | 51 | /// Set the Bot ID 52 | if (env['botID'] == null || env['botID']!.isEmpty) { 53 | BotLogger.logln(LogType.error, 'Missing Bot ID in `.env` file'); 54 | exit(-1); 55 | } else { 56 | _clientID = env['botID']!.toSnowflake(); 57 | } 58 | } else { 59 | // /// If the file is not found, throw FileSystemException. 60 | // // throw const FileSystemException(); 61 | BotLogger.logln( 62 | LogType.error, 'Missing `.env` file | Fetching from env'); 63 | _prefix = Platform.environment['prefix']; 64 | _token = Platform.environment['token']; 65 | _clientID = Platform.environment['botID']!.toSnowflake(); 66 | } 67 | } on FileSystemException catch (_) { 68 | /// Throw an exception if the file is not found. 69 | BotLogger.logln(LogType.error, 'Missing `.env` file | Fetching from env'); 70 | _prefix = Platform.environment['prefix']; 71 | _token = Platform.environment['token']; 72 | _clientID = Platform.environment['botID']!.toSnowflake(); 73 | } catch (e) { 74 | throw Exception('Exception : $e'); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/events/music.event.dart: -------------------------------------------------------------------------------- 1 | // import 'dart:async'; 2 | 3 | // import 'package:nyxx/nyxx.dart'; 4 | // import 'package:nyxx_interactions/nyxx_interactions.dart'; 5 | // import 'package:nyxx_interactions/src/builders/component_builder.dart'; 6 | // import 'package:nyxx_lavalink/nyxx_lavalink.dart'; 7 | // import 'package:riverpod/riverpod.dart'; 8 | 9 | // import '../notifiers/time.notifier.dart'; 10 | // import '../services/logs.dart'; 11 | // import '../utils/colors.util.dart'; 12 | // import '../utils/constants.util.dart'; 13 | 14 | // class MusicEvent { 15 | // static Future> onMusicEvent( 16 | // ICluster cluster, ProviderContainer container) async { 17 | // return cluster. 18 | // onTrackStart.listen((ITrackStartEvent event) async { 19 | // try { 20 | // Provider