mirror of
https://github.com/ergochat/ergo.git
synced 2025-12-20 02:00:11 -08:00
Split NS/CS commands into separate functions
This commit is contained in:
parent
2ecec25d28
commit
3ef4c5f799
2 changed files with 296 additions and 283 deletions
100
irc/chanserv.go
100
irc/chanserv.go
|
|
@ -45,55 +45,59 @@ func (server *Server) chanservPrivmsgHandler(client *Client, message string) {
|
|||
return
|
||||
}
|
||||
|
||||
if !server.channelRegistrationEnabled {
|
||||
client.ChanServNotice(client.t("Channel registration is not enabled"))
|
||||
return
|
||||
}
|
||||
|
||||
channelName := params[1]
|
||||
channelKey, err := CasefoldChannel(channelName)
|
||||
if err != nil {
|
||||
client.ChanServNotice(client.t("Channel name is not valid"))
|
||||
return
|
||||
}
|
||||
|
||||
channelInfo := server.channels.Get(channelKey)
|
||||
if channelInfo == nil || !channelInfo.ClientIsAtLeast(client, modes.ChannelOperator) {
|
||||
client.ChanServNotice(client.t("You must be an oper on the channel to register it"))
|
||||
return
|
||||
}
|
||||
|
||||
if client.account == &NoAccount {
|
||||
client.ChanServNotice(client.t("You must be logged in to register a channel"))
|
||||
return
|
||||
}
|
||||
|
||||
// this provides the synchronization that allows exactly one registration of the channel:
|
||||
err = channelInfo.SetRegistered(client.AccountName())
|
||||
if err != nil {
|
||||
client.ChanServNotice(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// registration was successful: make the database reflect it
|
||||
go server.channelRegistry.StoreChannel(channelInfo, true)
|
||||
|
||||
client.ChanServNotice(fmt.Sprintf(client.t("Channel %s successfully registered"), channelName))
|
||||
|
||||
server.logger.Info("chanserv", fmt.Sprintf("Client %s registered channel %s", client.nick, channelName))
|
||||
server.snomasks.Send(sno.LocalChannels, fmt.Sprintf(ircfmt.Unescape("Channel registered $c[grey][$r%s$c[grey]] by $c[grey][$r%s$c[grey]]"), channelName, client.nickMaskString))
|
||||
|
||||
// give them founder privs
|
||||
change := channelInfo.applyModeMemberNoMutex(client, modes.ChannelFounder, modes.Add, client.NickCasefolded())
|
||||
if change != nil {
|
||||
//TODO(dan): we should change the name of String and make it return a slice here
|
||||
//TODO(dan): unify this code with code in modes.go
|
||||
args := append([]string{channelName}, strings.Split(change.String(), " ")...)
|
||||
for _, member := range channelInfo.Members() {
|
||||
member.Send(nil, fmt.Sprintf("ChanServ!services@%s", client.server.name), "MODE", args...)
|
||||
}
|
||||
}
|
||||
server.chanservRegisterHandler(client, params[1])
|
||||
} else {
|
||||
client.ChanServNotice(client.t("Sorry, I don't know that command"))
|
||||
}
|
||||
}
|
||||
|
||||
// chanservRegisterHandler handles the ChanServ REGISTER subcommand.
|
||||
func (server *Server) chanservRegisterHandler(client *Client, channelName string) {
|
||||
if !server.channelRegistrationEnabled {
|
||||
client.ChanServNotice(client.t("Channel registration is not enabled"))
|
||||
return
|
||||
}
|
||||
|
||||
channelKey, err := CasefoldChannel(channelName)
|
||||
if err != nil {
|
||||
client.ChanServNotice(client.t("Channel name is not valid"))
|
||||
return
|
||||
}
|
||||
|
||||
channelInfo := server.channels.Get(channelKey)
|
||||
if channelInfo == nil || !channelInfo.ClientIsAtLeast(client, modes.ChannelOperator) {
|
||||
client.ChanServNotice(client.t("You must be an oper on the channel to register it"))
|
||||
return
|
||||
}
|
||||
|
||||
if client.account == &NoAccount {
|
||||
client.ChanServNotice(client.t("You must be logged in to register a channel"))
|
||||
return
|
||||
}
|
||||
|
||||
// this provides the synchronization that allows exactly one registration of the channel:
|
||||
err = channelInfo.SetRegistered(client.AccountName())
|
||||
if err != nil {
|
||||
client.ChanServNotice(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// registration was successful: make the database reflect it
|
||||
go server.channelRegistry.StoreChannel(channelInfo, true)
|
||||
|
||||
client.ChanServNotice(fmt.Sprintf(client.t("Channel %s successfully registered"), channelName))
|
||||
|
||||
server.logger.Info("chanserv", fmt.Sprintf("Client %s registered channel %s", client.nick, channelName))
|
||||
server.snomasks.Send(sno.LocalChannels, fmt.Sprintf(ircfmt.Unescape("Channel registered $c[grey][$r%s$c[grey]] by $c[grey][$r%s$c[grey]]"), channelName, client.nickMaskString))
|
||||
|
||||
// give them founder privs
|
||||
change := channelInfo.applyModeMemberNoMutex(client, modes.ChannelFounder, modes.Add, client.NickCasefolded())
|
||||
if change != nil {
|
||||
//TODO(dan): we should change the name of String and make it return a slice here
|
||||
//TODO(dan): unify this code with code in modes.go
|
||||
args := append([]string{channelName}, strings.Split(change.String(), " ")...)
|
||||
for _, member := range channelInfo.Members() {
|
||||
member.Send(nil, fmt.Sprintf("ChanServ!services@%s", client.server.name), "MODE", args...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue