Skip to content

Commit dbb3fe5

Browse files
committed
migration done
1 parent ea59118 commit dbb3fe5

13 files changed

+489
-312
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ doc/api/
2727
*.js_
2828
*.js.deps
2929
*.js.map
30-
*.env
3130
.flutter-plugins
3231
.flutter-plugins-dependencies
3332

3433
### Dart Patch ###
3534
# dotenv environment variables file
36-
35+
*.env
3736
# End of https://www.toptal.com/developers/gitignore/api/dart
3837

3938
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM google/dart:2.15.0-82.2.beta as builder
1+
FROM google/dart:latest as builder
22

33
WORKDIR /app
44

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- <h1 align="center">Welcome to flutter-bot 🤖</h1>
1+
<h1 align="center">Welcome to flutter-bot 🤖</h1>
22
<p>
33
<img alt="Version" src="https://img.shields.io/badge/version-2.4.4--stable.1-blue.svg?cacheSeconds=2592000" />
44
<a href="https://github.com/yahu1031/FlutterBot#readme" target="_blank">
@@ -190,4 +190,4 @@ Click on the bot to add this to your guild. [🤖](https://discord.com/api/oauth
190190
***
191191

192192
<p align="center"> Made with 💚, From Minnu. </p> <br />
193-
<p align="center">All assets used in this project related to flutter are taken directly from <a href="https://flutter.dev">Flutter.dev</a></p> -->
193+
<p align="center">All assets used in this project related to flutter are taken directly from <a href="https://flutter.dev">Flutter.dev</a></p>

bin/flutter_bot.dart

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
1-
import 'package:nyxx_lavalink/lavalink.dart';
1+
import 'dart:async';
22

3+
import 'package:nyxx_interactions/nyxx_interactions.dart';
4+
5+
import '../src/events/interations/button.interation.dart';
36
import './../src/services/load_env.util.dart';
47
import './../src/notifiers/login.notifier.dart';
58
import './../src/notifiers/on_ready.notifier.dart';
69
import './../src/notifiers/on_msg.notifier.dart';
7-
import './../src/services/logs.dart';
8-
import './../src/events/music.event.dart';
910
import 'package:nyxx/nyxx.dart';
1011
import 'package:riverpod/riverpod.dart';
1112

1213
Future<void> main() async {
13-
ProviderContainer container = ProviderContainer();
14-
// await AtBotEnv.loadEnv(container);
15-
AtBotEnv env = container.read(atBotEnvProvider);
16-
Snowflake clientID = env.clientID!;
17-
Nyxx? client = await container.read(clientProvider.future);
18-
Cluster cluster = Cluster(client!, clientID);
1914
try {
20-
await cluster.addNode(NodeOptions(
21-
host: 'lavalink.yahu1031.repl.co',
22-
port: 443,
23-
ssl: true,
24-
));
15+
ProviderContainer container = ProviderContainer();
16+
container.read(atBotEnvProvider);
17+
INyxxWebsocket? client = await container.read(clientProvider.future);
18+
await client?.connect();
19+
// await Flutter.getData(container);
20+
await ClientReady.onReadyEvent(client, container);
21+
await MessageNotifier.onMsgEvent(client, container);
22+
23+
/// User interaction.
24+
IInteractions.create(WebsocketInteractionBackend(client!))
25+
..events.onButtonEvent.listen(buttonInteraction)
26+
..syncOnReady();
2527
} on Exception catch (e) {
26-
BotLogger.log(LogType.error, e.toString());
28+
print(e.toString());
2729
}
28-
await MusicEvent.onMusicEvent(cluster, container);
29-
await ClientReady.onReadyEvent(client, container);
30-
await MessageNotifier.onMsgEvent(client, container, cluster: cluster);
3130
}

pubspec.yaml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: A simple command-line application.
33
version: 1.0.0
44
# homepage: https://www.example.com
55
environment:
6-
sdk: '>=2.14.4 <3.0.0'
6+
sdk: '>=2.15.0 <3.0.0'
77

88
# dependencies:
99
# path: ^1.8.0
@@ -13,7 +13,8 @@ dependencies:
1313
dotenv: ^3.0.0
1414
http: ^0.13.4
1515
intl: ^0.17.0
16-
nyxx: ^2.1.2
17-
nyxx_interactions: ^2.0.3
18-
nyxx_lavalink: ^2.0.1
19-
riverpod: ^1.0.0
16+
nyxx: ^3.2.1
17+
nyxx_interactions: ^3.1.0
18+
nyxx_lavalink: ^3.0.0
19+
nyxx_pagination: ^2.0.0
20+
riverpod: ^1.0.3

src/commands/commands.dart

Lines changed: 66 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,87 @@ import 'dart:convert';
33
import 'package:http/http.dart' as http;
44
import 'package:riverpod/riverpod.dart';
55

6+
import '../services/logs.dart';
7+
68
class Flutter {
79
/// API data of flutter widgets, properties, methods, etc.
8-
static StateProvider<List<Map<String, dynamic>>?> apiData = StateProvider<List<Map<String, dynamic>>?>((_) => null);
10+
static StateProvider<List<Map<String, dynamic>>?> apiData =
11+
StateProvider<List<Map<String, dynamic>>?>((_) => null);
912

1013
/// Pub API data of flutter and dart packages.
11-
static StateProvider<Map<String, dynamic>?> pubData = StateProvider<Map<String, dynamic>?>((_) => null);
14+
static StateProvider<Map<String, dynamic>?> pubData =
15+
StateProvider<Map<String, dynamic>?>((_) => null);
1216

1317
/// This function will fetch the data from the API
1418
static Future<void> getData(ProviderContainer ref) async {
1519
try {
1620
// make the request
17-
http.Response response = await http.get(Uri.parse('https://api.flutter.dev/flutter/index.json'));
21+
http.Response response = await http
22+
.get(Uri.parse('https://api.flutter.dev/flutter/index.json'));
1823
// conver the response to list
19-
List<Map<String, dynamic>> data = json.decode(response.body).cast<Map<String, dynamic>>();
24+
List<Map<String, dynamic>> data =
25+
json.decode(response.body).cast<Map<String, dynamic>>();
2026
ref.read(apiData.notifier).state = data;
2127
} catch (e) {
2228
print(e);
2329
}
2430
}
2531

2632
/// This function will return the Widget data.
27-
static Future<Map<String, dynamic>?> getWidget(List<String>? args, ProviderContainer ref) async {
33+
static Future<Map<String, dynamic>?> getWidget(
34+
List<String>? args, ProviderContainer ref) async {
2835
if (args == null || args.isEmpty) return null;
2936
List<Map<String, dynamic>>? data = ref.read(Flutter.apiData);
3037
for (Map<String, dynamic> widgetData in data!) {
3138
if (widgetData['name'].toLowerCase() == args[0].toLowerCase() &&
3239
(widgetData['enclosedBy']['name'].toLowerCase() == 'widgets' ||
33-
widgetData['enclosedBy']['name'].toString().toLowerCase() == args[0].toLowerCase())) {
40+
widgetData['enclosedBy']['name'].toString().toLowerCase() ==
41+
args[0].toLowerCase())) {
3442
return widgetData;
3543
}
3644
}
3745
return null;
3846
}
3947

4048
/// This function will return the Widget's property.
41-
static Future<Map<String, dynamic>?> getWidgetProperty(String widget, String property, ProviderContainer ref) async {
49+
static Future<Map<String, dynamic>?> getWidgetProperty(
50+
String widget, String property, ProviderContainer ref) async {
4251
List<Map<String, dynamic>>? data = ref.read(Flutter.apiData);
4352
for (Map<String, dynamic> propertyData in data!) {
4453
if (propertyData['name'].toLowerCase() == property &&
45-
propertyData['qualifiedName'].toString().toLowerCase().contains(widget.toLowerCase())) {
54+
propertyData['qualifiedName']
55+
.toString()
56+
.toLowerCase()
57+
.contains(widget.toLowerCase())) {
4658
return propertyData;
4759
}
4860
}
4961
return null;
5062
}
5163

5264
/// This function will return the list of properties of the widget.
53-
static Future<List<Map<String, dynamic>>?> getAllWidgetProperties(String widget, ProviderContainer ref) async {
65+
static Future<List<Map<String, dynamic>>> getAllWidgetProperties(
66+
String widget, ProviderContainer ref) async {
5467
List<Map<String, dynamic>>? data = ref.read(Flutter.apiData);
5568
List<Map<String, dynamic>>? properties = <Map<String, dynamic>>[];
5669
for (dynamic propertyData in data!) {
57-
if (propertyData['qualifiedName'].toString().toLowerCase().contains(widget.toLowerCase()) &&
58-
propertyData['enclosedBy']['name'].toString().toLowerCase() == widget.toLowerCase()) {
70+
if (propertyData['qualifiedName']
71+
.toString()
72+
.toLowerCase()
73+
.contains(widget.toLowerCase()) &&
74+
propertyData['enclosedBy'] != null &&
75+
propertyData['enclosedBy']['name'] != null &&
76+
propertyData['enclosedBy']['name'].toString().toLowerCase() ==
77+
widget.toLowerCase()) {
5978
properties.add(propertyData);
6079
}
6180
}
62-
return properties.isEmpty ? null : properties;
81+
return properties.isEmpty ? <Map<String, dynamic>>[] : properties;
6382
}
6483

6584
/// This function will return the similar widgets.
66-
static Future<List<Map<String, dynamic>>?> getSimilarWidgets(List<String> args, ProviderContainer ref) async {
85+
static Future<List<Map<String, dynamic>>?> getSimilarWidgets(
86+
List<String> args, ProviderContainer ref) async {
6787
List<Map<String, dynamic>>? data = ref.read(Flutter.apiData);
6888
List<Map<String, dynamic>> similarWidgets = <Map<String, dynamic>>[];
6989
for (dynamic widgetData in data!) {
@@ -76,26 +96,32 @@ class Flutter {
7696
}
7797

7898
/// This function will return the pub package.
79-
static Future<Map<String, dynamic>?> getPubPackage(String packageName, ProviderContainer ref) async {
99+
static Future<Map<String, dynamic>?> getPubPackage(
100+
String packageName, ProviderContainer ref) async {
80101
try {
81102
// make the request
82-
http.Response response = await http.get(Uri.parse('https://pub.dev/api/packages/$packageName'));
103+
http.Response response = await http
104+
.get(Uri.parse('https://pub.dev/api/packages/$packageName'));
83105
// conver the response to list
84106
Map<String, dynamic> data = json.decode(response.body);
85107
return data;
86108
} catch (e) {
87-
print(e);
109+
BotLogger.logln(LogType.error, e.toString());
110+
return null;
88111
}
89112
}
90113

91114
/// This function will return the all pub packages.
92-
static Future<List<Map<String, dynamic>>?> getAllPubPackages(String package, ProviderContainer ref) async {
115+
static Future<List<Map<String, dynamic>>?> getAllPubPackages(
116+
String package, ProviderContainer ref) async {
93117
try {
94118
// make the request
95-
http.Response response = await http.get(Uri.parse('https://pub.dev/api/search?q=$package'));
119+
http.Response response =
120+
await http.get(Uri.parse('https://pub.dev/api/search?q=$package'));
96121
// conver the response to list
97122
Map<String, dynamic> data = json.decode(response.body);
98-
List<Map<String, dynamic>> pubList = await data['packages'].cast<Map<String, dynamic>>();
123+
List<Map<String, dynamic>> pubList =
124+
await data['packages'].cast<Map<String, dynamic>>();
99125
return pubList.isEmpty ? null : pubList;
100126
} catch (e) {
101127
print(e);
@@ -104,14 +130,18 @@ class Flutter {
104130
}
105131

106132
/// This function will return the pub package's API docs.
107-
static Future<List<Map<String, dynamic>>?> getPubPackageDocs(String packageName, ProviderContainer ref) async {
133+
static Future<List<Map<String, dynamic>>?> getPubPackageDocs(
134+
String packageName, ProviderContainer ref) async {
108135
try {
109136
// make the request
110-
http.Response response =
111-
await http.get(Uri.parse('https://pub.dev/documentation/$packageName/latest/index.json'));
112-
if (response.body.contains('404 Not Found')) return <Map<String, dynamic>>[];
137+
http.Response response = await http.get(Uri.parse(
138+
'https://pub.dev/documentation/$packageName/latest/index.json'));
139+
if (response.body.contains('404 Not Found')) {
140+
return <Map<String, dynamic>>[];
141+
}
113142
// conver the response to list
114-
List<Map<String, dynamic>> data = await json.decode(response.body).cast<Map<String, dynamic>>();
143+
List<Map<String, dynamic>> data =
144+
await json.decode(response.body).cast<Map<String, dynamic>>();
115145
return data.isEmpty ? null : data;
116146
} catch (e) {
117147
print(e);
@@ -120,11 +150,12 @@ class Flutter {
120150
}
121151

122152
/// This package will return the pub package's API data.
123-
static Future<Map<String, dynamic>?> getPubPackageDocsData(String packageName, ProviderContainer ref) async {
153+
static Future<Map<String, dynamic>?> getPubPackageDocsData(
154+
String packageName, ProviderContainer ref) async {
124155
try {
125156
// make the request
126-
http.Response response =
127-
await http.get(Uri.parse('https://pub.dev/documentation/$packageName/latest/index.json'));
157+
http.Response response = await http.get(Uri.parse(
158+
'https://pub.dev/documentation/$packageName/latest/index.json'));
128159
// conver the response to list
129160
Map<String, dynamic> data = json.decode(response.body);
130161
return data.isEmpty ? null : data;
@@ -135,14 +166,19 @@ class Flutter {
135166
}
136167

137168
/// This function returns the author name.
138-
static Future<String?> getAuthorName(String package, ProviderContainer ref) async {
169+
static Future<String?> getAuthorName(
170+
String package, ProviderContainer ref) async {
139171
Map<String, dynamic>? packageData = await getPubPackage(package, ref);
140172
String? author = packageData!['latest']['pubspec']['author'];
141173
if (author == null) {
142174
if (packageData['latest']['pubspec']['repository'] == null) {
143-
return packageData['latest']['pubspec']['homepage'].toString().split('/')[3];
175+
return packageData['latest']['pubspec']['homepage']
176+
.toString()
177+
.split('/')[3];
144178
} else {
145-
return packageData['latest']['pubspec']['repository'].toString().split('/')[3];
179+
return packageData['latest']['pubspec']['repository']
180+
.toString()
181+
.split('/')[3];
146182
}
147183
}
148184
return author;
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
import 'package:nyxx_interactions/nyxx_interactions.dart';
3+
4+
Future<void> buttonInteraction(IButtonInteractionEvent event) async {
5+
try {
6+
/// Get the interaction ID
7+
// String id = event.interaction.customId;
8+
9+
/// Get the Guild ID
10+
// IGuild? guild = event.interaction.message!.client.guilds.;
11+
12+
} catch (e) {
13+
print(e);
14+
}
15+
}

0 commit comments

Comments
 (0)