Skip to content

Commit

Permalink
refactor: Imports and exports. (#85)
Browse files Browse the repository at this point in the history
* refactor: Compress `role.ts`, `role-category.ts` and `role-collection.ts` into a single file `types.ts`.

* fmt: Take advantage of line width.

* refactor: Remove per-module `parameters.ts` files.
  • Loading branch information
vxern committed Nov 26, 2022
1 parent edb853d commit 9635a9d
Show file tree
Hide file tree
Showing 19 changed files with 887 additions and 273 deletions.
7 changes: 1 addition & 6 deletions assets/localisations/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ import { defaultLanguage, Language } from 'logos/types.ts';

type Expression<T> = (argument: T) => string;
type Localisations<T> = Partial<Record<Language, T>> & { [defaultLanguage]: T };
type DiscordLocalisations = Required<
Record<
'name' | 'description',
Localisations<string>
>
>;
type DiscordLocalisations = Required<Record<'name' | 'description', Localisations<string>>>;
type CommandLocalisations<
OptionKeys extends string,
StringKeys extends string,
Expand Down
627 changes: 627 additions & 0 deletions deno.lock

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/commands/moderation/commands/timeout.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { ApplicationCommandOptionTypes } from 'discordeno';
import { Commands, createLocalisations } from 'logos/assets/localisations/mod.ts';
import { CommandBuilder } from 'logos/src/commands/command.ts';
import { user } from 'logos/src/commands/parameters.ts';
import { setTimeout } from 'logos/src/commands/moderation/commands/timeout/set.ts';
import { clearTimeout } from 'logos/src/commands/moderation/commands/timeout/clear.ts';
import { duration, reason } from 'logos/src/commands/moderation/parameters.ts';
import { CommandBuilder } from 'logos/src/commands/command.ts';
import { duration, reason, user } from 'logos/src/commands/parameters.ts';

const command: CommandBuilder = {
...createLocalisations(Commands.timeout),
Expand Down
3 changes: 1 addition & 2 deletions src/commands/moderation/commands/warn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import {
sendMessage,
} from 'discordeno';
import { Commands, createLocalisations, localise } from 'logos/assets/localisations/mod.ts';
import { reason } from 'logos/src/commands/moderation/parameters.ts';
import { CommandBuilder } from 'logos/src/commands/command.ts';
import { user } from 'logos/src/commands/parameters.ts';
import { reason, user } from 'logos/src/commands/parameters.ts';
import { getRelevantWarnings } from 'logos/src/commands/moderation/module.ts';
import { log } from 'logos/src/controllers/logging/logging.ts';
import { getOrCreateUser } from 'logos/src/database/functions/users.ts';
Expand Down
18 changes: 0 additions & 18 deletions src/commands/moderation/parameters.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/commands/music/commands/now.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import {
} from 'discordeno';
import { Commands, createLocalisations, localise } from 'logos/assets/localisations/mod.ts';
import { Song, SongListingContentTypes, SongStream } from 'logos/src/commands/music/data/types.ts';
import { collection } from 'logos/src/commands/music/parameters.ts';
import { OptionBuilder } from 'logos/src/commands/command.ts';
import { show } from 'logos/src/commands/parameters.ts';
import { show, collection } from 'logos/src/commands/parameters.ts';
import { Client } from 'logos/src/client.ts';
import { chunk, paginate, parseArguments, trim } from 'logos/src/utils.ts';
import configuration from 'logos/configuration.ts';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/commands/play.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
import { Commands, createLocalisations, localise } from 'logos/assets/localisations/mod.ts';
import { ListingResolver, sources } from 'logos/src/commands/music/data/sources/sources.ts';
import { SongListingContentTypes } from 'logos/src/commands/music/data/types.ts';
import { query } from 'logos/src/commands/music/parameters.ts';
import { OptionBuilder } from 'logos/src/commands/command.ts';
import { query } from 'logos/src/commands/parameters.ts';
import { Client } from 'logos/src/client.ts';
import { parseArguments } from 'logos/src/utils.ts';
import configuration from 'logos/configuration.ts';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/commands/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
} from 'discordeno';
import { Commands, createLocalisations, localise } from 'logos/assets/localisations/mod.ts';
import { SongListingContentTypes } from 'logos/src/commands/music/data/types.ts';
import { collection } from 'logos/src/commands/music/parameters.ts';
import { OptionBuilder } from 'logos/src/commands/command.ts';
import { collection } from 'logos/src/commands/parameters.ts';
import { Client } from 'logos/src/client.ts';
import { parseArguments } from 'logos/src/utils.ts';
import configuration from 'logos/configuration.ts';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/commands/skip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
} from 'discordeno';
import { Commands, createLocalisations, localise } from 'logos/assets/localisations/mod.ts';
import { SongListingContentTypes } from 'logos/src/commands/music/data/types.ts';
import { by, collection, to } from 'logos/src/commands/music/parameters.ts';
import { OptionBuilder } from 'logos/src/commands/command.ts';
import { by, collection, to } from 'logos/src/commands/parameters.ts';
import { Client } from 'logos/src/client.ts';
import { parseArguments } from 'logos/src/utils.ts';
import configuration from 'logos/configuration.ts';
Expand Down
2 changes: 1 addition & 1 deletion src/commands/music/commands/unskip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import {
} from 'discordeno';
import { Commands, createLocalisations, localise } from 'logos/assets/localisations/mod.ts';
import { SongListingContentTypes } from 'logos/src/commands/music/data/types.ts';
import { by, collection, to } from 'logos/src/commands/music/parameters.ts';
import { OptionBuilder } from 'logos/src/commands/command.ts';
import { by, collection, to } from 'logos/src/commands/parameters.ts';
import { Client } from 'logos/src/client.ts';
import { parseArguments } from 'logos/src/utils.ts';
import configuration from 'logos/configuration.ts';
Expand Down
44 changes: 0 additions & 44 deletions src/commands/music/parameters.ts

This file was deleted.

77 changes: 75 additions & 2 deletions src/commands/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const elements: OptionBuilder = {
required: true,
};

const index: OptionBuilder = {
const elementIndex: OptionBuilder = {
...createLocalisations(Parameters.global.index),
type: ApplicationCommandOptionTypes.Integer,
required: true,
Expand All @@ -26,4 +26,77 @@ const show: OptionBuilder = {
type: ApplicationCommandOptionTypes.Boolean,
};

export { elements, index, show, user };
const duration: OptionBuilder = {
...createLocalisations(Parameters.moderation.duration),
type: ApplicationCommandOptionTypes.String,
required: true,
autocomplete: true,
};

const reason: OptionBuilder = {
...createLocalisations(Parameters.moderation.reason),
type: ApplicationCommandOptionTypes.String,
required: true,
};

const songIndex: OptionBuilder = {
...createLocalisations(Parameters.music.index),
type: ApplicationCommandOptionTypes.Integer,
required: false,
};

const query: OptionBuilder = {
...createLocalisations(Parameters.music.query),
type: ApplicationCommandOptionTypes.String,
required: true,
};

const byTimestamp: OptionBuilder = {
...createLocalisations(Parameters.music.byTimestamp),
type: ApplicationCommandOptionTypes.Integer,
required: false,
};

const toTimestamp: OptionBuilder = {
...createLocalisations(Parameters.music.toTimestamp),
type: ApplicationCommandOptionTypes.Integer,
required: false,
};

const collection: OptionBuilder = {
...createLocalisations(Parameters.music.collection),
type: ApplicationCommandOptionTypes.Boolean,
};

const by: OptionBuilder = {
...createLocalisations(Parameters.music.by),
type: ApplicationCommandOptionTypes.Integer,
};

const to: OptionBuilder = {
...createLocalisations(Parameters.music.to),
type: ApplicationCommandOptionTypes.Integer,
};

const role: OptionBuilder = {
...createLocalisations(Parameters.social.roles),
type: ApplicationCommandOptionTypes.Role,
required: true,
};

export {
by,
byTimestamp,
collection,
duration,
elementIndex,
elements,
query,
reason,
role,
show,
songIndex,
to,
toTimestamp,
user,
};
12 changes: 4 additions & 8 deletions src/commands/social/commands/profile/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@ import {
} from 'discordeno';
import { Commands, createLocalisations, localise } from 'logos/assets/localisations/mod.ts';
import { OptionBuilder } from 'logos/src/commands/command.ts';
import roles from 'logos/src/commands/social/data/roles.ts';
import { Role, RoleCategory, RoleCategoryTypes } from 'logos/src/commands/social/data/types.ts';
import {
createSelectOptionsFromCategories,
getRelevantCategories,
RoleCategory,
RoleCategoryTypes,
} from 'logos/src/commands/social/data/structures/role-category.ts';
import {
createSelectOptionsFromCollection,
getRelevantCategories,
resolveRoles,
} from 'logos/src/commands/social/data/structures/role-collection.ts';
import { Role } from 'logos/src/commands/social/data/structures/role.ts';
import roles from 'logos/src/commands/social/data/roles.ts';
} from 'logos/src/commands/social/module.ts';
import { Client } from 'logos/src/client.ts';
import { createInteractionCollector } from 'logos/src/utils.ts';
import configuration from 'logos/configuration.ts';
Expand Down
3 changes: 1 addition & 2 deletions src/commands/social/data/roles.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Roles } from 'logos/assets/localisations/mod.ts';
import { RoleCategory, RoleCategoryTypes } from 'logos/src/commands/social/data/structures/role-category.ts';
import { RoleCollectionTypes } from 'logos/src/commands/social/data/structures/role-collection.ts';
import { RoleCategory, RoleCategoryTypes, RoleCollectionTypes } from 'logos/src/commands/social/data/types.ts';
import { fromHex } from 'logos/src/utils.ts';

const categories: RoleCategory[] = [
Expand Down
108 changes: 0 additions & 108 deletions src/commands/social/data/structures/role-collection.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/commands/social/data/structures/role.ts

This file was deleted.

Loading

0 comments on commit 9635a9d

Please sign in to comment.