feat(arabot): add new scheduler plugin

This commit is contained in:
Anthony 2022-08-19 03:36:40 +01:00
parent 092dcce2fe
commit ba638bb6e2
5 changed files with 638 additions and 125 deletions

View File

@ -3,23 +3,32 @@ services:
image: postgres:14
container_name: postgres
restart: always
ports:
- 5432:5432
env_file:
- .env
volumes:
- postgres:/var/lib/postgresql/data
redis:
image: redis:7
container_name: redis
restart: always
env_file:
- .env
volumes:
- redis:/data
node:
build:
context: .
dockerfile: Dockerfile
depends_on:
- postgres
restart: on-failure
- redis
env_file:
- .env
volumes:
postgres:
name: arabot-db
redis:
name: arabot-redis

703
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -27,12 +27,15 @@
"homepage": "https://github.com/veganhacktivists/arabot#readme",
"dependencies": {
"@prisma/client": "^4.0.0",
"@sapphire/framework": "^3.0.0-next.8007303.0",
"@sapphire/framework": "^3.0.0-next.7dd13af.0",
"@sapphire/plugin-scheduled-tasks": "^4.0.0-next.15d7f9b.0",
"@sapphire/plugin-subcommands": "^2.2.2",
"@sapphire/stopwatch": "^1.4.1",
"@sapphire/ts-config": "^3.3.4",
"@sapphire/utilities": "^3.7.0",
"@types/cron": "^2.0.0",
"@types/node": "^18.0.3",
"bullmq": "^1.87.2",
"cron": "^2.1.0",
"discord-api-types": "^0.33.3",
"discord.js": "^13.9.2",
@ -42,6 +45,7 @@
"typescript": "^4.7.4"
},
"devDependencies": {
"@types/ioredis": "^4.28.10",
"@typescript-eslint/eslint-plugin": "^5.30.7",
"@typescript-eslint/parser": "^5.30.7",
"eslint": "^8.20.0",

View File

@ -21,7 +21,7 @@
*/
import { LogLevel, SapphireClient } from '@sapphire/framework';
import { ScheduleManager } from './utils/scheduleManager';
import { ScheduledTaskRedisStrategy } from '@sapphire/plugin-scheduled-tasks/register-redis';
require('dotenv').config();
@ -43,6 +43,16 @@ const client = new SapphireClient({
'DIRECT_MESSAGES',
'DIRECT_MESSAGE_REACTIONS',
],
tasks: {
// Scheduler with redis
strategy: new ScheduledTaskRedisStrategy({
bull: {
connection: {
host: 'redis',
},
},
}),
},
});
// Main function to log in
@ -57,9 +67,6 @@ const main = async () => {
client.destroy();
process.exit(1);
}
// Scheduled Commands
await ScheduleManager();
};
main();

View File

@ -17,15 +17,31 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { ScheduledTask } from '@sapphire/plugin-scheduled-tasks';
import { container } from '@sapphire/framework';
import type { TextChannel } from 'discord.js';
import IDs from '../utils/ids';
export async function standupRun() {
const { client } = container;
export class StandupTask extends ScheduledTask {
public constructor(context: ScheduledTask.Context, options: ScheduledTask.Options) {
super(context, {
...options,
cron: '0 12 * * 1',
});
}
const channel = client.channels.cache.get(IDs.channels.staff.coordinators) as TextChannel;
public async run() {
const { client } = container;
await channel.send(`Hiya <@&${IDs.roles.staff.coordinator}> it's time for your weekly standup!
const channel = client.channels.cache.get(IDs.channels.staff.coordinators) as TextChannel;
await channel.send(`Hiya <@&${IDs.roles.staff.coordinator}> it's time for your weekly standup!
\nPlease submit it in <#${IDs.channels.staff.standup}> :)`);
}
}
declare module '@sapphire/plugin-scheduled-tasks' {
interface ScheduledTasks {
cron: never;
}
}