Finish adding Sticker function calls
This commit is contained in:
parent
6079fa9a01
commit
5e6e47bd0a
3 changed files with 84 additions and 1 deletions
|
@ -11,6 +11,8 @@ class DiscordEndpoints {
|
|||
static const Applications = "/applications";
|
||||
static const Users = "/users";
|
||||
static const Stickers = "/stickers";
|
||||
static const StickerPacks = "/sticker-packs";
|
||||
static const Guilds = "/guilds";
|
||||
}
|
||||
|
||||
class DiscordSessionSettings {
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:libac_dart/discord/networking/endpoints.dart';
|
||||
import 'package:libac_dart/structs/Snowflake.dart';
|
||||
|
@ -12,4 +15,82 @@ class StickerPackets {
|
|||
|
||||
return Sticker.fromJson(reply.data);
|
||||
}
|
||||
|
||||
static Future<List<StickerPack>> getStickerPacks() async {
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio
|
||||
.get("${DiscordEndpoints.BaseURL}${DiscordEndpoints.StickerPacks}");
|
||||
|
||||
List<StickerPack> stickerPacks = [];
|
||||
var js = json.decode(reply.data);
|
||||
var jsStickerPacks = js['sticker_packs'];
|
||||
|
||||
for (var entry in jsStickerPacks) {
|
||||
stickerPacks.add(StickerPack.decode(entry));
|
||||
}
|
||||
|
||||
return stickerPacks;
|
||||
}
|
||||
|
||||
static Future<List<Sticker>> getGuildStickers(Snowflake guildId) async {
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio.get(
|
||||
"${DiscordEndpoints.BaseURL}${DiscordEndpoints.Guilds}${guildId.toString()}${DiscordEndpoints.Stickers}");
|
||||
|
||||
List<Sticker> stickers = [];
|
||||
for (var entry in json.decode(reply.data)) {
|
||||
stickers.add(Sticker.decode(entry));
|
||||
}
|
||||
|
||||
return stickers;
|
||||
}
|
||||
|
||||
static Future<Sticker> getGuildSticker(
|
||||
Snowflake guildId, Snowflake id) async {
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio.get(
|
||||
"${DiscordEndpoints.BaseURL}${DiscordEndpoints.Guilds}${guildId.toString()}${DiscordEndpoints.Stickers}/${id.toString()}");
|
||||
|
||||
return Sticker.fromJson(reply.data);
|
||||
}
|
||||
|
||||
static Future<Sticker> createGuildSticker(Snowflake guildId, String name,
|
||||
String description, String tags, Uint8List fileContents) async {
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var fd = FormData.fromMap({
|
||||
"name": name,
|
||||
"description": description,
|
||||
"tags": tags,
|
||||
"file": MultipartFile.fromBytes(fileContents)
|
||||
});
|
||||
|
||||
var reply = await dio.post(
|
||||
"${DiscordEndpoints.BaseURL}${DiscordEndpoints.Guilds}/${guildId.toString()}${DiscordEndpoints.Stickers}",
|
||||
options: Options(contentType: "multipart/form-data"),
|
||||
data: fd);
|
||||
return Sticker.fromJson(reply.data);
|
||||
}
|
||||
|
||||
static Future<Sticker> updateGuildSticker(Snowflake guildId,
|
||||
Snowflake stickerId, String name, String description, String tags) async {
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio.patch(
|
||||
"${DiscordEndpoints.BaseURL}${DiscordEndpoints.Guilds}/${guildId.toString()}${DiscordEndpoints.Stickers}/${stickerId.toString()}",
|
||||
data: json
|
||||
.encode({"name": name, "description": description, "tags": tags}));
|
||||
|
||||
return Sticker.fromJson(reply.data);
|
||||
}
|
||||
|
||||
static Future<bool> deleteGuildSticker(
|
||||
Snowflake guildId, Snowflake stickerId) async {
|
||||
Dio dio = Dio(DiscordSessionSettings.getOptions);
|
||||
var reply = await dio.delete(
|
||||
"${DiscordEndpoints.BaseURL}/${guildId.toString()}${DiscordEndpoints.Stickers}/${stickerId.toString()}");
|
||||
|
||||
if (reply.statusCode == 204) {
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
name: libac_dart
|
||||
description: "Aria's Creations code library"
|
||||
version: 1.2.071124+0244
|
||||
version: 1.2.071124+1630
|
||||
homepage: "https://zontreck.com"
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue