Got rid of Export default's because they're bad bad

This commit is contained in:
MrMasrozYTLIVE 2024-06-16 12:19:18 +03:00
parent d7ad22b115
commit 623645090d
8 changed files with 51 additions and 58 deletions

View File

@ -1,21 +1,22 @@
import path from 'path';
import Hyperswarm, { PeerDiscovery } from 'hyperswarm';
import TextMessage from "./message/TextMessage";
import FileMessage from "./message/FileMessage";
import AudioMessage from "./message/AudioMessage";
import Message from "./message/Message";
import {TextMessage} from "./message/TextMessage";
import {FileMessage} from "./message/FileMessage";
import {AudioMessage} from "./message/AudioMessage";
import {Message} from "./message/Message";
import Corestore from 'corestore';
import Hyperdrive from 'hyperdrive';
import fs from 'fs';
// @ts-ignore
import ServeDrive from 'serve-drive';
import IconMessage from "./message/IconMessage";
import TypedEventEmitter from "./util/TypedEventEmitter";
import {IconMessage} from "./message/IconMessage";
import {TypedEventEmitter} from "./util/TypedEventEmitter";
import {LinkUpEvents} from "./LinkUpEvents";
/**
* This class is the core component of the bot system. It handles connections to the Hyperswarm network, manages message sending and receiving, and emits events for various actions.
*/
class Client extends TypedEventEmitter<LinkUpEvents> {
export class Client extends TypedEventEmitter<LinkUpEvents> {
public botName: string = "";
public servePort: number | null = 0;
public storagePath: string | undefined;
@ -325,26 +326,4 @@ class Client extends TypedEventEmitter<LinkUpEvents> {
await this.swarm?.destroy();
console.log(`Bot ${this.botName} disconnected.`);
}
}
export type LinkUpEvents = {
/**
* Triggered when a new message is received.
*
* @event Client#onMessage
* @property {TextMessage} TextMessage - Class with all of the information about received text message
* @example
* const bot = new Client("MyBot");
* bot.on('onMessage', (message) => {
* console.log(`Message from ${message.peerName}: ${message.message}`);
* });
*/
'onMessage': [textMessage: TextMessage]
'onFile': [fileMessage: FileMessage]
'onAudio': [audioMessage: AudioMessage]
'onIcon': [iconMessage: IconMessage]
'onError': [error: any]
'onBotJoinRoom': [currentTopic: string]
}
export default Client;
}

24
src/LinkUpEvents.ts Normal file
View File

@ -0,0 +1,24 @@
import {TextMessage} from "./message/TextMessage";
import {FileMessage} from "./message/FileMessage";
import {AudioMessage} from "./message/AudioMessage";
import {IconMessage} from "./message/IconMessage";
export type LinkUpEvents = {
/**
* Triggered when a new message is received.
*
* @event Client#onMessage
* @property {TextMessage} TextMessage - Class with all of the information about received text message
* @example
* const bot = new Client("MyBot");
* bot.on('onMessage', (message) => {
* console.log(`Message from ${message.peerName}: ${message.message}`);
* });
*/
'onMessage': [textMessage: TextMessage]
'onFile': [fileMessage: FileMessage]
'onAudio': [audioMessage: AudioMessage]
'onIcon': [iconMessage: IconMessage]
'onError': [error: any]
'onBotJoinRoom': [currentTopic: string]
}

View File

@ -2,11 +2,11 @@
* @module Message
*/
import Message from "./Message";
import {Message} from "./Message";
import b4a from "b4a";
import Client from "../Client";
import {Client} from "../Client";
class AudioMessage extends Message {
export class AudioMessage extends Message {
audioUrl: string;
audioType: string;
audioData: string;
@ -59,5 +59,3 @@ class AudioMessage extends Message {
return new AudioMessage(bot.botName, bot.botAvatar, bot.currentTopic, Date.now(), audioUrl, audioType, audioData);
}
}
export default AudioMessage;

View File

@ -2,11 +2,11 @@
* @module Message
*/
import Message from "./Message";
import {Message} from "./Message";
import b4a from "b4a";
import Client from "../Client";
import {Client} from "../Client";
class FileMessage extends Message {
export class FileMessage extends Message {
fileName: string;
fileUrl: string;
fileType: string;
@ -63,6 +63,4 @@ class FileMessage extends Message {
const fileData = b4a.toString(fileBuffer, 'base64'); // Convert file buffer to base64
return new FileMessage(bot.botName, bot.botAvatar, bot.currentTopic, Date.now(), fileName, fileUrl, fileType, fileData);
}
}
export default FileMessage;
}

View File

@ -2,11 +2,11 @@
* @module Message
*/
import Message from "./Message";
import {Message} from "./Message";
import b4a from "b4a";
import Client from "../Client";
import {Client} from "../Client";
class IconMessage extends Message {
export class IconMessage extends Message {
/**
* @description Creates a new icon message.
* @since 1.0
@ -31,6 +31,4 @@ class IconMessage extends Message {
static new(bot: Client, avatarBuffer: Buffer): IconMessage {
return new IconMessage(bot.botName, b4a.toString(avatarBuffer, 'base64'), Date.now());
}
}
export default IconMessage;
}

View File

@ -4,7 +4,7 @@
* @author MiTask
* @module Message
*/
class Message {
export class Message {
type: string;
peerName: string;
peerAvatar: string;
@ -54,6 +54,4 @@ class Message {
...this.toJson()
});
}
}
export default Message;
}

View File

@ -2,10 +2,10 @@
* @module Message
*/
import Message from "./Message";
import Client from "../Client";
import {Message} from "./Message";
import {Client} from "../Client";
class TextMessage extends Message {
export class TextMessage extends Message {
message: string;
/**
* @description Creates a new text message.
@ -46,6 +46,4 @@ class TextMessage extends Message {
static new(bot: Client, message: string): TextMessage {
return new TextMessage(bot.botName, bot.botAvatar, bot.currentTopic, Date.now(), message);
}
}
export default TextMessage;
}

View File

@ -4,7 +4,7 @@ import {EventEmitter} from "stream";
* This class is used for TypeSafe events.
* @internal
*/
export default class TypedEventEmitter<TEvents extends Record<string, any>> {
export class TypedEventEmitter<TEvents extends Record<string, any>> {
private emitter = new EventEmitter()
/**