mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
refactor progress
This commit is contained in:
8257 files changed
+1190205
-761038
No files matched your search
@@ -17,39 +17,22 @@
|
||||
* along with Fluxer. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import type {ChannelMoveOperation} from '~/components/layout/utils/channelMoveOperation';
|
||||
import type {AuditLogActionType} from '~/constants/AuditLogActionType';
|
||||
import {Endpoints} from '~/Endpoints';
|
||||
import http from '~/lib/HttpClient';
|
||||
import {Logger} from '~/lib/Logger';
|
||||
import type {Guild} from '~/records/GuildRecord';
|
||||
import type {GuildRole} from '~/records/GuildRoleRecord';
|
||||
import type {Invite} from '~/records/MessageRecord';
|
||||
import InviteStore from '~/stores/InviteStore';
|
||||
import type {ChannelMoveOperation} from '@app/components/layout/utils/ChannelMoveOperation';
|
||||
import {Endpoints} from '@app/Endpoints';
|
||||
import http from '@app/lib/HttpClient';
|
||||
import {Logger} from '@app/lib/Logger';
|
||||
import InviteStore from '@app/stores/InviteStore';
|
||||
import type {AuditLogActionType} from '@fluxer/constants/src/AuditLogActionType';
|
||||
import type {
|
||||
AuditLogWebhookResponse,
|
||||
GuildAuditLogEntryResponse,
|
||||
} from '@fluxer/schema/src/domains/guild/GuildAuditLogSchemas';
|
||||
import type {Guild} from '@fluxer/schema/src/domains/guild/GuildResponseSchemas';
|
||||
import type {GuildRole} from '@fluxer/schema/src/domains/guild/GuildRoleSchemas';
|
||||
import type {Invite} from '@fluxer/schema/src/domains/invite/InviteSchemas';
|
||||
import type {UserPartial} from '@fluxer/schema/src/domains/user/UserResponseSchemas';
|
||||
|
||||
const logger = new Logger('Guilds');
|
||||
|
||||
import type {UserPartial} from '~/records/UserRecord';
|
||||
|
||||
export interface AuditLogChangeEntry {
|
||||
key?: string;
|
||||
old_value?: unknown;
|
||||
new_value?: unknown;
|
||||
oldValue?: unknown;
|
||||
newValue?: unknown;
|
||||
}
|
||||
|
||||
export type GuildAuditLogChangePayload = Array<AuditLogChangeEntry> | null;
|
||||
|
||||
export interface GuildAuditLogEntry {
|
||||
id: string;
|
||||
action_type: number;
|
||||
user_id: string | null;
|
||||
target_id: string | null;
|
||||
reason?: string;
|
||||
options?: Record<string, unknown>;
|
||||
changes?: GuildAuditLogChangePayload;
|
||||
}
|
||||
const logger = new Logger('GuildActionCreators');
|
||||
|
||||
export interface GuildAuditLogFetchParams {
|
||||
userId?: string;
|
||||
@@ -60,9 +43,9 @@ export interface GuildAuditLogFetchParams {
|
||||
}
|
||||
|
||||
interface GuildAuditLogFetchResponse {
|
||||
audit_log_entries: Array<GuildAuditLogEntry>;
|
||||
audit_log_entries: Array<GuildAuditLogEntryResponse>;
|
||||
users: Array<UserPartial>;
|
||||
webhooks: Array<unknown>;
|
||||
webhooks: Array<AuditLogWebhookResponse>;
|
||||
}
|
||||
|
||||
export interface GuildBan {
|
||||
@@ -79,19 +62,19 @@ export interface GuildBan {
|
||||
expires_at: string | null;
|
||||
}
|
||||
|
||||
export const create = async (params: Pick<Guild, 'name'> & {icon?: string | null}): Promise<Guild> => {
|
||||
export async function create(params: Pick<Guild, 'name'> & {icon?: string | null}): Promise<Guild> {
|
||||
try {
|
||||
const response = await http.post<Guild>(Endpoints.GUILDS, params);
|
||||
const guild = response.body;
|
||||
logger.debug(`Created new guild: ${params.name}`);
|
||||
logger.debug(`Created new guild: ${params['name']}`);
|
||||
return guild;
|
||||
} catch (error) {
|
||||
logger.error('Failed to create guild:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const update = async (
|
||||
export async function update(
|
||||
guildId: string,
|
||||
params: Partial<
|
||||
Pick<
|
||||
@@ -108,12 +91,14 @@ export const update = async (
|
||||
| 'system_channel_flags'
|
||||
| 'features'
|
||||
| 'default_message_notifications'
|
||||
| 'message_history_cutoff'
|
||||
| 'verification_level'
|
||||
| 'mfa_level'
|
||||
| 'nsfw_level'
|
||||
| 'explicit_content_filter'
|
||||
>
|
||||
>,
|
||||
): Promise<Guild> => {
|
||||
): Promise<Guild> {
|
||||
try {
|
||||
const response = await http.patch<Guild>(Endpoints.GUILD(guildId), params);
|
||||
const guild = response.body;
|
||||
@@ -123,9 +108,9 @@ export const update = async (
|
||||
logger.error(`Failed to update guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const moveChannel = async (guildId: string, operation: ChannelMoveOperation): Promise<void> => {
|
||||
export async function moveChannel(guildId: string, operation: ChannelMoveOperation): Promise<void> {
|
||||
try {
|
||||
await http.patch({
|
||||
url: Endpoints.GUILD_CHANNELS(guildId),
|
||||
@@ -144,9 +129,9 @@ export const moveChannel = async (guildId: string, operation: ChannelMoveOperati
|
||||
logger.error(`Failed to move channel ${operation.channelId} in guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const getVanityURL = async (guildId: string): Promise<{code: string | null; uses: number}> => {
|
||||
export async function getVanityURL(guildId: string): Promise<{code: string | null; uses: number}> {
|
||||
try {
|
||||
const response = await http.get<{code: string | null; uses: number}>(Endpoints.GUILD_VANITY_URL(guildId));
|
||||
const result = response.body;
|
||||
@@ -156,9 +141,9 @@ export const getVanityURL = async (guildId: string): Promise<{code: string | nul
|
||||
logger.error(`Failed to fetch vanity URL for guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const updateVanityURL = async (guildId: string, code: string | null): Promise<string> => {
|
||||
export async function updateVanityURL(guildId: string, code: string | null): Promise<string> {
|
||||
try {
|
||||
const response = await http.patch<{code: string}>(Endpoints.GUILD_VANITY_URL(guildId), {code});
|
||||
logger.debug(`Updated vanity URL for guild ${guildId} to ${code || 'none'}`);
|
||||
@@ -167,9 +152,9 @@ export const updateVanityURL = async (guildId: string, code: string | null): Pro
|
||||
logger.error(`Failed to update vanity URL for guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const createRole = async (guildId: string, name: string): Promise<void> => {
|
||||
export async function createRole(guildId: string, name: string): Promise<void> {
|
||||
try {
|
||||
await http.post({url: Endpoints.GUILD_ROLES(guildId), body: {name}});
|
||||
logger.debug(`Created role "${name}" in guild ${guildId}`);
|
||||
@@ -177,9 +162,9 @@ export const createRole = async (guildId: string, name: string): Promise<void> =
|
||||
logger.error(`Failed to create role in guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const updateRole = async (guildId: string, roleId: string, patch: Partial<GuildRole>): Promise<void> => {
|
||||
export async function updateRole(guildId: string, roleId: string, patch: Partial<GuildRole>): Promise<void> {
|
||||
try {
|
||||
await http.patch({url: Endpoints.GUILD_ROLE(guildId, roleId), body: patch});
|
||||
logger.debug(`Updated role ${roleId} in guild ${guildId}`);
|
||||
@@ -187,9 +172,9 @@ export const updateRole = async (guildId: string, roleId: string, patch: Partial
|
||||
logger.error(`Failed to update role ${roleId} in guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const deleteRole = async (guildId: string, roleId: string): Promise<void> => {
|
||||
export async function deleteRole(guildId: string, roleId: string): Promise<void> {
|
||||
try {
|
||||
await http.delete({url: Endpoints.GUILD_ROLE(guildId, roleId)});
|
||||
logger.debug(`Deleted role ${roleId} from guild ${guildId}`);
|
||||
@@ -197,9 +182,9 @@ export const deleteRole = async (guildId: string, roleId: string): Promise<void>
|
||||
logger.error(`Failed to delete role ${roleId} from guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const setRoleOrder = async (guildId: string, orderedRoleIds: Array<string>): Promise<void> => {
|
||||
export async function setRoleOrder(guildId: string, orderedRoleIds: Array<string>): Promise<void> {
|
||||
try {
|
||||
const filteredIds = orderedRoleIds.filter((id) => id !== guildId);
|
||||
const payload = filteredIds.map((id, index) => ({id, position: filteredIds.length - index}));
|
||||
@@ -209,9 +194,9 @@ export const setRoleOrder = async (guildId: string, orderedRoleIds: Array<string
|
||||
logger.error(`Failed to update role ordering in guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const setRoleHoistOrder = async (guildId: string, orderedRoleIds: Array<string>): Promise<void> => {
|
||||
export async function setRoleHoistOrder(guildId: string, orderedRoleIds: Array<string>): Promise<void> {
|
||||
try {
|
||||
const filteredIds = orderedRoleIds.filter((id) => id !== guildId);
|
||||
const payload = filteredIds.map((id, index) => ({id, hoist_position: filteredIds.length - index}));
|
||||
@@ -221,9 +206,9 @@ export const setRoleHoistOrder = async (guildId: string, orderedRoleIds: Array<s
|
||||
logger.error(`Failed to update role hoist ordering in guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const resetRoleHoistOrder = async (guildId: string): Promise<void> => {
|
||||
export async function resetRoleHoistOrder(guildId: string): Promise<void> {
|
||||
try {
|
||||
await http.delete({url: Endpoints.GUILD_ROLE_HOIST_POSITIONS(guildId)});
|
||||
logger.debug(`Reset role hoist ordering in guild ${guildId}`);
|
||||
@@ -231,9 +216,9 @@ export const resetRoleHoistOrder = async (guildId: string): Promise<void> => {
|
||||
logger.error(`Failed to reset role hoist ordering in guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const remove = async (guildId: string): Promise<void> => {
|
||||
export async function remove(guildId: string): Promise<void> {
|
||||
try {
|
||||
await http.post({url: Endpoints.GUILD_DELETE(guildId), body: {}});
|
||||
logger.debug(`Deleted guild ${guildId}`);
|
||||
@@ -241,9 +226,9 @@ export const remove = async (guildId: string): Promise<void> => {
|
||||
logger.error(`Failed to delete guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const leave = async (guildId: string): Promise<void> => {
|
||||
export async function leave(guildId: string): Promise<void> {
|
||||
try {
|
||||
await http.delete({url: Endpoints.USER_GUILDS(guildId)});
|
||||
logger.debug(`Left guild ${guildId}`);
|
||||
@@ -251,9 +236,9 @@ export const leave = async (guildId: string): Promise<void> => {
|
||||
logger.error(`Failed to leave guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const fetchGuildInvites = async (guildId: string): Promise<Array<Invite>> => {
|
||||
export async function fetchGuildInvites(guildId: string): Promise<Array<Invite>> {
|
||||
try {
|
||||
InviteStore.handleGuildInvitesFetchPending(guildId);
|
||||
const response = await http.get<Array<Invite>>(Endpoints.GUILD_INVITES(guildId));
|
||||
@@ -265,9 +250,9 @@ export const fetchGuildInvites = async (guildId: string): Promise<Array<Invite>>
|
||||
InviteStore.handleGuildInvitesFetchError(guildId);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const toggleInvitesDisabled = async (guildId: string, disabled: boolean): Promise<Guild> => {
|
||||
export async function toggleInvitesDisabled(guildId: string, disabled: boolean): Promise<Guild> {
|
||||
try {
|
||||
const response = await http.patch<Guild>(Endpoints.GUILD(guildId), {
|
||||
features: disabled ? ['INVITES_DISABLED'] : [],
|
||||
@@ -279,9 +264,9 @@ export const toggleInvitesDisabled = async (guildId: string, disabled: boolean):
|
||||
logger.error(`Failed to ${disabled ? 'disable' : 'enable'} invites for guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const toggleTextChannelFlexibleNames = async (guildId: string, enabled: boolean): Promise<Guild> => {
|
||||
export async function toggleTextChannelFlexibleNames(guildId: string, enabled: boolean): Promise<Guild> {
|
||||
try {
|
||||
const response = await http.patch<Guild>(Endpoints.GUILD_TEXT_CHANNEL_FLEXIBLE_NAMES(guildId), {enabled});
|
||||
const guild = response.body;
|
||||
@@ -294,9 +279,9 @@ export const toggleTextChannelFlexibleNames = async (guildId: string, enabled: b
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const toggleDetachedBanner = async (guildId: string, enabled: boolean): Promise<Guild> => {
|
||||
export async function toggleDetachedBanner(guildId: string, enabled: boolean): Promise<Guild> {
|
||||
try {
|
||||
const response = await http.patch<Guild>(Endpoints.GUILD_DETACHED_BANNER(guildId), {enabled});
|
||||
const guild = response.body;
|
||||
@@ -306,24 +291,9 @@ export const toggleDetachedBanner = async (guildId: string, enabled: boolean): P
|
||||
logger.error(`Failed to ${enabled ? 'enable' : 'disable'} detached banner for guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const toggleDisallowUnclaimedAccounts = async (guildId: string, enabled: boolean): Promise<Guild> => {
|
||||
try {
|
||||
const response = await http.patch<Guild>(Endpoints.GUILD_DISALLOW_UNCLAIMED_ACCOUNTS(guildId), {enabled});
|
||||
const guild = response.body;
|
||||
logger.debug(`${enabled ? 'Enabled' : 'Disabled'} disallow unclaimed accounts for guild ${guildId}`);
|
||||
return guild;
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`Failed to ${enabled ? 'enable' : 'disable'} disallow unclaimed accounts for guild ${guildId}:`,
|
||||
error,
|
||||
);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const transferOwnership = async (guildId: string, newOwnerId: string): Promise<Guild> => {
|
||||
export async function transferOwnership(guildId: string, newOwnerId: string): Promise<Guild> {
|
||||
try {
|
||||
const response = await http.post<Guild>(Endpoints.GUILD_TRANSFER_OWNERSHIP(guildId), {
|
||||
new_owner_id: newOwnerId,
|
||||
@@ -335,15 +305,15 @@ export const transferOwnership = async (guildId: string, newOwnerId: string): Pr
|
||||
logger.error(`Failed to transfer ownership of guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const banMember = async (
|
||||
export async function banMember(
|
||||
guildId: string,
|
||||
userId: string,
|
||||
deleteMessageDays?: number,
|
||||
reason?: string,
|
||||
banDurationSeconds?: number,
|
||||
): Promise<void> => {
|
||||
): Promise<void> {
|
||||
try {
|
||||
await http.put({
|
||||
url: Endpoints.GUILD_BAN(guildId, userId),
|
||||
@@ -358,9 +328,9 @@ export const banMember = async (
|
||||
logger.error(`Failed to ban user ${userId} from guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const unbanMember = async (guildId: string, userId: string): Promise<void> => {
|
||||
export async function unbanMember(guildId: string, userId: string): Promise<void> {
|
||||
try {
|
||||
await http.delete({url: Endpoints.GUILD_BAN(guildId, userId)});
|
||||
logger.debug(`Unbanned user ${userId} from guild ${guildId}`);
|
||||
@@ -368,9 +338,9 @@ export const unbanMember = async (guildId: string, userId: string): Promise<void
|
||||
logger.error(`Failed to unban user ${userId} from guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const fetchBans = async (guildId: string): Promise<Array<GuildBan>> => {
|
||||
export async function fetchBans(guildId: string): Promise<Array<GuildBan>> {
|
||||
try {
|
||||
const response = await http.get<Array<GuildBan>>(Endpoints.GUILD_BANS(guildId));
|
||||
const bans = response.body;
|
||||
@@ -380,12 +350,12 @@ export const fetchBans = async (guildId: string): Promise<Array<GuildBan>> => {
|
||||
logger.error(`Failed to fetch bans for guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export const fetchGuildAuditLogs = async (
|
||||
export async function fetchGuildAuditLogs(
|
||||
guildId: string,
|
||||
params: GuildAuditLogFetchParams,
|
||||
): Promise<GuildAuditLogFetchResponse> => {
|
||||
): Promise<GuildAuditLogFetchResponse> {
|
||||
try {
|
||||
const query: Record<string, string | number> = {};
|
||||
if (params.limit !== undefined) query.limit = params.limit;
|
||||
@@ -406,4 +376,4 @@ export const fetchGuildAuditLogs = async (
|
||||
logger.error(`Failed to fetch audit logs for guild ${guildId}:`, error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user