Format application permission overrides better
This commit is contained in:
Vendored
+12
@@ -8,6 +8,18 @@ export type RoleChangeLog = {
|
|||||||
new?: Pick<APIRole, 'id' | 'name'>[]
|
new?: Pick<APIRole, 'id' | 'name'>[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ApplicationCommandPermission = {
|
||||||
|
type: 1 | 2 | 3,
|
||||||
|
permission: boolean,
|
||||||
|
id: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ApplicationCommandPermissionChangeLog = {
|
||||||
|
key: sting,
|
||||||
|
old?: ApplicationCommandPermission,
|
||||||
|
new?: ApplicationCommandPermission
|
||||||
|
}
|
||||||
|
|
||||||
export type TimeoutChangeLog = {
|
export type TimeoutChangeLog = {
|
||||||
key: 'communication_disabled_until',
|
key: 'communication_disabled_until',
|
||||||
old?: string,
|
old?: string,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { AuditLogChange, AuditLogEvent, AuditLogOptionsType, GuildAuditLogsEntry, APIRole, time, TimestampStyles, PermissionsBitField, PermissionsString, Guild } from 'discord.js';
|
import { AuditLogChange, AuditLogEvent, AuditLogOptionsType, GuildAuditLogsEntry, APIRole, time, TimestampStyles, PermissionsBitField, PermissionsString, Guild } from 'discord.js';
|
||||||
import { PermissionsChangeLog, PinExtras, RoleChangeLog, TimeoutChangeLog } from '../types';
|
import { ApplicationCommandPermissionChangeLog, PermissionsChangeLog, PinExtras, RoleChangeLog, TimeoutChangeLog } from '../types';
|
||||||
import { getArrayDifference } from './array-utils';
|
import { getArrayDifference } from './array-utils';
|
||||||
|
|
||||||
export const enum TargetType {
|
export const enum TargetType {
|
||||||
@@ -55,7 +55,7 @@ export function formatSnowflake(snowflake: string, targetType: TargetType): stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function formatChanges(entry: GuildAuditLogsEntry): string {
|
export function formatChanges(entry: GuildAuditLogsEntry): string {
|
||||||
return entry.changes.map(c => formatChange(c)).filter(e => e).join('\n');
|
return entry.changes.map(c => formatChange(c, entry)).filter(e => e).join('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatExtras(entry: GuildAuditLogsEntry, guild: Guild): string {
|
export function formatExtras(entry: GuildAuditLogsEntry, guild: Guild): string {
|
||||||
@@ -90,7 +90,11 @@ export function formatExtras(entry: GuildAuditLogsEntry, guild: Guild): string {
|
|||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatChange(change: AuditLogChange): string | undefined {
|
function formatChange(change: AuditLogChange, entry: GuildAuditLogsEntry): string | undefined {
|
||||||
|
if (entry.action == AuditLogEvent.ApplicationCommandPermissionUpdate) {
|
||||||
|
return formatApplicationPermissionsUpdate(change as ApplicationCommandPermissionChangeLog);
|
||||||
|
}
|
||||||
|
|
||||||
switch (change.key) {
|
switch (change.key) {
|
||||||
case '$add':
|
case '$add':
|
||||||
case '$remove':
|
case '$remove':
|
||||||
@@ -114,6 +118,16 @@ function formatChange(change: AuditLogChange): string | undefined {
|
|||||||
return `Set ${change.key} from ${change.old} to ${change.new}`;
|
return `Set ${change.key} from ${change.old} to ${change.new}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatApplicationPermissionsUpdate(change: ApplicationCommandPermissionChangeLog): string | undefined {
|
||||||
|
if (change.new !== undefined && change.old === undefined)
|
||||||
|
return `${change.new.permission ? 'Allowed' : 'Denied'} access ${change.new.type == 3 ? 'in' : (change.new.permission ? 'to' : 'from')} ${formatSnowflake(change.new.id, change.new.type)} for command: ${change.key}`;
|
||||||
|
|
||||||
|
if (change.new === undefined && change.old !== undefined)
|
||||||
|
return `Removed permission overrides from ${formatSnowflake(change.old.id, change.old.type)} for command: ${change.key}`;
|
||||||
|
|
||||||
|
return `Updated permission overrides ${change.new!.type == 3 ? 'in' : 'for'} ${formatSnowflake(change.new!.id, change.new!.type)}: ${change.new!.permission ? 'allowed access to' : 'revoked access to'} command: ${change.key}`;
|
||||||
|
}
|
||||||
|
|
||||||
function formatMemberRoleChange(change: RoleChangeLog): string | undefined {
|
function formatMemberRoleChange(change: RoleChangeLog): string | undefined {
|
||||||
if (!change.new) return;
|
if (!change.new) return;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user