-
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.
Added message reader with reddit auto thread creator
- Loading branch information
Showing
4 changed files
with
59 additions
and
3 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 |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import { ExtendedClient } from "../../Client.js"; | ||
import { MessageManager } from "../../managers/messages/init.js"; | ||
import { Events } from "../base.js"; | ||
import { Message } from "discord.js"; | ||
import { Message, PartialMessage } from "discord.js"; | ||
|
||
export default new class MessageCreate extends Events { | ||
public name = "messageCreate" as const; | ||
public once = false; | ||
|
||
public execute(message: Message) { | ||
message | ||
public async execute(message: Message | PartialMessage) { | ||
const mes = message.partial ? await message.fetch() : message; | ||
const client: ExtendedClient = message.client; | ||
|
||
if (client.managers?.message instanceof MessageManager) client.managers.message.newMessage(mes); | ||
} | ||
} |
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,29 @@ | ||
import { Message } from "discord.js"; | ||
import { BaseManager } from "../base.js"; | ||
import { readdir } from "node:fs/promises"; | ||
import { URL, fileURLToPath } from "node:url"; | ||
import { BaseMessage } from "./messages/base.js"; | ||
|
||
export class MessageManager extends BaseManager { | ||
public name = "message"; | ||
#messages: BaseMessage[] = []; | ||
|
||
public async init() { | ||
const __dirname = fileURLToPath(new URL(".", import.meta.url)); | ||
const files = await readdir(__dirname + "messages"); | ||
|
||
for (const filename of files) { | ||
const message: BaseMessage = (await import(__dirname + "messages/" + filename)).default; | ||
if (!message || !message.enable) continue; | ||
this.#messages.push(message); | ||
} | ||
} | ||
|
||
public async newMessage(message: Message) { | ||
for (const messageConfig of this.#messages) { | ||
messageConfig.newMessage(message) | ||
} | ||
} | ||
} | ||
|
||
export default new MessageManager(); |
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,7 @@ | ||
import { Message } from "discord.js"; | ||
|
||
export abstract class BaseMessage { | ||
public abstract enable: boolean; | ||
|
||
public abstract newMessage(message: Message): any; | ||
} |
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,15 @@ | ||
import { Message } from "discord.js"; | ||
import { BaseMessage } from "./base.js"; | ||
|
||
export class Reddit extends BaseMessage { | ||
public enable = true; | ||
|
||
public newMessage(message: Message) { | ||
if (message.author.id !== "282286160494067712") return; | ||
|
||
const title = message.embeds[0]?.title ?? "Couldn't obtain embed title."; | ||
message.startThread({name: title.length > 100 ? title.slice(0, 97) + "..." : title}) | ||
} | ||
} | ||
|
||
export default new Reddit(); |