mirror of
https://github.com/mollersuite/monofile.git
synced 2024-11-21 21:36:26 -08:00
Move client to files.ts
This commit is contained in:
parent
2e29d40a1b
commit
107709a98a
|
@ -1,4 +1,3 @@
|
|||
import { IntentsBitField, Client } from "discord.js"
|
||||
import { serve } from "@hono/node-server"
|
||||
import { serveStatic } from "@hono/node-server/serve-static"
|
||||
import { Hono } from "hono"
|
||||
|
@ -67,16 +66,7 @@ if (!fs.existsSync(__dirname + "/../.data/"))
|
|||
fs.mkdirSync(__dirname + "/../.data/")
|
||||
|
||||
// discord
|
||||
|
||||
let client = new Client({
|
||||
intents: [
|
||||
IntentsBitField.Flags.GuildMessages,
|
||||
IntentsBitField.Flags.MessageContent,
|
||||
],
|
||||
rest: { timeout: config.requestTimeout },
|
||||
})
|
||||
|
||||
let files = new Files(client, config)
|
||||
let files = new Files(config)
|
||||
|
||||
const apiRouter = new APIRouter(files)
|
||||
apiRouter.loadAPIMethods().then(() => {
|
||||
|
@ -117,6 +107,4 @@ serve(
|
|||
}
|
||||
)
|
||||
|
||||
client.login(process.env.TOKEN)
|
||||
|
||||
export = app
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import axios from "axios"
|
||||
import Discord, { Client, Message, TextBasedChannel } from "discord.js"
|
||||
import Discord, { Client, Message, TextBasedChannel, IntentsBitField } from "discord.js"
|
||||
import { readFile, writeFile } from "node:fs/promises"
|
||||
import { Readable } from "node:stream"
|
||||
import crypto from "node:crypto"
|
||||
|
@ -74,14 +74,21 @@ export default class Files {
|
|||
files: { [key: string]: FilePointer } = {}
|
||||
uploadChannel?: TextBasedChannel
|
||||
|
||||
constructor(client: Client, config: Configuration) {
|
||||
constructor(config: Configuration) {
|
||||
this.config = config
|
||||
this.client = client
|
||||
this.client = new Client({
|
||||
intents: [
|
||||
IntentsBitField.Flags.GuildMessages,
|
||||
IntentsBitField.Flags.MessageContent,
|
||||
],
|
||||
rest: { timeout: config.requestTimeout },
|
||||
})
|
||||
|
||||
|
||||
client.on("ready", () => {
|
||||
this.client.on("ready", () => {
|
||||
console.log("Discord OK!")
|
||||
|
||||
client.guilds.fetch(config.targetGuild).then((g) => {
|
||||
this.client.guilds.fetch(config.targetGuild).then((g) => {
|
||||
g.channels.fetch(config.targetChannel).then((a) => {
|
||||
if (a?.isTextBased()) {
|
||||
this.uploadChannel = a
|
||||
|
@ -90,6 +97,8 @@ export default class Files {
|
|||
})
|
||||
})
|
||||
|
||||
this.client.login(process.env.TOKEN)
|
||||
|
||||
readFile(process.cwd() + "/.data/files.json")
|
||||
.then((buf) => {
|
||||
this.files = JSON.parse(buf.toString() || "{}")
|
||||
|
@ -333,6 +342,7 @@ export default class Files {
|
|||
let attach = Array.from(msg.attachments.values())
|
||||
for (
|
||||
let i =
|
||||
|
||||
useRanges && xi == scan_msg_begin
|
||||
? scan_files_begin - xi * 10
|
||||
: 0;
|
||||
|
|
Loading…
Reference in a new issue