ignix-handler 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
1
+ # ignix-handler
package/package.json CHANGED
@@ -1,6 +1,21 @@
1
1
  {
2
2
  "name": "ignix-handler",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "homepage": "https://github.com/Octane-Bot/ignix-handler#readme",
6
+ "bugs": {
7
+ "url": "https://github.com/Octane-Bot/ignix-handler/issues"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/Octane-Bot/ignix-handler.git"
12
+ },
13
+ "type": "commonjs",
14
+ "main": "src/index.js",
15
+ "scripts": {
16
+ "test": "echo \"Error: no test specified\" && exit 1"
17
+ },
18
+ "dependencies": {
19
+ "mongoose": "^9.12.1"
20
+ }
21
+ }
@@ -0,0 +1,58 @@
1
+ const getAllFiles = require('./util/get-all-files')
2
+
3
+ class CommandHandler {
4
+ // <commandName, commandObject>
5
+ commands = new Map()
6
+
7
+ constructor(commandsDir, client) {
8
+ this.commandsDir = commandsDir
9
+ this.readFiles()
10
+ this.messageListener(client)
11
+ }
12
+
13
+ readFiles() {
14
+ const files = getAllFiles(this.commandsDir)
15
+
16
+ for (let file of files) {
17
+ const commandObject = require(file)
18
+
19
+ let commandName = file.split(/[/\\]/)
20
+ commandName = commandName.pop()
21
+ commandName = commandName.split('.')[0]
22
+
23
+ if (!commandObject.callback) {
24
+ throw new Error(
25
+ `Command "${commandName}" does not have a callback function.`
26
+ )
27
+ }
28
+
29
+ this.commands.set(commandName.toLowerCase(), commandObject)
30
+ }
31
+
32
+ console.log(this.commands)
33
+ }
34
+
35
+ messageListener(client) {
36
+ client.on('messageCreate', (message) => {
37
+ const { content } = message
38
+
39
+ if (!content.startsWith('!')) {
40
+ return
41
+ }
42
+
43
+ const args = content.split(/\s+/)
44
+ const commandName = args.shift().substring(1).toLowerCase()
45
+
46
+ const commandObject = this.commands.get(commandName)
47
+ if (!commandObject) {
48
+ return
49
+ }
50
+
51
+ const { callback } = commandObject
52
+
53
+ callback({ message })
54
+ })
55
+ }
56
+ }
57
+
58
+ module.exports = CommandHandler
package/src/index.js ADDED
@@ -0,0 +1,31 @@
1
+
2
+ const mongoose = require('mongoose')
3
+
4
+ const CommandHandler = require('./CommandHandler')
5
+
6
+ class Main {
7
+ constructor({ client, mongoUri, commandsDir }) {
8
+ if (!client) {
9
+ throw new Error('A client is required.')
10
+ }
11
+
12
+ if (mongoUri) {
13
+ this.connectToMongo(mongoUri)
14
+ }
15
+
16
+ if (commandsDir) {
17
+ new CommandHandler(commandsDir, client)
18
+ }
19
+ }
20
+
21
+ async connectToMongo(mongoUri) {
22
+ try {
23
+ await mongoose.connect(mongoUri)
24
+ console.log('✅ MongoDB connected successfully!')
25
+ } catch (error) {
26
+ console.error('❌ MongoDB connection failed:', error)
27
+ }
28
+ }
29
+ }
30
+
31
+ module.exports = Main
@@ -0,0 +1,24 @@
1
+ const fs = require('fs')
2
+ const path = require('path')
3
+
4
+ const getAllFiles = (dir) => {
5
+ const files = fs.readdirSync(dir, { withFileTypes: true })
6
+ const commandFiles = []
7
+
8
+ for (const file of files) {
9
+ const filePath = path.join(dir, file.name)
10
+
11
+ if (file.isDirectory()) {
12
+ commandFiles.push(...getAllFiles(filePath))
13
+ continue
14
+ }
15
+
16
+ if (file.isFile()) {
17
+ commandFiles.push(filePath)
18
+ }
19
+ }
20
+
21
+ return commandFiles
22
+ }
23
+
24
+ module.exports = getAllFiles