Skip to content

Commit 76f4957

Browse files
committed
fix: rename harmony to harmonix
1 parent f329d3c commit 76f4957

18 files changed

+138
-138
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ packages/*/LICENSE
1919

2020
# Generated dirs
2121
dist
22-
.harmony
23-
.harmony-*
22+
.harmonix
23+
.harmonix-*
2424
.output
2525
.output-*
2626
.gen

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 Harmony
3+
Copyright (c) 2024 Harmonix
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Harmony
1+
# Harmonix
22

33
Create Discord Bot with ease and simplicity.
44

55
## License
66

7-
Published under the [MIT](https://github.com/harmony-ts/harmony/blob/main/LICENSE) license.
7+
Published under the [MIT](https://github.com/harmonix-js/core/blob/main/LICENSE) license.
88
Made by [@nethriis](https://github.com/nethriis) 💙

bin/index.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#!/usr/bin/env node
22

3-
import { createHarmony } from '../dist/index.mjs'
3+
import { createHarmonix } from '../dist/index.mjs'
44
import 'dotenv/config'
55

6-
const initHarmony = async () => {
7-
await createHarmony({ rootDir: './playground' }, { cwd: './playground' })
6+
const initHarmonix = async () => {
7+
await createHarmonix({ rootDir: './playground' }, { cwd: './playground' })
88
}
99

10-
initHarmony()
10+
initHarmonix()

playground/harmonix.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { defineHarmonixConfig } from '../src'
2+
3+
export default defineHarmonixConfig({
4+
defaultPrefix: 'h!',
5+
clientId: '929023549656662047'
6+
})

playground/harmony.config.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/commands.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@ import { dirname } from 'pathe'
33
import { filename } from 'pathe/utils'
44
import {
55
CommandArgType,
6-
type HarmonyCommandArgType,
6+
type HarmonixCommandArgType,
77
type CommandExecute,
88
type CommandOptions,
9-
type Harmony,
10-
type HarmonyCommand,
11-
type HarmonyCommandInput,
9+
type Harmonix,
10+
type HarmonixCommand,
11+
type HarmonixCommandInput,
1212
type CommandArg,
1313
type CommandExecuteOptions,
1414
ArgumentResolver
1515
} from './types'
1616
import { SlashCommandBuilder } from 'discord.js'
1717

18-
export const resolveHarmonyCommand = (
19-
cmd: HarmonyCommandInput,
20-
harmonyOptions: Harmony['options']
21-
): HarmonyCommand<boolean> => {
18+
export const resolveHarmonixCommand = (
19+
cmd: HarmonixCommandInput,
20+
harmonixOptions: Harmonix['options']
21+
): HarmonixCommand<boolean> => {
2222
if (typeof cmd === 'string') {
23-
const _jiti = jiti(harmonyOptions.rootDir, {
23+
const _jiti = jiti(harmonixOptions.rootDir, {
2424
interopDefault: true
2525
})
2626
const _cmdPath = _jiti.resolve(cmd)
27-
const command = _jiti(_cmdPath) as HarmonyCommand<boolean>
27+
const command = _jiti(_cmdPath) as HarmonixCommand<boolean>
2828
const options: CommandOptions = {
2929
name: command.options.name || filename(_cmdPath).split('.')[0],
3030
category: command.options.category || filename(dirname(_cmdPath)),
@@ -41,11 +41,11 @@ export const resolveHarmonyCommand = (
4141
export const defineCommand = <Slash extends boolean>(
4242
options: CommandOptions & { slash?: Slash },
4343
execute: CommandExecute<Slash>
44-
): HarmonyCommand<Slash> => {
44+
): HarmonixCommand<Slash> => {
4545
return { options, execute }
4646
}
4747

48-
export const toJSON = (cmd: HarmonyCommand<true>) => {
48+
export const toJSON = (cmd: HarmonixCommand<true>) => {
4949
const builder = new SlashCommandBuilder()
5050
.setName(cmd.options.name!)
5151
.setDescription(cmd.options.description || 'No description provided')
@@ -133,7 +133,7 @@ export const toJSON = (cmd: HarmonyCommand<true>) => {
133133
}
134134

135135
export const defineArgument = <
136-
Type extends keyof HarmonyCommandArgType
136+
Type extends keyof HarmonixCommandArgType
137137
>(options: {
138138
type: Type
139139
name: string

src/discord.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import { Client, REST, Routes, Events } from 'discord.js'
2-
import type { Harmony, HarmonyCommand, HarmonyEvent } from './types'
2+
import type { Harmonix, HarmonixCommand, HarmonixEvent } from './types'
33
import 'dotenv/config'
44
import { toJSON } from './commands'
55

6-
export const initCient = (harmonyOptions: Harmony['options']) => {
7-
const client = new Client({ intents: harmonyOptions.intents })
6+
export const initCient = (harmonixOptions: Harmonix['options']) => {
7+
const client = new Client({ intents: harmonixOptions.intents })
88

9-
client.login(process.env.HARMONY_CLIENT_TOKEN)
9+
client.login(process.env.HARMONIX_CLIENT_TOKEN)
1010

1111
return client
1212
}
1313

1414
export const registerCommands = (
15-
harmony: Harmony,
16-
commands: HarmonyCommand<false>[]
15+
harmonix: Harmonix,
16+
commands: HarmonixCommand<false>[]
1717
) => {
18-
harmony.client?.on(Events.MessageCreate, (message) => {
18+
harmonix.client?.on(Events.MessageCreate, (message) => {
1919
if (message.author.bot) return
20-
const prefix = harmony.options.defaultPrefix
20+
const prefix = harmonix.options.defaultPrefix
2121
const args = message.content.slice(prefix.length).trim().split(/ +/)
2222
const command = args.shift()?.toLowerCase()
2323

@@ -28,43 +28,43 @@ export const registerCommands = (
2828
cmd?.options.args?.map((arg, i) => [arg.name, args[i]]) || []
2929
)
3030
if (!cmd || cmd.options.slash) return
31-
cmd.execute(harmony.client!, message, { slash: false, params: params })
31+
cmd.execute(harmonix.client!, message, { slash: false, params: params })
3232
})
3333
}
3434

3535
export const registerSlashCommands = async (
36-
harmony: Harmony,
37-
commands: HarmonyCommand<true>[]
36+
harmonix: Harmonix,
37+
commands: HarmonixCommand<true>[]
3838
) => {
3939
if (commands.length === 0) return
40-
const rest = new REST().setToken(process.env.HARMONY_CLIENT_TOKEN || '')
40+
const rest = new REST().setToken(process.env.HARMONIX_CLIENT_TOKEN || '')
4141

4242
await rest.put(
4343
Routes.applicationCommands(
44-
harmony.options.clientId || process.env.HARMONY_CLIENT_ID || ''
44+
harmonix.options.clientId || process.env.HARMONIX_CLIENT_ID || ''
4545
),
4646
{ body: commands.map((cmd) => toJSON(cmd)) }
4747
)
48-
harmony.client?.on('interactionCreate', (interaction) => {
48+
harmonix.client?.on('interactionCreate', (interaction) => {
4949
if (!interaction.isChatInputCommand()) return
5050
const cmd = commands.find(
5151
(cmd) => cmd.options.name === interaction.commandName
5252
)
5353

5454
if (!cmd || !cmd.options.slash) return
55-
cmd.execute(harmony.client!, interaction, {
55+
cmd.execute(harmonix.client!, interaction, {
5656
slash: true,
5757
params: interaction.options
5858
})
5959
})
6060
}
6161

62-
export const registerEvents = (harmony: Harmony, events: HarmonyEvent[]) => {
62+
export const registerEvents = (harmonix: Harmonix, events: HarmonixEvent[]) => {
6363
for (const event of events) {
6464
if (event.options.once) {
65-
harmony.client?.once(event.options.name!, event.callback)
65+
harmonix.client?.once(event.options.name!, event.callback)
6666
} else {
67-
harmony.client?.on(event.options.name!, event.callback)
67+
harmonix.client?.on(event.options.name!, event.callback)
6868
}
6969
}
7070
}

src/events.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ import type {
55
DefineEventWithOptions,
66
EventCallback,
77
EventOptions,
8-
Harmony,
9-
HarmonyEvent,
10-
HarmonyEventInput
8+
Harmonix,
9+
HarmonixEvent,
10+
HarmonixEventInput
1111
} from './types'
1212

13-
export const resolveHarmonyEvent = (
14-
evt: HarmonyEventInput,
15-
harmonyOptions: Harmony['options']
16-
): HarmonyEvent => {
13+
export const resolveHarmonixEvent = (
14+
evt: HarmonixEventInput,
15+
harmonixOptions: Harmonix['options']
16+
): HarmonixEvent => {
1717
if (typeof evt === 'string') {
18-
const _jiti = jiti(harmonyOptions.rootDir, {
18+
const _jiti = jiti(harmonixOptions.rootDir, {
1919
interopDefault: true
2020
})
2121
const _evtPath = _jiti.resolve(evt)
22-
const event = _jiti(_evtPath) as HarmonyEvent
22+
const event = _jiti(_evtPath) as HarmonixEvent
2323
const options: EventOptions = {
2424
name: event.options.name || filename(_evtPath).split('.')[0],
2525
once: event.options.once || filename(_evtPath).endsWith('.once')
@@ -33,7 +33,7 @@ export const resolveHarmonyEvent = (
3333

3434
export const defineEvent: DefineEvent & DefineEventWithOptions = (
3535
...args: [EventOptions | EventCallback, EventCallback?]
36-
): HarmonyEvent => {
36+
): HarmonixEvent => {
3737
let options: EventOptions = {}
3838

3939
if (args.length === 1) {

src/harmonix.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { LoadConfigOptions } from 'c12'
2+
import { loadOptions } from './options'
3+
import { scanCommands, scanEvents } from './scan'
4+
import { resolveHarmonixCommand } from './commands'
5+
import { resolveHarmonixEvent } from './events'
6+
import {
7+
initCient,
8+
registerCommands,
9+
registerEvents,
10+
registerSlashCommands
11+
} from './discord'
12+
import type { Harmonix, HarmonixConfig, HarmonixOptions } from './types'
13+
14+
export const createHarmonix = async (
15+
config: HarmonixConfig = {},
16+
opts: LoadConfigOptions = {}
17+
) => {
18+
const options = await loadOptions(config, opts)
19+
const harmonix: Harmonix = {
20+
options: options as HarmonixOptions
21+
}
22+
23+
const scannedCommands = await scanCommands(harmonix)
24+
const _commands = [...(harmonix.options.commands || []), ...scannedCommands]
25+
const commands = _commands.map((cmd) =>
26+
resolveHarmonixCommand(cmd, harmonix.options)
27+
)
28+
29+
const scannedEvents = await scanEvents(harmonix)
30+
const _events = [...(harmonix.options.events || []), ...scannedEvents]
31+
const events = _events.map((evt) => resolveHarmonixEvent(evt, harmonix.options))
32+
33+
harmonix.client = initCient(harmonix.options)
34+
registerCommands(
35+
harmonix,
36+
commands.filter((cmd) => !cmd.options.slash)
37+
)
38+
await registerSlashCommands(
39+
harmonix,
40+
commands.filter((cmd) => cmd.options.slash)
41+
)
42+
registerEvents(harmonix, events)
43+
44+
return harmonix
45+
}

src/harmony.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export * from './events'
22
export * from './commands'
33
export * from './options'
4-
export * from './harmony'
4+
export * from './harmonix'
55
export * from './scan'

src/options.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import { LoadConfigOptions, loadConfig } from 'c12'
22
import { resolve } from 'pathe'
3-
import type { HarmonyConfig } from './types'
3+
import type { HarmonixConfig } from './types'
44

5-
const HarmonyDefaults: HarmonyConfig = {
5+
const HarmonixDefaults: HarmonixConfig = {
66
scanDirs: [],
77
ignore: [],
88
intents: ['Guilds', 'GuildMessages', 'MessageContent']
99
}
1010

1111
export const loadOptions = async (
12-
configOverrides: HarmonyConfig = {},
12+
configOverrides: HarmonixConfig = {},
1313
opts: LoadConfigOptions
1414
) => {
15-
const { config } = await loadConfig<HarmonyConfig>({
16-
name: 'harmony',
17-
configFile: 'harmony.config',
18-
rcFile: '.harmonyrc',
15+
const { config } = await loadConfig<HarmonixConfig>({
16+
name: 'harmonix',
17+
configFile: 'harmonix.config',
18+
rcFile: '.harmonixrc',
1919
dotenv: true,
2020
globalRc: true,
2121
overrides: configOverrides,
22-
defaults: HarmonyDefaults,
22+
defaults: HarmonixDefaults,
2323
...opts
2424
})
2525

@@ -40,6 +40,6 @@ export const loadOptions = async (
4040
return options
4141
}
4242

43-
export const defineHarmonyConfig = (config: HarmonyConfig) => {
43+
export const defineHarmonixConfig = (config: HarmonixConfig) => {
4444
return config
4545
}

0 commit comments

Comments
 (0)