Skip to content

Commit

Permalink
Reddit: disable feeds option (botlabs-gg#981)
Browse files Browse the repository at this point in the history
* reddit disable feed option

* Update reddit.html

* update database column disabled to true if channelID 0

That should do it
  • Loading branch information
mrbentarikau authored Jun 18, 2021
1 parent c7a90bb commit ac6cca8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
7 changes: 4 additions & 3 deletions reddit/assets/reddit.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ <h3>{{if .Slow}}Slow{{else}}Fast{{end}} reddit feeds</h3>
for that.{{end}}</p>
<p>The subreddit field is just the name of the subreddit (no /r/ in front of it), examples: "games",
"multicopter"</p>
<p><b>If Server Channel is set to "None" the added or already active Reddit feed will be disabled.</b></p>
</div>
<div class="col-md-6">
<h3>New feed</h3>
Expand All @@ -68,7 +69,7 @@ <h3>New feed</h3>
<div class="form-group col">
<label for="new-channel-slow-{{.Slow}}">Server Channel</label>
<select id="new-channel-slow-{{.Slow}}" class="form-control" name="channel">
{{textChannelOptions .Dot.ActiveGuild.Channels 0 false ""}}
{{textChannelOptions .Dot.ActiveGuild.Channels 0 true "None"}}
</select>
</div>
</div>
Expand Down Expand Up @@ -111,7 +112,7 @@ <h3>Current reddit feeds</h3>
<div class="form-group col">
<label for="channel-feed-{{.ID}}">Server Channel</label>
<select id="channel-feed-{{.ID}}" class="form-control" name="channel">
{{textChannelOptions $channels .ChannelID false ""}}
{{textChannelOptions $channels .ChannelID true "None"}}
</select>
</div>
</div>
Expand Down Expand Up @@ -154,4 +155,4 @@ <h3>Current reddit feeds</h3>
</form>
<!-- /.row -->
{{end}}{{end}}
{{end}}
{{end}}
17 changes: 12 additions & 5 deletions reddit/plugin_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ const (
type CreateForm struct {
Subreddit string `schema:"subreddit" valid:",1,100"`
Slow bool `schema:"slow"`
Channel int64 `schema:"channel" valid:"channel,false`
Channel int64 `schema:"channel" valid:"channel,true`
ID int64 `schema:"id"`
UseEmbeds bool `schema:"use_embeds"`
NSFWMode int `schema:"nsfw_filter"`
MinUpvotes int `schema:"min_upvotes"`
}

type UpdateForm struct {
Channel int64 `schema:"channel" valid:"channel,false`
Channel int64 `schema:"channel" valid:"channel,true`
ID int64 `schema:"id"`
UseEmbeds bool `schema:"use_embeds"`
NSFWMode int `schema:"nsfw_filter"`
Expand All @@ -63,7 +63,7 @@ func (p *Plugin) InitWeb() {
web.CPMux.Handle(pat.New("/reddit/*"), redditMux)
web.CPMux.Handle(pat.New("/reddit"), redditMux)

// Alll handlers here require guild channels present
// All handlers here require guild channels present
redditMux.Use(web.RequireBotMemberMW)
redditMux.Use(web.RequirePermMW(discordgo.PermissionManageWebhooks))
redditMux.Use(baseData)
Expand Down Expand Up @@ -135,13 +135,17 @@ func HandleNew(w http.ResponseWriter, r *http.Request) interface{} {
Subreddit: strings.ToLower(strings.TrimSpace(newElem.Subreddit)),
UseEmbeds: newElem.UseEmbeds,
FilterNSFW: newElem.NSFWMode,
Disabled: false,
}

if newElem.Slow {
watchItem.Slow = true
watchItem.MinUpvotes = newElem.MinUpvotes
}


if watchItem.ChannelID == 0 {
watchItem.Disabled = true
}
err := watchItem.InsertG(ctx, boil.Infer())
if web.CheckErr(templateData, err, "Failed saving item :'(", web.CtxLogger(ctx).Error) {
return templateData
Expand Down Expand Up @@ -189,7 +193,10 @@ func HandleModify(w http.ResponseWriter, r *http.Request) interface{} {
if item.Slow {
item.MinUpvotes = updated.MinUpvotes
}


if item.ChannelID == 0 {
item.Disabled = true
}
_, err := item.UpdateG(ctx, boil.Whitelist("channel_id", "use_embeds", "filter_nsfw", "min_upvotes", "disabled"))
if web.CheckErr(templateData, err, "Failed saving item :'(", web.CtxLogger(ctx).Error) {
return templateData
Expand Down

0 comments on commit ac6cca8

Please sign in to comment.