Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas747 committed Jul 15, 2021
2 parents 1fc8f0b + 85ab5d6 commit 119571a
Show file tree
Hide file tree
Showing 53 changed files with 1,440 additions and 694 deletions.
21 changes: 1 addition & 20 deletions .github/workflows/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:
id: changed-files
uses: tj-actions/changed-files@v2.1

- if: ${{ !contains(steps.changed-files.outputs.modified_files, 'noCopy.txt') }}
name: master comment
- name: master comment
uses: thollander/actions-comment-pull-request@master
with:
message: |
Expand All @@ -30,21 +29,3 @@ jobs:
For that, simply click the edit button next to the title of this pull request and select the new base;
To prevent conflicts, I suggest you first `git merge upstream/dev` on your local branch and push these new changes. Alternatively, `git rebase upstream/dev` on your local branch and then force-push.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- if: ${{ contains(steps.changed-files.outputs.modified_files, 'swearwords.go') }}
name: automod comment
uses: thollander/actions-comment-pull-request@master
with:
message: |
Hey @${{github.actor }}! Thank you for your interest in contributing to YAGPDB.
Unfortunately, basic automoderator will not receive **any** updates. To be able to use a custom list of swearwords, please use [automoderator v2](https://docs.yagpdb.xyz/tools-and-utilities/automoderator-v2).
As an alternative, you can amend your own words at the bottom of your basic automoderator settings.
For more information, please join the [support server](https://discord.gg/0vYlUK2XBKldPSMY).
Additionally, please do not open pull requests against the `master` branch, as stated in [CONTRIBUTING.md](../../CONTRIBUTING.md):
> push the changes you make to the dev branch (Jonas747/yagpdb/dev).
If you insist on wanting to keep this PR open, because it contains critical changes, please change the base branch to `dev`.
For that, simply click the edit button next to the title of this pull request and select the new base;
To prevent conflicts, I suggest you first `git merge upstream/dev` on your local branch and push these new changes. Alternatively, `git rebase upstream/dev` on your local branch and then force-push.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions cmd/yagpdb/templates/cp_main.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ <h2 class="card-title">
{{end}}

{{/*Specific template helpers*/}}
{{define "template_helper_user"}}<code>{{"{{"}}.User.(ID/Username/Mention/Discriminator/Bot){{"}}"}}</code>{{end}}
{{define "template_helper_guild"}}<code>{{"{{"}}.Server.(ID/Name/Icon/Owner/Permissions){{"}}"}}</code>{{end}}
{{define "template_helper_user"}}<code>{{"{{"}}.User{{"}}"}}: <a href="https://docs.yagpdb.xyz/reference/templates#user"><code>.User</code> object documentation.</a></code>{{end}}
{{define "template_helper_guild"}}<code>{{"{{"}}.Guild{{"}}"}}<a href="https://docs.yagpdb.xyz/reference/templates#guild-server"><code>.Guild</code> object reference.</a></code>{{end}}

{{define "set_roles"}}<script>var activeGuildRoles = JSON.parse('{{json .ActiveGuild.Roles}}');</script>{{end}}
25 changes: 19 additions & 6 deletions cmd/yagpdb/templates/cp_nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
</li>
</ul>
</div>
</div>
</div>

<script>
$(function(){
Expand Down Expand Up @@ -162,7 +162,7 @@
<i class="fas fa-bars" aria-label="Toggle sidebar"></i>
</div>
</div>

<div class="nano">
<div class="nano-content">
<nav id="menu" class="nav-main" role="navigation">
Expand All @@ -186,7 +186,7 @@
<ul class="nav nav-children">
{{range (index .SidebarItems "Core")}}
{{template "sidebar_item" (dict "ActiveGuild" $ag "Item" .)}}
{{end}}
{{end}}
</ul>
</li>
<li class="nav-parent ">
Expand Down Expand Up @@ -229,7 +229,7 @@
<span>Documentation</span>
</a>
</li>
</ul>
</ul>
</nav>
</div>
</div>
Expand All @@ -255,7 +255,7 @@
{{end}}
{{end}}

{{define "sidebar_item"}}
{{define "sidebar_item"}}
{{$ag := .ActiveGuild}}
{{$item := .Item}}
<li>
Expand Down Expand Up @@ -300,7 +300,12 @@

{{range $index, $element := .ManagedGuilds -}}{{if $element.Connected -}}
<li>
<a role="menuitem" tabindex="-1" href="/manage/{{$element.ID}}/home"><i class="fas fa-wrench"></i>
<a role="menuitem" tabindex="-1" href="/manage/{{$element.ID}}/home">
{{if $element.Icon}}
<img src="https://cdn.discordapp.com/icons/{{$element.ID}}/{{$element.Icon}}?size=64" class="rounded-circle server-image"></img>
{{else}}
<i class="fas fa-wrench"></i>
{{end}}
{{$element.Name}}</a>
</li>
{{end}}{{end}}
Expand All @@ -321,4 +326,12 @@
{{end}}
</ul>
</div>
<style>
.server-image {
width: 25px;
height: 25px;
margin-right: 3px;
vertical-align: middle;
}
</style>
{{end}}
3 changes: 3 additions & 0 deletions commands/tmplexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ func execCmd(tmplCtx *templates.Context, dryRun bool, m *discordgo.MessageCreate
case *discordgo.User:
cmdLine += "<@" + strconv.FormatInt(t.ID, 10) + ">"
fakeMsg.Mentions = append(fakeMsg.Mentions, t)
case discordgo.User:
cmdLine += "<@" + strconv.FormatInt(t.ID, 10) + ">"
fakeMsg.Mentions = append(fakeMsg.Mentions, &t)
case []string:
for i, str := range t {
if i != 0 {
Expand Down
4 changes: 2 additions & 2 deletions common/adjectives.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,9 @@ var Adjectives = []string{
"handsome",
"handy",
"happy",
"happy-g-lucky",
"happy-go-lucky",
"hard",
"hard-t-find",
"hard-to-find",
"harmful",
"harmless",
"harmonious",
Expand Down
25 changes: 17 additions & 8 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,17 @@ var (
})
)

var RedisAddr = loadRedisAddr()

func loadRedisAddr() string {
addr := os.Getenv("YAGPDB_REDIS")
if addr == "" {
addr = "localhost:6379"
}

return addr
}

func connectRedis(unitTests bool) (err error) {
maxConns := RedisPoolSize
if maxConns == 0 {
Expand All @@ -220,10 +231,6 @@ func connectRedis(unitTests bool) (err error) {

// we kinda bypass the config system because the config system also relies on redis
// this way the only required env var is the redis address, and per-host specific things
addr := os.Getenv("YAGPDB_REDIS")
if addr == "" {
addr = "localhost:6379"
}

opts := []radix.PoolOpt{
radix.PoolOnEmptyWait(),
Expand All @@ -233,12 +240,14 @@ func connectRedis(unitTests bool) (err error) {

// if were running unit tests, use the 2nd db to avoid accidentally running tests against a main db
if unitTests {
radix.PoolConnFunc(func(network, addr string) (radix.Conn, error) {
return radix.Dial(network, addr, radix.DialSelectDB(2))
})
opts = append(opts,
radix.PoolConnFunc(func(network, addr string) (radix.Conn, error) {
return radix.Dial(network, addr, radix.DialSelectDB(2))
}),
)
}

RedisPool, err = radix.NewPool("tcp", addr, maxConns, opts...)
RedisPool, err = radix.NewPool("tcp", RedisAddr, maxConns, opts...)
return
}

Expand Down
1 change: 0 additions & 1 deletion common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var (
ConfPQUsername = config.RegisterOption("yagpdb.pqusername", "Postgres user", "postgres")
ConfPQPassword = config.RegisterOption("yagpdb.pqpassword", "Postgres passoword", "")
ConfPQDB = config.RegisterOption("yagpdb.pqdb", "Postgres database", "yagpdb")
ConfRedis = config.RegisterOption("yagpdb.redis", "Redis address", "localhost:6379")

ConfMaxCCR = config.RegisterOption("yagpdb.max_ccr", "Maximum number of concurrent outgoing requests to discord", 25)
ConfDisableKeepalives = config.RegisterOption("yagpdb.disable_keepalives", "Disables keepalive connections for outgoing requests to discord, this shouldn't be needed but i had networking issues once so i had to", false)
Expand Down
42 changes: 42 additions & 0 deletions common/mqueue/bgworker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package mqueue

import (
"sync"
"time"

"github.com/jonas747/yagpdb/common"
"github.com/jonas747/yagpdb/common/backgroundworkers"
"github.com/mediocregopher/radix/v3"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

var _ backgroundworkers.BackgroundWorkerPlugin = (*Plugin)(nil)

// RunBackgroundWorker implements backgroundworkers.BackgroundWorkerPlugin
func (p *Plugin) RunBackgroundWorker() {
t := time.NewTicker(time.Second * 5)
for range t.C {
p.updateMetrcis()
}
}

// StopBackgroundWorker implements backgroundworkers.BackgroundWorkerPlugin
func (p *Plugin) StopBackgroundWorker(wg *sync.WaitGroup) {
wg.Done()
}

func (p *Plugin) updateMetrcis() {
var n int64
err := common.RedisPool.Do(radix.Cmd(&n, "ZCARD", "mqueue"))
if err != nil {
logger.WithError(err).Error("failed updating mqueue metrics")
}

metricsQueueSize.Set(float64(n))
}

var metricsQueueSize = promauto.NewGauge(prometheus.GaugeOpts{
Name: "yagpdb_mqueue_size_total",
Help: "The size of the send message queue",
})
Loading

0 comments on commit 119571a

Please sign in to comment.