This repository has been archived by the owner on Jul 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finish and publish
v0.1.0
of botway_dart
- Loading branch information
Showing
5 changed files
with
118 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
... | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
library botway_dart; | ||
|
||
export 'src/botway_dart_base.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |