@@ -3,6 +3,7 @@ import log from "../../log";
3
3
import Chan , { Channel } from "../../models/chan" ;
4
4
import Network , { NetworkWithIrcFramework } from "../../models/network" ;
5
5
import { PackageInfo } from "../packages" ;
6
+ import PublicClient from "../packages/publicClient" ;
6
7
7
8
export type PluginInputHandler = (
8
9
this : Client ,
@@ -15,7 +16,18 @@ export type PluginInputHandler = (
15
16
type Plugin = {
16
17
commands : string [ ] ;
17
18
input : ( network : Network , chan : Chan , cmd : string , args : string [ ] ) => void ;
18
- allowDisconnected ?: boolean | undefined ;
19
+ allowDisconnected ?: boolean ;
20
+ } ;
21
+
22
+ type ExternalPluginCommand = {
23
+ packageInfo : PackageInfo ;
24
+ input : (
25
+ pub : PublicClient ,
26
+ netChan : { network : Network ; chan : Chan } ,
27
+ cmd : string ,
28
+ args : string [ ]
29
+ ) => void ;
30
+ allowDisconnected ?: boolean ;
19
31
} ;
20
32
21
33
const clientSideCommands = [ "/collapse" , "/expand" , "/search" ] ;
@@ -79,7 +91,7 @@ for (const input of builtInInputs) {
79
91
} ) ;
80
92
}
81
93
82
- const pluginCommands = new Map ( ) ;
94
+ const pluginCommands = new Map < string , ExternalPluginCommand > ( ) ;
83
95
84
96
const getCommands = ( ) =>
85
97
Array . from ( userInputs . keys ( ) )
@@ -89,9 +101,22 @@ const getCommands = () =>
89
101
. concat ( passThroughCommands )
90
102
. sort ( ) ;
91
103
92
- const addPluginCommand = ( packageInfo : PackageInfo , command , func ) => {
93
- func . packageInfo = packageInfo ;
94
- pluginCommands . set ( command , func ) ;
104
+ const addPluginCommand = ( packageInfo : PackageInfo , command : any , obj : any ) => {
105
+ if ( typeof command !== "string" ) {
106
+ log . error ( `plugin {packageInfo.packageName} tried to register a bad command` ) ;
107
+ return ;
108
+ } else if ( ! obj || typeof obj . input !== "function" ) {
109
+ log . error (
110
+ `plugin ${ packageInfo . packageName } tried to register command "${ command } without a callback"`
111
+ ) ;
112
+ return ;
113
+ }
114
+
115
+ pluginCommands . set ( command , {
116
+ packageInfo : packageInfo ,
117
+ input : obj . input ,
118
+ allowDisconnected : obj . allowDisconnected ,
119
+ } ) ;
95
120
} ;
96
121
97
122
export default {
0 commit comments