1
0
Fork 0
mirror of https://github.com/diamondburned/cchat-mock.git synced 2024-11-30 17:12:48 +00:00

Added mock message completiong

This commit is contained in:
diamondburned (Forefront) 2020-05-22 13:57:35 -07:00
parent 66db865abc
commit a3e768c864
3 changed files with 20 additions and 3 deletions

View file

@ -4,6 +4,7 @@ import (
"errors" "errors"
"math/rand" "math/rand"
"strconv" "strconv"
"strings"
"sync/atomic" "sync/atomic"
"time" "time"
@ -21,8 +22,10 @@ type Channel struct {
} }
var ( var (
_ cchat.Server = (*Channel)(nil) _ cchat.Server = (*Channel)(nil)
_ cchat.ServerMessage = (*Channel)(nil) _ cchat.ServerMessage = (*Channel)(nil)
_ cchat.ServerMessageSender = (*Channel)(nil)
_ cchat.ServerMessageSendCompleter = (*Channel)(nil)
) )
func (ch *Channel) ID() string { func (ch *Channel) ID() string {
@ -75,6 +78,18 @@ func (ch *Channel) SendMessage(msg cchat.SendableMessage) error {
return nil return nil
} }
func (ch *Channel) CompleteMessage(words []string, i int) []string {
switch {
case strings.HasPrefix("complete", words[i]):
words[i] = "complete"
case strings.HasPrefix("me", words[i]) && i > 0 && words[i-1] == "complete":
words[i] = "me"
default:
return nil
}
return words
}
func generateChannels(s *Service, amount int) []cchat.Server { func generateChannels(s *Service, amount int) []cchat.Server {
var channels = make([]cchat.Server, amount) var channels = make([]cchat.Server, amount)
for i := range channels { for i := range channels {

2
go.mod
View file

@ -4,5 +4,5 @@ go 1.14
require ( require (
github.com/Pallinder/go-randomdata v1.2.0 github.com/Pallinder/go-randomdata v1.2.0
github.com/diamondburned/cchat v0.0.4 github.com/diamondburned/cchat v0.0.5
) )

2
go.sum
View file

@ -8,3 +8,5 @@ github.com/diamondburned/cchat v0.0.3 h1:XpuRcs+RhdFOGfsD3uCporEhVo8HQ5s95Qlj+4U
github.com/diamondburned/cchat v0.0.3/go.mod h1:2MdhWABRer4WhwcuLR0b2VY5S22Y1zDTpFqriAFrC08= github.com/diamondburned/cchat v0.0.3/go.mod h1:2MdhWABRer4WhwcuLR0b2VY5S22Y1zDTpFqriAFrC08=
github.com/diamondburned/cchat v0.0.4 h1:RSuAX3T4PsPOPBDNZMTt6Mr+g1UZQ3A7vSBf9QPS7uQ= github.com/diamondburned/cchat v0.0.4 h1:RSuAX3T4PsPOPBDNZMTt6Mr+g1UZQ3A7vSBf9QPS7uQ=
github.com/diamondburned/cchat v0.0.4/go.mod h1:2MdhWABRer4WhwcuLR0b2VY5S22Y1zDTpFqriAFrC08= github.com/diamondburned/cchat v0.0.4/go.mod h1:2MdhWABRer4WhwcuLR0b2VY5S22Y1zDTpFqriAFrC08=
github.com/diamondburned/cchat v0.0.5 h1:g0+569jnFqx4euNsqjurqjAY+xxG5n8kmGnDRwA8qFs=
github.com/diamondburned/cchat v0.0.5/go.mod h1:2MdhWABRer4WhwcuLR0b2VY5S22Y1zDTpFqriAFrC08=