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 func RepeatRune(r rune, times int) (result string) { for i := 0; i < times; i++ { result += string(r) } return } // Replaces a character inside a string with a given rune at index // // Thanks https://stackoverflow.com/a/24894202/12036073 func ReplaceAtIndex(in string, r rune, i int) string { out := []rune(in) out[i] = r return string(out) } func TwoDByteArrayToStringArray(in [][]byte) (result []string) { for _, v := range in { result = append(result, string(v)) } return } func AppendToFile(path string, value string) { allChatsFile, _ := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644) allChatsFile.WriteString(value) allChatsFile.Close() } /* Pagination */ const PageSize = 15 func TotalPages(messageAmount int) int { return ctfcmath.CeilDivInt(messageAmount, PageSize) } func Paginate(page int, messages ...string) []string { return messages[ctfcmath.MaxInt(len(messages)-PageSize*page, 0) : len(messages)-PageSize*(page-1)] }