2023-10-28 13:50:37 +00:00
|
|
|
import axios from "axios";
|
2023-10-28 18:21:13 +00:00
|
|
|
import { DateTime } from "luxon";
|
2023-10-28 13:50:37 +00:00
|
|
|
|
|
|
|
type UserInfo = {
|
|
|
|
name: string;
|
|
|
|
patreon: boolean;
|
|
|
|
timezone: string | null;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type GuildInfo = {
|
|
|
|
id: string;
|
|
|
|
name: string;
|
|
|
|
};
|
|
|
|
|
2023-10-28 18:21:13 +00:00
|
|
|
type EmbedField = {
|
|
|
|
title: string;
|
|
|
|
value: string;
|
|
|
|
inline: boolean;
|
|
|
|
};
|
|
|
|
|
|
|
|
export type Reminder = {
|
|
|
|
attachment: string | null;
|
|
|
|
attachment_name: string | null;
|
|
|
|
avatar: string | null;
|
|
|
|
channel: string;
|
|
|
|
content: string;
|
|
|
|
embed_author: string;
|
|
|
|
embed_author_url: string | null;
|
|
|
|
embed_color: number;
|
|
|
|
embed_description: string;
|
|
|
|
embed_footer: string;
|
|
|
|
embed_footer_url: string | null;
|
|
|
|
embed_image_url: string | null;
|
|
|
|
embed_thumbnail_url: string | null;
|
|
|
|
embed_title: string;
|
|
|
|
embed_fields: EmbedField[] | null;
|
|
|
|
enabled: boolean;
|
|
|
|
expires: DateTime | null;
|
|
|
|
interval_seconds: number | null;
|
|
|
|
interval_days: number | null;
|
|
|
|
interval_months: number | null;
|
|
|
|
name: string;
|
|
|
|
restartable: boolean;
|
|
|
|
tts: boolean;
|
|
|
|
uid: string;
|
|
|
|
username: string;
|
|
|
|
utc_time: DateTime;
|
|
|
|
};
|
|
|
|
|
|
|
|
type ChannelInfo = {
|
|
|
|
id: string;
|
|
|
|
name: string;
|
|
|
|
};
|
|
|
|
|
2023-10-28 13:50:37 +00:00
|
|
|
export function fetchUserInfo(): Promise<UserInfo> {
|
2023-10-28 18:21:13 +00:00
|
|
|
return axios.get("/dashboard/api/user").then((resp) => resp.data) as Promise<UserInfo>;
|
2023-10-28 13:50:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function fetchUserGuilds(): Promise<GuildInfo[]> {
|
2023-10-28 18:21:13 +00:00
|
|
|
return axios.get("/dashboard/api/user/guilds").then((resp) => resp.data) as Promise<
|
|
|
|
GuildInfo[]
|
|
|
|
>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function fetchGuildReminders(guild: string): Promise<Reminder[]> {
|
|
|
|
return axios
|
|
|
|
.get(`/dashboard/api/guild/${guild}/reminders`)
|
|
|
|
.then((resp) => resp.data)
|
|
|
|
.then((value) =>
|
|
|
|
value.map((reminder) => ({
|
|
|
|
...reminder,
|
|
|
|
utc_time: DateTime.fromISO(reminder.utc_time),
|
|
|
|
expires: reminder.expires === null ? null : DateTime.fromISO(reminder.expires),
|
|
|
|
})),
|
|
|
|
) as Promise<Reminder[]>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function fetchGuildChannels(guild: string): Promise<ChannelInfo[]> {
|
|
|
|
return axios.get(`/dashboard/api/guild/${guild}/channels`).then((resp) => resp.data) as Promise<
|
|
|
|
ChannelInfo[]
|
|
|
|
>;
|
2023-10-28 13:50:37 +00:00
|
|
|
}
|