-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit fb73bda
Showing
22 changed files
with
4,478 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Dependencies | ||
node_modules | ||
jspm_packages | ||
|
||
package-lock.json | ||
packages/*/README.md | ||
!packages/harmonix/README.md | ||
packages/*/LICENSE | ||
*/**/yarn.lock | ||
/.yarn | ||
|
||
# Logs | ||
*.log | ||
|
||
# Temp directories | ||
.temp | ||
.tmp | ||
.cache | ||
|
||
# Generated dirs | ||
dist | ||
.harmony | ||
.harmony-* | ||
.output | ||
.output-* | ||
.gen | ||
|
||
# Junit reports | ||
reports | ||
|
||
# Coverage reports | ||
coverage | ||
*.lcov | ||
.nyc_output | ||
|
||
# VSCode | ||
.vscode | ||
|
||
# Intellij idea | ||
*.iml | ||
.idea | ||
|
||
.env | ||
.pnpm-store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#!/usr/bin/env node | ||
|
||
import { loadCommands, loadEvents, loadHarmonyConfig } from '../dist/index.mjs' | ||
import { | ||
Client, | ||
Collection, | ||
SlashCommandBuilder, | ||
REST, | ||
Routes | ||
} from 'discord.js' | ||
import 'dotenv/config' | ||
|
||
const commands = loadCommands() | ||
const events = loadEvents() | ||
|
||
const client = new Client({ | ||
intents: ['Guilds', 'GuildMessages', 'MessageContent'] | ||
}) | ||
|
||
client.commands = new Collection() | ||
console.log('commands', commands) | ||
console.log('events', events) | ||
|
||
for (const command in commands) { | ||
const { slash, data, execute } = commands[command]() | ||
|
||
if (slash || data.slash) { | ||
client.commands.set(command, { | ||
data: new SlashCommandBuilder() | ||
.setName(command) | ||
.setDescription(data.description), | ||
slash: slash || data.slash, | ||
execute | ||
}) | ||
} else { | ||
client.commands.set(command, { | ||
data, | ||
slash: false, | ||
execute | ||
}) | ||
} | ||
} | ||
|
||
for (const event in events) { | ||
const { once, data, callback } = events[event]() | ||
|
||
if (once || data.once) { | ||
client.once(event, callback) | ||
} else { | ||
client.on(event, callback) | ||
} | ||
} | ||
|
||
const rest = new REST().setToken(process.env.CLIENT_TOKEN) | ||
|
||
const refreshSlashCommands = async () => { | ||
try { | ||
console.log('Started refreshing application (/) commands.') | ||
|
||
const commands = client.commands | ||
.filter((command) => command.slash) | ||
.map(({ data }) => data.toJSON()) | ||
|
||
await rest.put(Routes.applicationCommands(process.env.CLIENT_ID), { | ||
body: commands | ||
}) | ||
|
||
console.log('Successfully reloaded application (/) commands.') | ||
} catch (error) { | ||
console.log(error) | ||
} | ||
} | ||
|
||
refreshSlashCommands() | ||
|
||
client.on('interactionCreate', async (interaction) => { | ||
if (!interaction.isChatInputCommand()) return | ||
const command = interaction.client.commands.get(interaction.commandName) | ||
|
||
if (!command || !command.slash) { | ||
console.log(`No command matching ${interaction.commandName} was found.`) | ||
return | ||
} | ||
|
||
try { | ||
await command.execute(client, interaction) | ||
} catch (error) { | ||
console.log(error) | ||
if (interaction.deferred || interaction.replied) { | ||
await interaction.followUp({ | ||
content: 'There was an error while executing this command!', | ||
ephemeral: true | ||
}) | ||
} else { | ||
await interaction.reply({ | ||
content: 'There was an error while executing this command!', | ||
ephemeral: true | ||
}) | ||
} | ||
} | ||
}) | ||
|
||
client.on('messageCreate', async (message) => { | ||
const config = await loadHarmonyConfig() | ||
|
||
if (message.author.bot) return | ||
if (!message.content.startsWith(config.defaultPrefix)) return | ||
|
||
const commandName = message.content.slice(config.defaultPrefix.length) | ||
const command = client.commands.get(commandName) | ||
|
||
if (!command || command.slash) return | ||
|
||
try { | ||
await command.execute(client, message) | ||
} catch (error) { | ||
console.log(error) | ||
message.reply('There was an error while executing this command!') | ||
} | ||
}) | ||
|
||
client.login(process.env.CLIENT_TOKEN) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { defineBuildConfig } from 'unbuild' | ||
|
||
export default defineBuildConfig({ | ||
declaration: true, | ||
rollup: { | ||
inlineDependencies: true, | ||
resolve: { | ||
exportConditions: ['production', 'node'] as any | ||
} | ||
}, | ||
entries: ['./src/index'] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{ | ||
"name": "core", | ||
"version": "1.0.0", | ||
"description": "", | ||
"license": "ISC", | ||
"type": "module", | ||
"scripts": { | ||
"prepack": "unbuild", | ||
"start": "node ./bin/index.mjs", | ||
"lint": "prettier --write ." | ||
}, | ||
"types": "./dist/index.d.ts", | ||
"dependencies": { | ||
"c12": "^1.10.0", | ||
"defu": "^6.1.4", | ||
"discord.js": "^14.15.1", | ||
"dotenv": "^16.4.5", | ||
"jiti": "^1.21.0", | ||
"pathe": "^1.1.2", | ||
"unbuild": "^2.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^20.12.8", | ||
"prettier": "^3.2.5", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.4.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { defineCommand } from '../../../src' | ||
|
||
export default defineCommand( | ||
{ | ||
slash: true, | ||
description: 'Ban a user from the server', | ||
args: [ | ||
{ | ||
name: 'user', | ||
description: 'The user to kick', | ||
type: 6, | ||
required: true | ||
}, | ||
{ | ||
name: 'reason', | ||
description: 'The reason for banning the user', | ||
type: 3, | ||
required: false | ||
} | ||
] | ||
}, | ||
(_, message) => { | ||
message.reply('Banned user') | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { defineCommand } from '../../../src' | ||
|
||
export default defineCommand( | ||
{ | ||
description: 'Kick a user from the server', | ||
args: [ | ||
{ | ||
name: 'user', | ||
description: 'The user to kick', | ||
type: 6, | ||
required: true | ||
}, | ||
{ | ||
name: 'reason', | ||
description: 'The reason for kicking the user', | ||
type: 3, | ||
required: false | ||
} | ||
] | ||
}, | ||
(_, message) => { | ||
message.reply('Kicked user') | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineCommand } from '../../../src' | ||
|
||
export default defineCommand( | ||
{ | ||
description: 'Pong!' | ||
}, | ||
(client, message) => { | ||
message.reply('Pong ' + client.ws.ping + 'ms!') | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { defineCommand } from '../../../src' | ||
|
||
export default defineCommand( | ||
{ | ||
description: 'Test the bot' | ||
}, | ||
() => { | ||
console.log('Tested the bot') | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { defineEvent } from '../../src' | ||
|
||
export default defineEvent({}, (client) => { | ||
console.log(`Ready! Logged in as ${client.user?.tag}`) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { defineHarmonyConfig } from '../src' | ||
|
||
export default defineHarmonyConfig({}) |
Oops, something went wrong.