aboutsummaryrefslogtreecommitdiff
path: root/go-src/utils
diff options
context:
space:
mode:
Diffstat (limited to 'go-src/utils')
-rw-r--r--go-src/utils/utils.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/go-src/utils/utils.go b/go-src/utils/utils.go
index c1bd8a4..8d0c1c7 100644
--- a/go-src/utils/utils.go
+++ b/go-src/utils/utils.go
@@ -2,6 +2,8 @@ package utils
import (
"os"
+
+ ctfcmath "gitlab.com/Syndamia/ctfc/go-src/ctfcMath"
)
// Repeats a rune given amount of times and returns the result as a string
@@ -34,10 +36,14 @@ func AppendToFile(path string, value string) {
allChatsFile.Close()
}
-func TotalPages(maxSize int, messageAmount int) int {
- return messageAmount / maxSize
+/* Pagination */
+
+const PageSize = 15
+
+func TotalPages(messageAmount int) int {
+ return ctfcmath.CeilDivInt(messageAmount, PageSize)
}
-func Paginate(page int, maxSize int, messages ...string) []string {
- return messages[len(messages)-maxSize*page : len(messages)-maxSize*(page-1)]
+func Paginate(page int, messages ...string) []string {
+ return messages[ctfcmath.MaxInt(len(messages)-PageSize*page, 0) : len(messages)-PageSize*(page-1)]
}