Finish adding Sticker function calls

This commit is contained in:
zontreck 2024-07-11 16:30:49 -07:00
parent 6079fa9a01
commit 5e6e47bd0a
3 changed files with 84 additions and 1 deletions

View file

@ -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 {

View file

@ -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;
}
}

View file

@ -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"