Merge pull request #5 from smyalygames/main

feat(arabot): add basic functionality
This commit is contained in:
Anthony 2022-07-09 04:09:34 +01:00 committed by GitHub
commit 9c2c7766a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 106 additions and 0 deletions

14
package-lock.json generated
View File

@ -13,6 +13,7 @@
"@sapphire/ts-config": "^3.3.4",
"@types/node": "^18.0.3",
"discord.js": "^13.8.1",
"dotenv": "^16.0.1",
"typescript": "^4.7.4"
},
"devDependencies": {
@ -858,6 +859,14 @@
"node": ">=6.0.0"
}
},
"node_modules/dotenv": {
"version": "16.0.1",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.1.tgz",
"integrity": "sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ==",
"engines": {
"node": ">=12"
}
},
"node_modules/es-abstract": {
"version": "1.20.1",
"resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.20.1.tgz",
@ -3271,6 +3280,11 @@
"esutils": "^2.0.2"
}
},
"dotenv": {
"version": "16.0.1",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.1.tgz",
"integrity": "sha512-1K6hR6wtk2FviQ4kEiSjFiH5rpzEVi8WW0x96aztHVMhEspNpc4DVOUTEHtEva5VThQ8IaBX1Pe4gSzpVVUsKQ=="
},
"es-abstract": {
"version": "1.20.1",
"resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.20.1.tgz",

View File

@ -28,6 +28,7 @@
"@sapphire/ts-config": "^3.3.4",
"@types/node": "^18.0.3",
"discord.js": "^13.8.1",
"dotenv": "^16.0.1",
"typescript": "^4.7.4"
},
"devDependencies": {

39
src/commands/ping.ts Normal file
View File

@ -0,0 +1,39 @@
// SPDX-License-Identifier: GPL-3.0-or-later
/*
Animal Rights Advocates Discord Bot
Copyright (C) 2022 Anthony Berg
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { Command } from '@sapphire/framework';
import type { Message } from 'discord.js';
export class PingCommand extends Command {
public constructor(context: Command.Context) {
super(context, {
name: 'ping',
aliases: ['pong'],
description: 'ping pong',
});
}
public async messageRun(message: Message) {
const msg = await message.channel.send('Ping?');
const content = `Pong from JavaScript! Bot Latency ${Math.round(this.container.client.ws.ping)}ms. API Latency ${msg.createdTimestamp - message.createdTimestamp}ms.`;
return msg.edit(content);
}
}

52
src/index.ts Normal file
View File

@ -0,0 +1,52 @@
// SPDX-License-Identifier: GPL-3.0-or-later
/*
Animal Rights Advocates Discord Bot
Copyright (C) 2022 Anthony Berg
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
I used the Sapphire documentation and parts of the code from the Sapphire CLI to
create this file.
*/
import { LogLevel, SapphireClient } from '@sapphire/framework';
require('dotenv').config();
// Setting up the Sapphire client
const client = new SapphireClient({
defaultPrefix: process.env.DEFAULT_PREFIX,
logger: {
level: LogLevel.Debug,
},
intents:
['GUILDS',
'GUILD_MESSAGES'],
});
// Main function to log in
const main = async () => {
try {
const token = process.env.DISCORD_TOKEN;
client.logger.info('Logging in');
await client.login(token);
client.logger.info('Logged in');
} catch (error) {
client.logger.fatal(error);
client.destroy();
process.exit(1);
}
};
main();