return errors from saypublic/sayprivate et al
This commit is contained in:
parent
444854e586
commit
9eddfc6e58
@ -468,8 +468,8 @@ func (this *AdcProtocol) ourINFO(includePid bool) string {
|
||||
return ret[1:]
|
||||
}
|
||||
|
||||
func (this *AdcProtocol) SayInfo() {
|
||||
this.hc.SayRaw("BINF " + this.escape(this.sid) + " " + this.ourINFO(true) + "\n")
|
||||
func (this *AdcProtocol) SayInfo() error {
|
||||
return this.hc.SayRaw("BINF " + this.escape(this.sid) + " " + this.ourINFO(true) + "\n")
|
||||
}
|
||||
|
||||
func (this *AdcProtocol) parts2flags(parts []string) (map[string]string, error) {
|
||||
@ -614,16 +614,17 @@ func (this *AdcProtocol) unescape(encoded string) string {
|
||||
return strings.Replace(v2, `\\`, `\`, -1)
|
||||
}
|
||||
|
||||
func (this *AdcProtocol) SayPublic(msg string) {
|
||||
this.hc.SayRaw("BMSG " + this.sid + " " + this.escape(msg) + "\n")
|
||||
func (this *AdcProtocol) SayPublic(msg string) error {
|
||||
return this.hc.SayRaw("BMSG " + this.sid + " " + this.escape(msg) + "\n")
|
||||
}
|
||||
|
||||
func (this *AdcProtocol) SayPrivate(user, message string) {
|
||||
if sid, ok := this.Nick2SID(user); ok {
|
||||
this.hc.SayRaw("DMSG " + this.sid + " " + sid + " " + this.escape(message) + "\n")
|
||||
} else {
|
||||
this.logError(fmt.Errorf("Unknown user '%s'", user))
|
||||
func (this *AdcProtocol) SayPrivate(user, message string) error {
|
||||
sid, ok := this.Nick2SID(user)
|
||||
if !ok {
|
||||
return fmt.Errorf("Unknown user '%s'", user)
|
||||
}
|
||||
|
||||
return this.hc.SayRaw("DMSG " + this.sid + " " + sid + " " + this.escape(message) + "\n")
|
||||
}
|
||||
|
||||
func (this *AdcProtocol) ProtoMessageSeparator() string {
|
||||
|
@ -49,34 +49,34 @@ func (this *AutodetectProtocol) ProcessCommand(msg string) {
|
||||
this.realProto.ProcessCommand(msg)
|
||||
}
|
||||
|
||||
func (this *AutodetectProtocol) SayPublic(msg string) {
|
||||
func (this *AutodetectProtocol) SayPublic(msg string) error {
|
||||
this.realProtoMut.Lock()
|
||||
defer this.realProtoMut.Unlock()
|
||||
|
||||
if this.realProto == nil {
|
||||
this.realProto = NewNmdcProtocol(this.hc)
|
||||
}
|
||||
this.realProto.SayPublic(msg)
|
||||
return this.realProto.SayPublic(msg)
|
||||
}
|
||||
|
||||
func (this *AutodetectProtocol) SayPrivate(user, message string) {
|
||||
func (this *AutodetectProtocol) SayPrivate(user, message string) error {
|
||||
this.realProtoMut.Lock()
|
||||
defer this.realProtoMut.Unlock()
|
||||
|
||||
if this.realProto == nil {
|
||||
this.realProto = NewNmdcProtocol(this.hc)
|
||||
}
|
||||
this.realProto.SayPrivate(user, message)
|
||||
return this.realProto.SayPrivate(user, message)
|
||||
}
|
||||
|
||||
func (this *AutodetectProtocol) SayInfo() {
|
||||
func (this *AutodetectProtocol) SayInfo() error {
|
||||
this.realProtoMut.Lock()
|
||||
defer this.realProtoMut.Unlock()
|
||||
|
||||
if this.realProto == nil {
|
||||
this.realProto = NewNmdcProtocol(this.hc)
|
||||
}
|
||||
this.realProto.SayInfo()
|
||||
return this.realProto.SayInfo()
|
||||
}
|
||||
|
||||
func (this *AutodetectProtocol) ProtoMessageSeparator() string {
|
||||
|
@ -41,16 +41,25 @@ func (this *HubConnection) Users(cb func(*map[string]UserInfo) error) error {
|
||||
return cb(&this.users)
|
||||
}
|
||||
|
||||
func (this *HubConnection) SayPublic(message string) {
|
||||
this.proto.SayPublic(message)
|
||||
func (this *HubConnection) SayPublic(message string) error {
|
||||
if this.proto == nil {
|
||||
return ErrNotConnected
|
||||
}
|
||||
return this.proto.SayPublic(message)
|
||||
}
|
||||
|
||||
func (this *HubConnection) SayPrivate(recipient string, message string) {
|
||||
this.proto.SayPrivate(recipient, message)
|
||||
func (this *HubConnection) SayPrivate(recipient string, message string) error {
|
||||
if this.proto == nil {
|
||||
return ErrNotConnected
|
||||
}
|
||||
return this.proto.SayPrivate(recipient, message)
|
||||
}
|
||||
|
||||
func (this *HubConnection) SayInfo() {
|
||||
this.proto.SayInfo()
|
||||
func (this *HubConnection) SayInfo() error {
|
||||
if this.proto == nil {
|
||||
return ErrNotConnected
|
||||
}
|
||||
return this.proto.SayInfo()
|
||||
}
|
||||
|
||||
func (this *HubConnection) UserExists(nick string) bool {
|
||||
|
@ -292,16 +292,16 @@ func (this *NmdcProtocol) unescape(encoded string) string {
|
||||
return strings.Replace(v2, "&", "&", -1)
|
||||
}
|
||||
|
||||
func (this *NmdcProtocol) SayPublic(message string) {
|
||||
this.hc.SayRaw("<" + this.hc.Hco.Self.Nick + "> " + this.escape(message) + "|")
|
||||
func (this *NmdcProtocol) SayPublic(message string) error {
|
||||
return this.hc.SayRaw("<" + this.hc.Hco.Self.Nick + "> " + this.escape(message) + "|")
|
||||
}
|
||||
|
||||
func (this *NmdcProtocol) SayPrivate(recipient, message string) {
|
||||
this.hc.SayRaw("$To: " + recipient + " From: " + this.hc.Hco.Self.Nick + " $<" + this.hc.Hco.Self.Nick + "> " + this.escape(message) + "|")
|
||||
func (this *NmdcProtocol) SayPrivate(recipient, message string) error {
|
||||
return this.hc.SayRaw("$To: " + recipient + " From: " + this.hc.Hco.Self.Nick + " $<" + this.hc.Hco.Self.Nick + "> " + this.escape(message) + "|")
|
||||
}
|
||||
|
||||
func (this *NmdcProtocol) SayInfo() {
|
||||
this.hc.SayRaw(this.getUserMyINFO(this.hc.Hco.Self) + "|")
|
||||
func (this *NmdcProtocol) SayInfo() error {
|
||||
return this.hc.SayRaw(this.getUserMyINFO(this.hc.Hco.Self) + "|")
|
||||
}
|
||||
|
||||
func (this *NmdcProtocol) parseMyINFO(protomsg string) (*UserInfo, error) {
|
||||
|
@ -3,11 +3,11 @@ package libnmdc
|
||||
type Protocol interface {
|
||||
ProcessCommand(msg string)
|
||||
|
||||
SayPublic(string)
|
||||
SayPublic(string) error
|
||||
|
||||
SayPrivate(user, message string)
|
||||
SayPrivate(user, message string) error
|
||||
|
||||
SayInfo()
|
||||
SayInfo() error
|
||||
|
||||
ProtoMessageSeparator() string
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user