From fa79297bfab4fbf66f5c23f929708508ed943ef4 Mon Sep 17 00:00:00 2001 From: Abdfn <64256993+abdfnx@users.noreply.github.com> Date: Sat, 2 Jul 2022 08:46:33 +0000 Subject: [PATCH] finish and publish `v0.1.0` of `botway_dart` --- packages/botway_dart/.gitignore | 12 ++++ packages/botway_dart/README.md | 30 +++++++++ packages/botway_dart/lib/botway_dart.dart | 3 + .../botway_dart/lib/src/botway_dart_base.dart | 62 +++++++++++++++++++ packages/botway_dart/pubspec.yaml | 11 ++++ 5 files changed, 118 insertions(+) create mode 100644 packages/botway_dart/.gitignore create mode 100644 packages/botway_dart/README.md create mode 100644 packages/botway_dart/lib/botway_dart.dart create mode 100644 packages/botway_dart/lib/src/botway_dart_base.dart create mode 100644 packages/botway_dart/pubspec.yaml diff --git a/packages/botway_dart/.gitignore b/packages/botway_dart/.gitignore new file mode 100644 index 00000000..3b4b2da4 --- /dev/null +++ b/packages/botway_dart/.gitignore @@ -0,0 +1,12 @@ +# Files and directories created by pub. +.dart_tool/ +.packages + +# Conventional directory for build outputs. +build/ + +# Omit committing pubspec.lock for library packages; see +# https://dart.dev/guides/libraries/private-files#pubspeclock. +pubspec.lock + +x.dart diff --git a/packages/botway_dart/README.md b/packages/botway_dart/README.md new file mode 100644 index 00000000..0497ad5f --- /dev/null +++ b/packages/botway_dart/README.md @@ -0,0 +1,30 @@ +
+

botway_dart

+

+ Dart client package for Botway +

+
+

+ Pub +

+
+ +## Usage + +> after creating a new dart botway project, you need to use your tokens to connect with your bot. + +```dart +import "package:nyxx/nyxx.dart"; +import "package:botway_dart/botway_dart.dart"; + +void main() { + var bot_config = Botway(); + + final bot = NyxxFactory.createNyxxWebsocket(bot_config.Get_Token(), GatewayIntents.allUnprivileged) + ..registerPlugin(Logging()) // Default logging plugin + ..registerPlugin(CliIntegration()) // Cli integration for nyxx allows stopping application via SIGTERM and SIGKILl + ..registerPlugin(IgnoreExceptions()) // Plugin that handles uncaught exceptions that may occur + ..connect(); + +... +``` diff --git a/packages/botway_dart/lib/botway_dart.dart b/packages/botway_dart/lib/botway_dart.dart new file mode 100644 index 00000000..9eb62715 --- /dev/null +++ b/packages/botway_dart/lib/botway_dart.dart @@ -0,0 +1,3 @@ +library botway_dart; + +export 'src/botway_dart_base.dart'; diff --git a/packages/botway_dart/lib/src/botway_dart_base.dart b/packages/botway_dart/lib/src/botway_dart_base.dart new file mode 100644 index 00000000..fe44c086 --- /dev/null +++ b/packages/botway_dart/lib/src/botway_dart_base.dart @@ -0,0 +1,62 @@ +import 'dart:io'; +import 'dart:convert'; +import 'package:yaml/yaml.dart'; +import 'package:path/path.dart' as p; + +class Botway { + get_bot_info(String value) { + if (File(".botway.yaml").existsSync()) { + String BotConfigFile = File('.botway.yaml').readAsStringSync(); + dynamic BotConfig = loadYaml(BotConfigFile); + + return BotConfig["bot"][value]; + } else { + throw Exception("ERROR: Bot config file not found"); + } + } + + String? get HomePath => + Platform.environment['HOME'] ?? Platform.environment['USERPROFILE']; + + String BotwayConfigFile() { + File BWFile = File(p.join(HomePath.toString(), '.botway', 'botway.json')); + + if (BWFile.existsSync()) { + return BWFile.readAsStringSync(); + } else { + throw Exception("ERROR: Botway config file not found"); + } + } + + dynamic get BotwayConfig => json.decode(BotwayConfigFile()); + + Get_Token() { + return BotwayConfig["botway"]["bots"][get_bot_info("name")]["bot_token"]; + } + + Get_App_Id() { + String value = "bot_app_id"; + + if (get_bot_info("type") == "slack") { + value = "bot_app_token"; + } + + return BotwayConfig["botway"]["bots"][get_bot_info("name")][value]; + } + + Get_Guild_Id(String server_name) { + if (get_bot_info("type") != "discord") { + throw Exception("ERROR: This function/feature is only working with discord bots"); + } else { + return BotwayConfig["botway"]["bots"][get_bot_info("name")]["guilds"][server_name]["server_id"]; + } + } + + Get_Signing_Secret() { + if (get_bot_info("type") != "slack") { + throw Exception("ERROR: This function/feature is only working with slack bots"); + } else { + return BotwayConfig["botway"]["bots"][get_bot_info("name")]["signing_secret"]; + } + } +} diff --git a/packages/botway_dart/pubspec.yaml b/packages/botway_dart/pubspec.yaml new file mode 100644 index 00000000..30bb850f --- /dev/null +++ b/packages/botway_dart/pubspec.yaml @@ -0,0 +1,11 @@ +name: botway_dart +description: Dart client package for Botway. +version: 0.1.0 +homepage: https://github.com/abdfnx/botway + +environment: + sdk: '>=2.17.5 <3.0.0' + +dependencies: + path: ^1.8.2 + yaml: ^3.1.1