diff --git a/src/internal/gomatrixbot/commands.go b/src/internal/gomatrixbot/commands.go index b999e42..081cc09 100644 --- a/src/internal/gomatrixbot/commands.go +++ b/src/internal/gomatrixbot/commands.go @@ -3,6 +3,7 @@ package gomatrixbot import ( "context" "fmt" + "math/rand" "os" "strings" "time" @@ -260,15 +261,19 @@ func (mtrx *MtrxClient) handleCommand(ctx context.Context, evt *event.Event) { } filesearch := strings.ReplaceAll(args[0], ".", "") - //filename quote - for _, v := range mtrx.pics { + // lookup filename from quote, shuffle each time + tmpPics := make([]string, len(mtrx.pics)) + perm := rand.Perm(len(mtrx.pics)) + for i, v := range perm { + tmpPics[v] = mtrx.pics[i] + } + + for _, v := range tmpPics { if strings.Contains(strings.ToLower(strings.Split(v, ".")[0]), strings.ToLower(filesearch)) { mtrx.postBirbWithText(ctx, evt, mtrx.getAnyRandomQuoteSearch(true, strings.Join(args[1:], " ")), 0, v) return } } - - // mtrx.sendMessage(ctx, evt.RoomID, "Can't find file with prefix: "+file) } }