Skip to content

Commit

Permalink
clean up templates, use go-chi, discord markdown (#22)
Browse files Browse the repository at this point in the history
* clean up templates, use go-chi, discord markdown, rewrite sitemap

* Update go.mod

Co-authored-by: IoIxD <[email protected]>
  • Loading branch information
samhza and IoIxD authored Sep 20, 2022
1 parent 795785c commit 0c881e0
Show file tree
Hide file tree
Showing 23 changed files with 978 additions and 773 deletions.
156 changes: 0 additions & 156 deletions bot.go

This file was deleted.

21 changes: 0 additions & 21 deletions config.go

This file was deleted.

55 changes: 0 additions & 55 deletions discord.go

This file was deleted.

43 changes: 27 additions & 16 deletions funcmap.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
package main

import (
"html/template"

"github.com/disgoorg/snowflake/v2"
"fmt"
"time"
)

func FuncMap(b *Bot) template.FuncMap {
return template.FuncMap{
"GetAvatarURL": b.GetAvatarURL,
"GetForums": b.GetForums,
"GetGuildName": b.GetGuildName,
"GetThreadsInChannel": b.GetThreadsInChannel,
"GetChannelTitle": b.GetChannelTitle,
"GetMessagesInChannel": b.GetMessagesInChannel,
"PostCount": b.PostCount,
"PrettyTime": PrettyTime,
"FormatDiscordThings": b.FormatDiscordThings,
"GuildNum": b.GuildNum,
"ParseSnowflake": snowflake.MustParse,
var funcMap = map[string]any{
"PrettyTime": PrettyTime,
}

func PrettyTime(timestamp time.Time) string {
unixTimeDur := time.Now().Sub(timestamp)

if unixTimeDur.Hours() >= 8760 {
return fmt.Sprintf("%0.f years ago", unixTimeDur.Hours()/8760)
}
if unixTimeDur.Hours() >= 730 {
return fmt.Sprintf("%0.f months ago", unixTimeDur.Hours()/730)
}
if unixTimeDur.Hours() >= 168 {
return fmt.Sprintf("%0.f weeks ago", unixTimeDur.Hours()/168)
}
if unixTimeDur.Hours() >= 24 {
return fmt.Sprintf("%0.f days ago", unixTimeDur.Hours()/24)
}
if unixTimeDur.Hours() >= 1 {
return fmt.Sprintf("%0.f hours ago", unixTimeDur.Hours())
}
if unixTimeDur.Minutes() >= 1 {
return fmt.Sprintf("%0.f minutes ago", unixTimeDur.Minutes())
}
return fmt.Sprintf("%0.f seconds ago", unixTimeDur.Seconds())
}
18 changes: 11 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ module github.com/IoIxD/DFS
go 1.19

require (
github.com/disgoorg/disgo v0.13.21-0.20220916011522-16246893ae55
github.com/disgoorg/log v1.2.0
github.com/disgoorg/snowflake/v2 v2.0.0
github.com/pelletier/go-toml/v2 v2.0.5
github.com/diamondburned/ningen/v3 v3.0.0-20220619214735-56004aa62571
github.com/naoina/toml v0.1.1
)

require (
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b // indirect
golang.org/x/exp v0.0.0-20220325121720-054d8573a5d8 // indirect
github.com/gorilla/schema v1.2.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/naoina/go-stringutil v0.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
go4.org v0.0.0-20200411211856-f5505b9728dd // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
)

require (
github.com/gomarkdown/markdown v0.0.0-20220905174103-7b278df48cfb
github.com/diamondburned/arikawa/v3 v3.1.1-0.20220919215554-d96ce0f54cf1
github.com/go-chi/chi/v5 v5.0.7
github.com/gorilla/websocket v1.5.0 // indirect
github.com/yuin/goldmark v1.4.14
)
Loading

0 comments on commit 0c881e0

Please sign in to comment.