@@ -17,7 +17,7 @@ import {
1717 unmuteGuildMember ,
1818} from "./modules/index.js" ;
1919
20- import type { Bot , GuildMuteDurations } from "../types/index.d.ts" ;
20+ import type { Bot , GuildMuteDurations , PluginOptions } from "../types/index.d.ts" ;
2121
2222/**
2323 * Injects the HyFlayer Plugin into a Mineflayer Bot
@@ -33,52 +33,58 @@ import type { Bot, GuildMuteDurations } from "../types/index.d.ts";
3333 * version: "1.8.9",
3434 * }) as HyFlayerBot
3535 *
36- * bot.loadPlugin(HyFlayer);
36+ * const hyflayer = HyFlayer()
37+ *
38+ * bot.loadPlugin(hyflayer);
3739 * ```
3840 */
39- export const HyFlayer = ( bot : Bot ) : void => {
40- /* Structures */
41- bot . mowojang = new MowojangClient ( ) ;
42- bot . hypixel = {
43- proxy : {
44- ip : undefined ,
45- port : undefined ,
46- latency : undefined ,
47- } ,
48- location : { } ,
49- } as Bot [ "hypixel" ] ;
41+ export const HyFlayer = ( options ?: PluginOptions ) => {
42+ const mowojang = options ?. mowojang ?? new MowojangClient ( ) ;
43+
44+ return ( bot : Bot ) : void => {
45+ /* Structures */
46+ bot . mowojang = mowojang ;
47+ bot . hypixel = {
48+ proxy : {
49+ ip : undefined ,
50+ port : undefined ,
51+ latency : undefined ,
52+ } ,
53+ location : { } ,
54+ } as Bot [ "hypixel" ] ;
5055
51- /* Functions */
52- bot . sendGuildMessage = ( msg : string ) => sendGuildMessage ( bot , msg ) ;
53- bot . sendGuildOfficerMessage = ( msg : string ) => sendGuildOfficerMessage ( bot , msg ) ;
54- bot . toggleGuildSlowChat = ( ) => toggleGuildSlowChat ( bot ) ;
55- bot . muteGuildChat = ( duration : GuildMuteDurations ) => muteGuildChat ( bot , duration ) ;
56- bot . muteGuildMember = ( member : string , duration : GuildMuteDurations ) => muteGuildMember ( bot , member , duration ) ;
57- bot . unmuteGuildChat = ( ) => unmuteGuildChat ( bot ) ;
58- bot . unmuteGuildMember = ( member : string ) => unmuteGuildMember ( bot , member ) ;
59- bot . sendPrivateMessage = ( player : string , msg : string ) => sendPrivateMessage ( bot , player , msg ) ;
60- bot . sendSkyblockCoopMessage = ( msg : string ) => sendSkyblockCoopMessage ( bot , msg ) ;
56+ /* Functions */
57+ bot . sendGuildMessage = ( msg : string ) => sendGuildMessage ( bot , msg ) ;
58+ bot . sendGuildOfficerMessage = ( msg : string ) => sendGuildOfficerMessage ( bot , msg ) ;
59+ bot . toggleGuildSlowChat = ( ) => toggleGuildSlowChat ( bot ) ;
60+ bot . muteGuildChat = ( duration : GuildMuteDurations ) => muteGuildChat ( bot , duration ) ;
61+ bot . muteGuildMember = ( member : string , duration : GuildMuteDurations ) => muteGuildMember ( bot , member , duration ) ;
62+ bot . unmuteGuildChat = ( ) => unmuteGuildChat ( bot ) ;
63+ bot . unmuteGuildMember = ( member : string ) => unmuteGuildMember ( bot , member ) ;
64+ bot . sendPrivateMessage = ( player : string , msg : string ) => sendPrivateMessage ( bot , player , msg ) ;
65+ bot . sendSkyblockCoopMessage = ( msg : string ) => sendSkyblockCoopMessage ( bot , msg ) ;
6166
62- /* Proxy Parsing */
63- bot . once ( "login" , ( ) => {
64- bot . hypixel . proxy = {
65- ip : bot . _client ?. socket ?. remoteAddress ,
66- port : bot . _client ?. socket ?. remotePort ,
67- latency : bot ?. player ?. ping || undefined ,
68- } ;
69- setInterval ( ( ) => {
70- bot . hypixel . proxy . latency = bot ?. player ?. ping || undefined ;
71- } , 60000 ) ;
72- } ) ;
67+ /* Proxy Parsing */
68+ bot . once ( "login" , ( ) => {
69+ bot . hypixel . proxy = {
70+ ip : bot . _client ?. socket ?. remoteAddress ,
71+ port : bot . _client ?. socket ?. remotePort ,
72+ latency : bot ?. player ?. ping || undefined ,
73+ } ;
74+ setInterval ( ( ) => {
75+ bot . hypixel . proxy . latency = bot ?. player ?. ping || undefined ;
76+ } , 60000 ) ;
77+ } ) ;
7378
74- /* Location Parsing */
75- parseLocation ( bot ) ;
76- bot . once ( "spawn" , ( ) => getLocation ( bot ) ) ;
77- bot . on ( "respawn" , ( ) => getLocation ( bot ) ) ;
79+ /* Location Parsing */
80+ parseLocation ( bot ) ;
81+ bot . once ( "spawn" , ( ) => getLocation ( bot ) ) ;
82+ bot . on ( "respawn" , ( ) => getLocation ( bot ) ) ;
7883
79- /* Chat Parsers */
80- parsePrivateChat ( bot ) ;
81- parseSkyblockCoopChat ( bot ) ;
82- parseGuildChat ( bot ) ;
83- parseGuildEvents ( bot ) ;
84+ /* Chat Parsers */
85+ parsePrivateChat ( bot ) ;
86+ parseSkyblockCoopChat ( bot ) ;
87+ parseGuildChat ( bot ) ;
88+ parseGuildEvents ( bot ) ;
89+ } ;
8490} ;
0 commit comments