1- import type { TODO } from '#models' ;
1+ import type { CommandHandler , TODO } from '#models' ;
22
33/**
44 * Ban user from channel(s).
@@ -24,12 +24,37 @@ export const quiet: TODO = null;
2424 * `/unquiet * <username>`
2525 */
2626export const unquiet : TODO = null ;
27- /**
28- * Send notice to channel(s).
29- * `/notice <channel> <message>`
30- * `/notice * <message>`
31- */
32- export const notice : TODO = null ;
27+
28+ export const notice : CommandHandler = {
29+ name : 'notice' ,
30+ description : 'Send notice to specified channel or all channels if * is specified.' ,
31+ usage : '/notice <channel> <message>' ,
32+ examples : [ '/notice #general Hello, everyone' , '/notice * Hello, everyone' ] ,
33+ requiresOperator : true ,
34+ execute ( { currentChannel, args, sendMessage, stores } ) {
35+ if ( args . length < 2 ) {
36+ stores . channel . addSystemMessage (
37+ currentChannel ,
38+ 'Please provide a channel and the notice message' ,
39+ ) ;
40+ return ;
41+ }
42+
43+ const text = args . slice ( 1 ) . join ( ' ' ) ;
44+ const targetChannels : string [ ] = [ ] ;
45+ if ( args [ 0 ] === '*' ) {
46+ stores . channel . channelList . forEach ( ( channel ) => {
47+ targetChannels . push ( channel ) ;
48+ } ) ;
49+ } else {
50+ targetChannels . push ( args [ 0 ] ) ;
51+ }
52+
53+ targetChannels . forEach ( ( channel ) => {
54+ sendMessage ( channel , text , 'notice' ) ;
55+ } ) ;
56+ } ,
57+ } ;
3358/**
3459 * Ban hostmask (form: `user!nick@host`).
3560 * `/banmask <channel> <mask>`
@@ -40,16 +65,52 @@ export const banmask: TODO = null;
4065 * `/unbanmask <channel> <mask>`
4166 */
4267export const unbanmask : TODO = null ;
43- /**
44- * Get username by nick.
45- * `/user <nick>`
46- */
47- export const user : TODO = null ;
48- /**
49- * Get nicks by username.
50- * `/nicks <username>`
51- */
52- export const nicks : TODO = null ;
68+
69+ export const user : CommandHandler = {
70+ name : 'user' ,
71+ description : 'Get username by nick.' ,
72+ requiresOperator : true ,
73+ usage : '/user <nick>' ,
74+ execute ( { currentChannel, args, stores } ) {
75+ if ( args . length === 0 ) {
76+ stores . channel . addSystemMessage ( currentChannel , '"/user" requires a <nick> argument.' ) ;
77+ return ;
78+ }
79+ const nick = args [ 0 ] ;
80+ const user = stores . userList . getUserByNick ( nick ) ;
81+ if ( ! user ) {
82+ stores . channel . addSystemMessage ( currentChannel , `"${ nick } " not found.` ) ;
83+ } else {
84+ stores . channel . addSystemMessage ( currentChannel , `"${ nick } " username: ${ user . username } ` ) ;
85+ }
86+ } ,
87+ } ;
88+
89+ export const nicks : CommandHandler = {
90+ name : 'nicks' ,
91+ description : 'Get nicks by username.' ,
92+ usage : '/nicks <username>' ,
93+ requiresOperator : true ,
94+ execute ( { currentChannel, args, stores } ) {
95+ if ( args . length === 0 ) {
96+ stores . channel . addSystemMessage ( currentChannel , '"/nicks" requires a <username> argument.' ) ;
97+ return ;
98+ }
99+
100+ const username = args [ 0 ] ;
101+ const user = stores . userList . getUserByUsername ( username ) ;
102+ if ( ! user ) {
103+ stores . channel . addSystemMessage ( currentChannel , `"${ username } " not found.` ) ;
104+ } else if ( user . status === 'offline' ) {
105+ stores . channel . addSystemMessage ( currentChannel , `"${ username } " is currently offline.` ) ;
106+ } else {
107+ stores . channel . addSystemMessage (
108+ currentChannel ,
109+ `"${ username } " nicks: ${ Array . from ( user . nicks ) . join ( ', ' ) } ` ,
110+ ) ;
111+ }
112+ } ,
113+ } ;
53114/**
54115 * Kick user from channel(s).
55116 * `/kick <channel> <username> [reason]`
@@ -65,8 +126,16 @@ export const banlist: TODO = null;
65126 * `/changenick <newNick>`
66127 */
67128export const changenick : TODO = null ;
68- /**
69- * Allow operator to send a RAW command through the websocket.
70- * `/execute <line>`
71- */
72- export const execute : TODO = null ;
129+
130+ export const execute : CommandHandler = {
131+ name : 'execute' ,
132+ description :
133+ 'Allow operator to send an IRC command directly through the websocket. For using commands not yet available in the client.' ,
134+ usage : '/execute <IRC commands>' ,
135+ requiresOperator : true ,
136+ execute ( { fullText, stores } ) {
137+ if ( fullText . length > 0 ) {
138+ stores . irc . client ?. raw ( fullText ) ;
139+ }
140+ } ,
141+ } ;
0 commit comments