All checks were successful
check / check (push) Successful in 2m28s
- Create 'type MessageType int' in pkg/irc/numerics.go - Type all Rpl*/Err* numeric constants as MessageType - Add Name() method returning the standard IRC name (e.g. RPL_WELCOME) - Add String() method returning zero-padded numeric (e.g. 001) - Update enqueueNumeric/respondIRCError to accept MessageType - Update internal/db to use MessageType conversion for Name() calls - Change names map key type from int to MessageType Refs #52
356 lines
12 KiB
Go
356 lines
12 KiB
Go
// Package irc provides constants and utilities for the
|
|
// IRC protocol, including numeric reply codes from
|
|
// RFC 1459 and RFC 2812, and standard command names.
|
|
package irc
|
|
|
|
import "fmt"
|
|
|
|
// MessageType represents an IRC numeric reply or error code.
|
|
type MessageType int
|
|
|
|
// Name returns the standard IRC name for this numeric code
|
|
// (e.g., MessageType(2).Name() returns "RPL_YOURHOST").
|
|
// Returns an empty string if the code is unknown.
|
|
func (t MessageType) Name() string {
|
|
return names[t]
|
|
}
|
|
|
|
// String returns the three-digit zero-padded string representation
|
|
// of the numeric code (e.g., MessageType(1).String() returns "001").
|
|
func (t MessageType) String() string {
|
|
return fmt.Sprintf("%03d", int(t))
|
|
}
|
|
|
|
// Connection registration replies (001-005).
|
|
const (
|
|
RplWelcome MessageType = 1
|
|
RplYourHost MessageType = 2
|
|
RplCreated MessageType = 3
|
|
RplMyInfo MessageType = 4
|
|
RplBounce MessageType = 5 // RFC 2812; also known as RPL_ISUPPORT in practice
|
|
RplIsupport MessageType = 5 // De-facto standard (same numeric as RplBounce)
|
|
)
|
|
|
|
// Command responses (200-399).
|
|
const (
|
|
// RFC 2812 trace/stats/links replies (200-219).
|
|
RplTraceLink MessageType = 200
|
|
RplTraceConnecting MessageType = 201
|
|
RplTraceHandshake MessageType = 202
|
|
RplTraceUnknown MessageType = 203
|
|
RplTraceOperator MessageType = 204
|
|
RplTraceUser MessageType = 205
|
|
RplTraceServer MessageType = 206
|
|
RplTraceService MessageType = 207
|
|
RplTraceNewType MessageType = 208
|
|
RplTraceClass MessageType = 209
|
|
RplStatsLinkInfo MessageType = 211
|
|
RplStatsCommands MessageType = 212
|
|
RplStatsCLine MessageType = 213
|
|
RplStatsNLine MessageType = 214
|
|
RplStatsILine MessageType = 215
|
|
RplStatsKLine MessageType = 216
|
|
RplStatsQLine MessageType = 217
|
|
RplStatsYLine MessageType = 218
|
|
RplEndOfStats MessageType = 219
|
|
|
|
RplUmodeIs MessageType = 221
|
|
RplServList MessageType = 234
|
|
RplServListEnd MessageType = 235
|
|
RplStatsLLine MessageType = 241
|
|
RplStatsUptime MessageType = 242
|
|
RplStatsOLine MessageType = 243
|
|
RplStatsHLine MessageType = 244
|
|
RplLuserClient MessageType = 251
|
|
RplLuserOp MessageType = 252
|
|
RplLuserUnknown MessageType = 253
|
|
|
|
RplLuserChannels MessageType = 254
|
|
RplLuserMe MessageType = 255
|
|
RplAdminMe MessageType = 256
|
|
RplAdminLoc1 MessageType = 257
|
|
RplAdminLoc2 MessageType = 258
|
|
RplAdminEmail MessageType = 259
|
|
RplTraceLog MessageType = 261
|
|
RplTraceEnd MessageType = 262
|
|
RplTryAgain MessageType = 263
|
|
|
|
RplAway MessageType = 301
|
|
RplUserHost MessageType = 302
|
|
RplIson MessageType = 303
|
|
RplUnaway MessageType = 305
|
|
RplNowAway MessageType = 306
|
|
RplWhoisUser MessageType = 311
|
|
RplWhoisServer MessageType = 312
|
|
RplWhoisOperator MessageType = 313
|
|
RplWhoWasUser MessageType = 314
|
|
RplEndOfWho MessageType = 315
|
|
RplWhoisIdle MessageType = 317
|
|
RplEndOfWhois MessageType = 318
|
|
RplWhoisChannels MessageType = 319
|
|
RplListStart MessageType = 321
|
|
RplList MessageType = 322
|
|
RplListEnd MessageType = 323
|
|
RplChannelModeIs MessageType = 324
|
|
|
|
RplUniqOpIs MessageType = 325
|
|
RplCreationTime MessageType = 329
|
|
RplNoTopic MessageType = 331
|
|
RplTopic MessageType = 332
|
|
RplTopicWhoTime MessageType = 333
|
|
RplInviting MessageType = 341
|
|
RplSummoning MessageType = 342
|
|
RplInviteList MessageType = 346
|
|
RplEndOfInviteList MessageType = 347
|
|
RplExceptList MessageType = 348
|
|
RplEndOfExceptList MessageType = 349
|
|
RplVersion MessageType = 351
|
|
RplWhoReply MessageType = 352
|
|
RplNamReply MessageType = 353
|
|
RplLinks MessageType = 364
|
|
RplEndOfLinks MessageType = 365
|
|
RplEndOfNames MessageType = 366
|
|
RplBanList MessageType = 367
|
|
RplEndOfBanList MessageType = 368
|
|
RplEndOfWhowas MessageType = 369
|
|
RplInfo MessageType = 371
|
|
RplMotd MessageType = 372
|
|
RplEndOfInfo MessageType = 374
|
|
RplMotdStart MessageType = 375
|
|
RplEndOfMotd MessageType = 376
|
|
RplYoureOper MessageType = 381
|
|
RplRehashing MessageType = 382
|
|
RplYoureService MessageType = 383
|
|
RplTime MessageType = 391
|
|
RplUsersStart MessageType = 392
|
|
RplUsers MessageType = 393
|
|
RplEndOfUsers MessageType = 394
|
|
RplNoUsers MessageType = 395
|
|
)
|
|
|
|
// Error replies (400-599).
|
|
const (
|
|
ErrNoSuchNick MessageType = 401
|
|
ErrNoSuchServer MessageType = 402
|
|
ErrNoSuchChannel MessageType = 403
|
|
ErrCannotSendToChan MessageType = 404
|
|
ErrTooManyChannels MessageType = 405
|
|
ErrWasNoSuchNick MessageType = 406
|
|
ErrTooManyTargets MessageType = 407
|
|
ErrNoSuchService MessageType = 408
|
|
ErrNoOrigin MessageType = 409
|
|
ErrNoRecipient MessageType = 411
|
|
ErrNoTextToSend MessageType = 412
|
|
ErrNoTopLevel MessageType = 413
|
|
ErrWildTopLevel MessageType = 414
|
|
ErrBadMask MessageType = 415
|
|
ErrUnknownCommand MessageType = 421
|
|
ErrNoMotd MessageType = 422
|
|
ErrNoAdminInfo MessageType = 423
|
|
ErrFileError MessageType = 424
|
|
ErrNoNicknameGiven MessageType = 431
|
|
ErrErroneusNickname MessageType = 432
|
|
ErrNicknameInUse MessageType = 433
|
|
ErrNickCollision MessageType = 436
|
|
ErrUnavailResource MessageType = 437
|
|
|
|
ErrUserNotInChannel MessageType = 441
|
|
ErrNotOnChannel MessageType = 442
|
|
ErrUserOnChannel MessageType = 443
|
|
ErrNoLogin MessageType = 444
|
|
ErrSummonDisabled MessageType = 445
|
|
ErrUsersDisabled MessageType = 446
|
|
ErrNotRegistered MessageType = 451
|
|
ErrNeedMoreParams MessageType = 461
|
|
ErrAlreadyRegistered MessageType = 462
|
|
ErrNoPermForHost MessageType = 463
|
|
ErrPasswdMismatch MessageType = 464
|
|
ErrYoureBannedCreep MessageType = 465
|
|
ErrYouWillBeBanned MessageType = 466
|
|
ErrKeySet MessageType = 467
|
|
ErrChannelIsFull MessageType = 471
|
|
ErrUnknownMode MessageType = 472
|
|
ErrInviteOnlyChan MessageType = 473
|
|
ErrBannedFromChan MessageType = 474
|
|
ErrBadChannelKey MessageType = 475
|
|
ErrBadChanMask MessageType = 476
|
|
ErrNoChanModes MessageType = 477
|
|
ErrBanListFull MessageType = 478
|
|
ErrNoPrivileges MessageType = 481
|
|
ErrChanOpPrivsNeeded MessageType = 482
|
|
ErrCantKillServer MessageType = 483
|
|
ErrRestricted MessageType = 484
|
|
ErrUniqOpPrivsNeeded MessageType = 485
|
|
ErrNoOperHost MessageType = 491
|
|
|
|
ErrUmodeUnknownFlag MessageType = 501
|
|
ErrUsersDoNotMatch MessageType = 502
|
|
)
|
|
|
|
// names maps numeric codes to their standard IRC names.
|
|
//
|
|
//nolint:gochecknoglobals
|
|
var names = map[MessageType]string{
|
|
RplWelcome: "RPL_WELCOME",
|
|
RplYourHost: "RPL_YOURHOST",
|
|
RplCreated: "RPL_CREATED",
|
|
RplMyInfo: "RPL_MYINFO",
|
|
RplBounce: "RPL_BOUNCE",
|
|
|
|
RplTraceLink: "RPL_TRACELINK",
|
|
RplTraceConnecting: "RPL_TRACECONNECTING",
|
|
RplTraceHandshake: "RPL_TRACEHANDSHAKE",
|
|
RplTraceUnknown: "RPL_TRACEUNKNOWN",
|
|
RplTraceOperator: "RPL_TRACEOPERATOR",
|
|
RplTraceUser: "RPL_TRACEUSER",
|
|
RplTraceServer: "RPL_TRACESERVER",
|
|
RplTraceService: "RPL_TRACESERVICE",
|
|
RplTraceNewType: "RPL_TRACENEWTYPE",
|
|
RplTraceClass: "RPL_TRACECLASS",
|
|
RplStatsLinkInfo: "RPL_STATSLINKINFO",
|
|
RplStatsCommands: "RPL_STATSCOMMANDS",
|
|
RplStatsCLine: "RPL_STATSCLINE",
|
|
RplStatsNLine: "RPL_STATSNLINE",
|
|
RplStatsILine: "RPL_STATSILINE",
|
|
RplStatsKLine: "RPL_STATSKLINE",
|
|
RplStatsQLine: "RPL_STATSQLINE",
|
|
RplStatsYLine: "RPL_STATSYLINE",
|
|
RplEndOfStats: "RPL_ENDOFSTATS",
|
|
|
|
RplUmodeIs: "RPL_UMODEIS",
|
|
RplServList: "RPL_SERVLIST",
|
|
RplServListEnd: "RPL_SERVLISTEND",
|
|
RplStatsLLine: "RPL_STATSLLINE",
|
|
RplStatsUptime: "RPL_STATSUPTIME",
|
|
RplStatsOLine: "RPL_STATSOLINE",
|
|
RplStatsHLine: "RPL_STATSHLINE",
|
|
RplLuserClient: "RPL_LUSERCLIENT",
|
|
RplLuserOp: "RPL_LUSEROP",
|
|
RplLuserUnknown: "RPL_LUSERUNKNOWN",
|
|
|
|
RplLuserChannels: "RPL_LUSERCHANNELS",
|
|
RplLuserMe: "RPL_LUSERME",
|
|
RplAdminMe: "RPL_ADMINME",
|
|
RplAdminLoc1: "RPL_ADMINLOC1",
|
|
RplAdminLoc2: "RPL_ADMINLOC2",
|
|
RplAdminEmail: "RPL_ADMINEMAIL",
|
|
RplTraceLog: "RPL_TRACELOG",
|
|
RplTraceEnd: "RPL_TRACEEND",
|
|
RplTryAgain: "RPL_TRYAGAIN",
|
|
|
|
RplAway: "RPL_AWAY",
|
|
RplUserHost: "RPL_USERHOST",
|
|
RplIson: "RPL_ISON",
|
|
RplUnaway: "RPL_UNAWAY",
|
|
RplNowAway: "RPL_NOWAWAY",
|
|
RplWhoisUser: "RPL_WHOISUSER",
|
|
RplWhoisServer: "RPL_WHOISSERVER",
|
|
RplWhoisOperator: "RPL_WHOISOPERATOR",
|
|
RplWhoWasUser: "RPL_WHOWASUSER",
|
|
RplEndOfWho: "RPL_ENDOFWHO",
|
|
RplWhoisIdle: "RPL_WHOISIDLE",
|
|
RplEndOfWhois: "RPL_ENDOFWHOIS",
|
|
RplWhoisChannels: "RPL_WHOISCHANNELS",
|
|
RplListStart: "RPL_LISTSTART",
|
|
RplList: "RPL_LIST",
|
|
RplListEnd: "RPL_LISTEND", //nolint:misspell
|
|
RplChannelModeIs: "RPL_CHANNELMODEIS",
|
|
|
|
RplUniqOpIs: "RPL_UNIQOPIS",
|
|
RplCreationTime: "RPL_CREATIONTIME",
|
|
RplNoTopic: "RPL_NOTOPIC",
|
|
RplTopic: "RPL_TOPIC",
|
|
RplTopicWhoTime: "RPL_TOPICWHOTIME",
|
|
RplInviting: "RPL_INVITING",
|
|
RplSummoning: "RPL_SUMMONING",
|
|
RplInviteList: "RPL_INVITELIST",
|
|
RplEndOfInviteList: "RPL_ENDOFINVITELIST",
|
|
RplExceptList: "RPL_EXCEPTLIST",
|
|
RplEndOfExceptList: "RPL_ENDOFEXCEPTLIST",
|
|
RplVersion: "RPL_VERSION",
|
|
RplWhoReply: "RPL_WHOREPLY",
|
|
RplNamReply: "RPL_NAMREPLY",
|
|
RplLinks: "RPL_LINKS",
|
|
RplEndOfLinks: "RPL_ENDOFLINKS",
|
|
RplEndOfNames: "RPL_ENDOFNAMES",
|
|
RplBanList: "RPL_BANLIST",
|
|
RplEndOfBanList: "RPL_ENDOFBANLIST",
|
|
RplEndOfWhowas: "RPL_ENDOFWHOWAS",
|
|
RplInfo: "RPL_INFO",
|
|
RplMotd: "RPL_MOTD",
|
|
RplEndOfInfo: "RPL_ENDOFINFO",
|
|
RplMotdStart: "RPL_MOTDSTART",
|
|
RplEndOfMotd: "RPL_ENDOFMOTD",
|
|
RplYoureOper: "RPL_YOUREOPER",
|
|
RplRehashing: "RPL_REHASHING",
|
|
RplYoureService: "RPL_YOURESERVICE",
|
|
RplTime: "RPL_TIME",
|
|
RplUsersStart: "RPL_USERSSTART",
|
|
RplUsers: "RPL_USERS",
|
|
RplEndOfUsers: "RPL_ENDOFUSERS",
|
|
RplNoUsers: "RPL_NOUSERS",
|
|
|
|
ErrNoSuchNick: "ERR_NOSUCHNICK",
|
|
ErrNoSuchServer: "ERR_NOSUCHSERVER",
|
|
ErrNoSuchChannel: "ERR_NOSUCHCHANNEL",
|
|
ErrCannotSendToChan: "ERR_CANNOTSENDTOCHAN",
|
|
ErrTooManyChannels: "ERR_TOOMANYCHANNELS",
|
|
ErrWasNoSuchNick: "ERR_WASNOSUCHNICK",
|
|
ErrTooManyTargets: "ERR_TOOMANYTARGETS",
|
|
ErrNoSuchService: "ERR_NOSUCHSERVICE",
|
|
ErrNoOrigin: "ERR_NOORIGIN",
|
|
ErrNoRecipient: "ERR_NORECIPIENT",
|
|
ErrNoTextToSend: "ERR_NOTEXTTOSEND",
|
|
ErrNoTopLevel: "ERR_NOTOPLEVEL",
|
|
ErrWildTopLevel: "ERR_WILDTOPLEVEL",
|
|
ErrBadMask: "ERR_BADMASK",
|
|
ErrUnknownCommand: "ERR_UNKNOWNCOMMAND",
|
|
ErrNoMotd: "ERR_NOMOTD",
|
|
ErrNoAdminInfo: "ERR_NOADMININFO",
|
|
ErrFileError: "ERR_FILEERROR",
|
|
ErrNoNicknameGiven: "ERR_NONICKNAMEGIVEN",
|
|
ErrErroneusNickname: "ERR_ERRONEUSNICKNAME",
|
|
ErrNicknameInUse: "ERR_NICKNAMEINUSE",
|
|
ErrNickCollision: "ERR_NICKCOLLISION",
|
|
ErrUnavailResource: "ERR_UNAVAILRESOURCE",
|
|
|
|
ErrUserNotInChannel: "ERR_USERNOTINCHANNEL",
|
|
ErrNotOnChannel: "ERR_NOTONCHANNEL",
|
|
ErrUserOnChannel: "ERR_USERONCHANNEL",
|
|
ErrNoLogin: "ERR_NOLOGIN",
|
|
ErrSummonDisabled: "ERR_SUMMONDISABLED",
|
|
ErrUsersDisabled: "ERR_USERSDISABLED",
|
|
ErrNotRegistered: "ERR_NOTREGISTERED",
|
|
ErrNeedMoreParams: "ERR_NEEDMOREPARAMS",
|
|
ErrAlreadyRegistered: "ERR_ALREADYREGISTERED",
|
|
ErrNoPermForHost: "ERR_NOPERMFORHOST",
|
|
ErrPasswdMismatch: "ERR_PASSWDMISMATCH",
|
|
ErrYoureBannedCreep: "ERR_YOUREBANNEDCREEP",
|
|
ErrYouWillBeBanned: "ERR_YOUWILLBEBANNED",
|
|
ErrKeySet: "ERR_KEYSET",
|
|
ErrChannelIsFull: "ERR_CHANNELISFULL",
|
|
ErrUnknownMode: "ERR_UNKNOWNMODE",
|
|
ErrInviteOnlyChan: "ERR_INVITEONLYCHAN",
|
|
ErrBannedFromChan: "ERR_BANNEDFROMCHAN",
|
|
ErrBadChannelKey: "ERR_BADCHANNELKEY",
|
|
ErrBadChanMask: "ERR_BADCHANMASK",
|
|
ErrNoChanModes: "ERR_NOCHANMODES",
|
|
ErrBanListFull: "ERR_BANLISTFULL",
|
|
ErrNoPrivileges: "ERR_NOPRIVILEGES",
|
|
ErrChanOpPrivsNeeded: "ERR_CHANOPRIVSNEEDED",
|
|
ErrCantKillServer: "ERR_CANTKILLSERVER",
|
|
ErrRestricted: "ERR_RESTRICTED",
|
|
ErrUniqOpPrivsNeeded: "ERR_UNIQOPPRIVSNEEDED",
|
|
ErrNoOperHost: "ERR_NOOPERHOST",
|
|
|
|
ErrUmodeUnknownFlag: "ERR_UMODEUNKNOWNFLAG",
|
|
ErrUsersDoNotMatch: "ERR_USERSDONTMATCH",
|
|
}
|
|
|
|
// Name returns the standard IRC name for a numeric code
|
|
// (e.g., Name(2) returns "RPL_YOURHOST"). Returns an
|
|
// empty string if the code is unknown.
|
|
func Name(code MessageType) string {
|
|
return names[code]
|
|
}
|