Alter networking to include authorization bot header, and add initial sticker calls
This commit is contained in:
parent
eae1f391de
commit
6079fa9a01
6 changed files with 95 additions and 6 deletions
|
@ -8,7 +8,7 @@ import 'endpoints.dart';
|
|||
class ApplicationPacket {
|
||||
/// This will request the current application instance.
|
||||
static Future<Application> getCurrentApplication() async {
|
||||
Dio dio = Dio();
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio.get(
|
||||
"${DiscordEndpoints.BaseURL}${DiscordEndpoints.Applications}${DiscordEndpoints.ME}");
|
||||
String jsonReply = reply.data as String;
|
||||
|
@ -18,7 +18,7 @@ class ApplicationPacket {
|
|||
|
||||
/// This will update the current application instance.
|
||||
static Future<Application> updateApplication(EditApplication app) async {
|
||||
Dio dio = Dio();
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio.patch(
|
||||
"${DiscordEndpoints.BaseURL}${DiscordEndpoints.Applications}${DiscordEndpoints.ME}",
|
||||
data: app.encode());
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import 'package:dio/dio.dart';
|
||||
|
||||
/// Contains currently supported endpoints and URLs.
|
||||
class DiscordEndpoints {
|
||||
/// Currently this is set to 10
|
||||
|
@ -8,4 +10,12 @@ class DiscordEndpoints {
|
|||
static const ME = "/@me";
|
||||
static const Applications = "/applications";
|
||||
static const Users = "/users";
|
||||
static const Stickers = "/stickers";
|
||||
}
|
||||
|
||||
class DiscordSessionSettings {
|
||||
static String BOT_TOKEN = "";
|
||||
|
||||
static BaseOptions get getOptions => BaseOptions(
|
||||
headers: {"Authorization": "Bot ${DiscordSessionSettings.BOT_TOKEN}"});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import 'package:dio/dio.dart';
|
||||
import 'package:libac_dart/discord/networking/endpoints.dart';
|
||||
import 'package:libac_dart/structs/Snowflake.dart';
|
||||
|
||||
import '../structures/sticker.dart';
|
||||
|
||||
class StickerPackets {
|
||||
static Future<Sticker> getSticker(Snowflake id) async {
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio.get(
|
||||
"${DiscordEndpoints.BaseURL}${DiscordEndpoints.Stickers}/${id.toString()}");
|
||||
|
||||
return Sticker.fromJson(reply.data);
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@ import '../structures/user.dart';
|
|||
class UserPackets {
|
||||
/// Requests the current user from Discord's servers
|
||||
static Future<User> getCurrentUser() async {
|
||||
Dio dio = Dio();
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio.get(
|
||||
"${DiscordEndpoints.BaseURL}${DiscordEndpoints.Users}${DiscordEndpoints.ME}");
|
||||
|
||||
|
@ -19,7 +19,7 @@ class UserPackets {
|
|||
///
|
||||
/// [id] is expected to be a valid Discord User ID
|
||||
static Future<User> getUser(int id) async {
|
||||
Dio dio = Dio();
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio
|
||||
.get("${DiscordEndpoints.BaseURL}${DiscordEndpoints.Users}/${id}");
|
||||
|
||||
|
@ -30,7 +30,7 @@ class UserPackets {
|
|||
///
|
||||
/// Fires a User Update gateway event
|
||||
static Future<User> updateCurrentUser(ModifyCurrentUserPacket mcup) async {
|
||||
Dio dio = Dio();
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio.patch(
|
||||
"${DiscordEndpoints.BaseURL}${DiscordEndpoints.Users}${DiscordEndpoints.ME}",
|
||||
data: mcup.encode());
|
||||
|
|
|
@ -110,3 +110,67 @@ class StickerItem {
|
|||
formatType: int.parse(js['format_type']));
|
||||
}
|
||||
}
|
||||
|
||||
class StickerPack {
|
||||
Snowflake id;
|
||||
List<Sticker> stickers;
|
||||
String name;
|
||||
Snowflake sku_id;
|
||||
Snowflake? coverStickerId;
|
||||
String description;
|
||||
Snowflake? bannerAssetId;
|
||||
|
||||
StickerPack(
|
||||
{required this.id,
|
||||
required this.stickers,
|
||||
required this.name,
|
||||
required this.sku_id,
|
||||
this.coverStickerId,
|
||||
required this.description,
|
||||
this.bannerAssetId});
|
||||
|
||||
String encode() {
|
||||
return json.encode(toJson());
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
List<Map<String, dynamic>> stickersJs = [];
|
||||
for (Sticker sticker in stickers) {
|
||||
stickersJs.add(sticker.toJson());
|
||||
}
|
||||
|
||||
return {
|
||||
"id": id.toString(),
|
||||
"stickers": stickersJs,
|
||||
"name": name,
|
||||
"sku_id": sku_id.toString(),
|
||||
if (coverStickerId != null) "cover_sticker_id": coverStickerId.toString(),
|
||||
"description": description,
|
||||
if (bannerAssetId != null) "banner_asset_id": bannerAssetId.toString()
|
||||
};
|
||||
}
|
||||
|
||||
factory StickerPack.fromJson(String js) {
|
||||
return StickerPack.decode(json.decode(js));
|
||||
}
|
||||
|
||||
factory StickerPack.decode(Map<String, dynamic> js) {
|
||||
List<Sticker> jsStickers = [];
|
||||
for (var entry in js['stickers']) {
|
||||
jsStickers.add(Sticker.decode(entry));
|
||||
}
|
||||
|
||||
return StickerPack(
|
||||
id: Snowflake.parse(js['id'], Snowflake.DiscordEpoch),
|
||||
stickers: jsStickers,
|
||||
name: js['name'],
|
||||
sku_id: Snowflake.parse(js['sku_id'], Snowflake.DiscordEpoch),
|
||||
coverStickerId: js.containsKey("cover_sticker_id")
|
||||
? Snowflake.parse(js['cover_sticker_id'], Snowflake.DiscordEpoch)
|
||||
: null,
|
||||
description: js['description'],
|
||||
bannerAssetId: js.containsKey("banner_asset_id")
|
||||
? Snowflake.parse(js['banner_asset_id'], Snowflake.DiscordEpoch)
|
||||
: null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: libac_dart
|
||||
description: "Aria's Creations code library"
|
||||
version: 1.2.071124+0214
|
||||
version: 1.2.071124+0244
|
||||
homepage: "https://zontreck.com"
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue