Skip to content
This repository has been archived by the owner on Jul 20, 2024. It is now read-only.

Commit

Permalink
finish and publish v0.1.0 of botway_dart
Browse files Browse the repository at this point in the history
  • Loading branch information
abdfnx committed Jul 2, 2022
1 parent 944ff8a commit fa79297
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/botway_dart/.gitignore
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions packages/botway_dart/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<div align="center">
<h1>botway_dart</h1>
<p>
Dart client package for Botway
</p>
<br />
<p>
<img alt="Pub" src="https://img.shields.io/pub/v/botway_dart?label=pub.dev&logo=dart">
</p>
</div>

## 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();
...
```
3 changes: 3 additions & 0 deletions packages/botway_dart/lib/botway_dart.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
library botway_dart;

export 'src/botway_dart_base.dart';
62 changes: 62 additions & 0 deletions packages/botway_dart/lib/src/botway_dart_base.dart
Original file line number Diff line number Diff line change
@@ -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"];
}
}
}
11 changes: 11 additions & 0 deletions packages/botway_dart/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fa79297

Please sign in to comment.