working state?
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -136,4 +136,7 @@ dist
|
|||||||
.pnp.*
|
.pnp.*
|
||||||
|
|
||||||
# VSCode Workspaces
|
# VSCode Workspaces
|
||||||
*.code-workspace
|
*.code-workspace
|
||||||
|
|
||||||
|
config.json
|
||||||
|
state.json
|
||||||
33
index.js
Normal file
33
index.js
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
// Require the necessary discord.js classes
|
||||||
|
const { Client, Events, GatewayIntentBits } = require('discord.js');
|
||||||
|
const cron = require('node-cron');
|
||||||
|
const fs = require('fs');
|
||||||
|
const torn = require('./torn.js');
|
||||||
|
|
||||||
|
const config = require('./config.json');
|
||||||
|
const state = require('./state.json');
|
||||||
|
|
||||||
|
// Create a new client instance
|
||||||
|
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||||
|
|
||||||
|
// When the client is ready, run this code (only once).
|
||||||
|
// The distinction between `client: Client<boolean>` and `readyClient: Client<true>` is important for TypeScript developers.
|
||||||
|
// It makes some properties non-nullable.
|
||||||
|
client.once(Events.ClientReady, readyClient => {
|
||||||
|
console.log(`Connected to Discord as ${readyClient.user.tag}`);
|
||||||
|
});
|
||||||
|
|
||||||
|
torn.readyCheck(config.torn);
|
||||||
|
|
||||||
|
// Log in to Discord with your client's token
|
||||||
|
client.login(config.token);
|
||||||
|
let task
|
||||||
|
fs.readdir('./tasks/', (err, files) => {
|
||||||
|
if (err) return console.log(err);
|
||||||
|
files.forEach(file => {
|
||||||
|
const task = require(`./tasks/${file}`);
|
||||||
|
const taskName = file.split('.')[0];
|
||||||
|
console.log(`Scheduling task "${taskName}" for ${task.schedule}`);
|
||||||
|
cron.schedule(task.schedule, () => { task(client, torn, config, state); });
|
||||||
|
});
|
||||||
|
});
|
||||||
1505
package-lock.json
generated
Normal file
1505
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
28
package.json
Normal file
28
package.json
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"name": "tornbot",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "echo \"Error: no test specified\" && exit 1"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/CesiumCs/tornbot.git"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/CesiumCs/tornbot/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/CesiumCs/tornbot#readme",
|
||||||
|
"description": "",
|
||||||
|
"dependencies": {
|
||||||
|
"discord.js": "^14.18.0",
|
||||||
|
"fs": "^0.0.1-security",
|
||||||
|
"node-cron": "^3.0.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^9.24.0",
|
||||||
|
"eslint": "^9.24.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
4
tasks/example.js
Normal file
4
tasks/example.js
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
module.exports = (client, config, state) => {
|
||||||
|
//console.log(`example log ${client.user.tag}`);
|
||||||
|
};
|
||||||
|
module.exports.schedule = '*/5 * * * * *';
|
||||||
9
torn.js
Normal file
9
torn.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
module.exports = (client, torn, config, state) => {
|
||||||
|
//console.log(`example log ${client.user.tag}`);
|
||||||
|
};
|
||||||
|
module.exports.readyCheck = async (key) => {
|
||||||
|
const url = `https://api.torn.com/user/?selections=basic&key=${key}`
|
||||||
|
const response = await fetch(url);
|
||||||
|
const data = await response.json();
|
||||||
|
console.log(`Connected to Torn as ${data.name} [${data.player_id}]`);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user