1
0
Fork 0
mirror of https://github.com/Eggbertx/gochan.git synced 2025-08-02 02:36:24 -07:00

Create event for reloading board and section arrays

This commit is contained in:
Eggbertx 2024-03-13 14:58:22 -07:00
parent be3cd50c08
commit 90b98c76de
6 changed files with 20 additions and 8 deletions

View file

@ -147,6 +147,10 @@ func (ipb IPBan) IsGlobalBan() bool {
return ipb.BoardID == nil
}
func (ban IPBan) BannedForever() bool {
return ban.IsActive && ban.Permanent && !ban.CanAppeal
}
func (ipb *IPBan) Deactivate(_ int) error {
const deactivateQuery = `UPDATE DBPREFIXip_ban SET is_active = FALSE WHERE id = ?`
const auditInsertQuery = `INSERT INTO DBPREFIXip_ban_audit

View file

@ -5,18 +5,17 @@ import (
"text/template"
"github.com/gochan-org/gochan/pkg/config"
"github.com/gochan-org/gochan/pkg/events"
"github.com/gochan-org/gochan/pkg/gctemplates"
"github.com/gochan-org/gochan/pkg/gcutil"
)
func init() {
events.RegisterEvent([]string{"reset-boards-sections"}, func(trigger string, i ...interface{}) error {
return ResetBoardSectionArrays()
})
gctemplates.AddTemplateFuncs(template.FuncMap{
"bannedForever": func(ban *IPBan) bool {
return ban.IsActive && ban.Permanent && !ban.CanAppeal
},
"isBanned": func(ban *IPBan, board string) bool {
return ban.IsActive && ban.BoardID != nil
},
"banMask": func(ban IPBan) string {
if ban.ID < 1 {
if ban.RangeStart == ban.RangeEnd {

View file

@ -8,6 +8,7 @@ import (
"sort"
"github.com/gochan-org/gochan/pkg/config"
"github.com/gochan-org/gochan/pkg/events"
)
const (
@ -228,6 +229,10 @@ func ParseTemplate(name, tmplStr string) (*template.Template, error) {
// InitTemplates loads the given templates by name. If no parameters are given,
// all templates are (re)loaded
func InitTemplates(which ...string) (err error) {
if _, err, _ = events.TriggerEvent("reset-boards-sections"); err != nil {
return err
}
if which == nil {
// no templates specified
for t := range templateMap {

View file

@ -77,6 +77,7 @@ func attachFlag(request *http.Request, post *gcsql.Post, board string, errEv *ze
}
post.Flag = flag
}
fmt.Println("Flag/Country:", post.Flag, post.Country)
return nil
}

View file

@ -115,6 +115,9 @@ This is a list of events that gochan may trigger at some point and can be used i
- **message-pre-format**
- Triggered when an incoming post or post edit is about to be formatted, event data includes the post object and the HTTP request
- **reset-boards-sections**
- Triggered when the boards and sections array needs to be refreshed
- **shutdown**
- Triggered when gochan is about to shut down, in `main()` as a deferred call

View file

@ -15,7 +15,7 @@
</div><br />
<div class="section-block" style="margin: 0px 26px 0px 24px">
<div class="section-title-block">
<span class="section-title"><b>{{if bannedForever .ban}}YOUR'E PERMABANNED, IDIOT!{{else}}YOU ARE BANNED :({{end}}</b></span>
<span class="section-title"><b>{{if .ban.BannedForever}}YOUR'E PERMABANNED, IDIOT!{{else}}YOU ARE BANNED :({{end}}</b></span>
</div>
<div class="section-body" style="padding-top:8px">
<div id="ban-info" style="float:left">{{if .ban.IsGlobalBan}}
@ -34,7 +34,7 @@
<textarea rows="4" cols="48" name="appealmsg" id="postmsg" placeholder="Appeal message"></textarea><br />
<input type="submit" name="doappeal" value="Submit" /><br />
</form>{{else}}You may <b>not</b> appeal this ban.<br />{{end}}
</div>{{if bannedForever .ban}}
</div>{{if .ban.BannedForever}}
<img id="banpage-image" src="{{webPath "permabanned.jpg"}}" style="float:right; margin: 4px 8px 8px 4px"/><br />
<audio id="jack" preload="auto" autobuffer loop>
<source src="{{webPath "static/hittheroad.ogg"}}" />