Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
jogramming committed Nov 22, 2018
2 parents cd6bfea + c8082b4 commit 7eb684a
Show file tree
Hide file tree
Showing 71 changed files with 1,541 additions and 282 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ cmd/yagpdb/access.log
cmd/yagpdb/static/report.html
cmd/yagpdb/yagpdb
cmd/yagpdb/templates/plugins/*.html
cmd/yagpdb/soundboard
cmd/yagpdb/shutdown_logs
cmd/yagpdb/safebrowsing_db
cmd/yagpdb/static/video/*

# We don't want filthy pre-configured config files here ! >:O
# THe graw agent file
*.agent
*.exe
*.exe
2 changes: 1 addition & 1 deletion automod/automod_web.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ func CheckLimits(exec boil.ContextExecutor, rule *models.AutomodRule, tmpl web.T
maxTotalMT := GuildMaxMessageTriggers(rule.GuildID)
maxTotalVT := GuildMaxViolationTriggers(rule.GuildID)

allParts, err := models.AutomodRuleData(qm.Where("guild_id = ? AND id != ?", rule.GuildID, rule.ID)).All(context.Background(), exec)
allParts, err := models.AutomodRuleData(qm.Where("guild_id = ? AND rule_id != ?", rule.GuildID, rule.ID)).All(context.Background(), exec)
if err != nil {
return
}
Expand Down
2 changes: 0 additions & 2 deletions automod/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package automod
import (
"github.com/jonas747/yagpdb/bot"
"github.com/jonas747/yagpdb/common"
"github.com/sirupsen/logrus"
"time"
)

Expand Down Expand Up @@ -336,7 +335,6 @@ func (ac *AccountAgeCondition) IsMet(data *TriggeredRuleData, settings interface

created := bot.SnowflakeToTime(data.MS.ID)
minutes := int(time.Since(created).Minutes())
logrus.Println(minutes)
if minutes <= settingsCast.Treshold {
// account were made within threshold
if ac.Below {
Expand Down
2 changes: 1 addition & 1 deletion automod/models/automod_rule_data.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion automod/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ func (r *UsernameRegexTrigger) Name() string {
return "Join username not matching regex"
}

return "Joins username matches regex"
return "Join username matches regex"
}

func (r *UsernameRegexTrigger) Description() string {
Expand Down
2 changes: 1 addition & 1 deletion automod_legacy/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func CheckMessage(m *discordgo.Message) bool {
return false // Pls no panicerinos or banerinos self
}

if m.Author.Bot {
if m.Author.Bot || m.GuildID == 0 {
return false
}

Expand Down
3 changes: 3 additions & 0 deletions autorole/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ OUTER:

cntSinceLastRedisUpdate := 0
for i, userID := range membersToGiveRole {
time.Sleep(time.Second)
select {
case <-stopChan:
logrus.WithField("guild", gs.ID).Info("Stopping autorole assigning...")
Expand Down Expand Up @@ -399,6 +400,8 @@ OUTER:
}
}

time.Sleep(time.Second)

logrus.Println("assigning to ", m.User.ID, " from guild chunk event")
err = common.AddRole(m, config.Role, chunk.GuildID)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions aylien/aylien.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (p *Plugin) AddCommands() {
Cooldown: 5,
Name: "sentiment",
Aliases: []string{"sent"},
Description: "Does sentiment analysys on a message or your last 5 messages longer than 3 words",
Description: "Does sentiment analysis on a message or your last 5 messages longer than 3 words",
Arguments: []*dcmd.ArgDef{
&dcmd.ArgDef{Name: "text", Type: dcmd.String},
},
Expand Down Expand Up @@ -112,7 +112,7 @@ func (p *Plugin) AddCommands() {
}
}

out := fmt.Sprintf("**Sentiment analysys on %d messages:**\n", len(responses))
out := fmt.Sprintf("**Sentiment analysis on %d messages:**\n", len(responses))
for _, resp := range responses {
out += fmt.Sprintf("*%s*\nPolarity: **%s** *(Confidence: %.2f%%)* Subjectivity: **%s** *(Confidence: %.2f%%)*\n\n", resp.Text, resp.Polarity, resp.PolarityConfidence*100, resp.Subjectivity, resp.SubjectivityConfidence*100)
}
Expand Down
4 changes: 4 additions & 0 deletions bot/admin_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ var (
)

func IsBotAdmin(userID int64) (isAdmin bool, err error) {
if userID == common.Conf.Owner {
return true, nil
}

err = common.RedisPool.Do(radix.FlatCmd(&isAdmin, "SISMEMBER", RedisKeyAdmins, userID))
return
}
Expand Down
1 change: 1 addition & 0 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func setup() {
State.MaxMessageAge = time.Hour
// State.Debug = true
State.ThrowAwayDMMessages = true
State.TrackPrivateChannels = false
State.CacheExpirey = time.Minute * 10
go State.RunGCWorker()

Expand Down
4 changes: 3 additions & 1 deletion bot/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ func GetMessages(channelID int64, limit int, deleted bool) ([]*WrappedMessage, e
msgBuf := make([]*WrappedMessage, limit)

cs := State.Channel(true, channelID)

if cs == nil {
return []*WrappedMessage{}, nil
}
cs.Owner.RLock()

n := len(msgBuf) - 1
Expand Down
6 changes: 3 additions & 3 deletions cah/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (p *Plugin) AddCommands() {
&dcmd.ArgDef{Name: "packs", Type: dcmd.String, Default: "main", Help: "Packs seperated by space, or * for all of them"},
},
ArgSwitches: []*dcmd.ArgDef{
{Switch: "v", Name: "Vote mode, players vote instead of having a cardczar"},
{Switch: "v", Name: "Vote mode - players vote instead of having a cardczar"},
},
RunFunc: func(data *dcmd.Data) (interface{}, error) {
voteMode := data.Switch("v").Bool()
Expand All @@ -43,7 +43,7 @@ func (p *Plugin) AddCommands() {
cmdEnd := &commands.YAGCommand{
Name: "end",
CmdCategory: commands.CategoryFun,
Description: "Ends a cards against humanity game thats ongoing in this channel",
Description: "Ends a cards against humanity game thats ongoing in this channel.",
RunFunc: func(data *dcmd.Data) (interface{}, error) {
isAdmin, err := bot.AdminOrPerm(0, data.Msg.Author.ID, data.CS.ID)
if err == nil && isAdmin {
Expand Down Expand Up @@ -71,7 +71,7 @@ func (p *Plugin) AddCommands() {
Arguments: []*dcmd.ArgDef{
&dcmd.ArgDef{Name: "user", Type: dcmd.UserID},
},
Description: "Kicks a player from the ongoing cards against humanity game in this channel",
Description: "Kicks a player from the ongoing cards against humanity game in this channel.",
RunFunc: func(data *dcmd.Data) (interface{}, error) {
userID := data.Args[0].Int64()
err := p.Manager.AdminKickUser(data.Msg.Author.ID, userID)
Expand Down
80 changes: 80 additions & 0 deletions cmd/yagpdb/gen-commands-docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package main

import (
"bytes"
"github.com/jonas747/dcmd"
"github.com/jonas747/yagpdb/commands"
"os"
"strings"
)

func GenCommandsDocs() {
// func GenerateHelp(d *Data, container *Container, formatter HelpFormatter) (embeds []*discordgo.MessageEmbed) {

sets := dcmd.SortCommands(commands.CommandSystem.Root, commands.CommandSystem.Root)

var out bytes.Buffer
out.WriteString("## Legend\n\n")
out.WriteString("`<required arg>` `[optional arg]`\n\n")
out.WriteString("Text arguments containing multiple words needs be to put in quotes (\"arg here\") or code ticks (`arg here`) if it's not the last argument and there's more than 1 text argument.\n\n")
out.WriteString("For example with the poll command if you want the question to have multiple words: `-poll \"whats your favorite color\" red blue green2`\n\n")

stdHelpFmt := &dcmd.StdHelpFormatter{}
mockCmdData := &dcmd.Data{}

for _, set := range sets {

out.WriteString("## " + set.Name() + " " + set.Emoji() + "\n\n")

for _, entry := range set.Commands {
// get the main name
nameStr := entry.Container.FullName(false)
if nameStr != "" {
nameStr += " "
}
nameStr += entry.Cmd.Trigger.Names[0]

// then aliases
aliases := strings.Join(entry.Cmd.Trigger.Names[1:], "/")

// arguments and switches
args := stdHelpFmt.ArgDefs(entry.Cmd, mockCmdData)
switches := stdHelpFmt.Switches(entry.Cmd.Command)

// grab the description
desc := ""
if cast, ok := entry.Cmd.Command.(dcmd.CmdWithDescriptions); ok {
short, long := cast.Descriptions(mockCmdData)
if long != "" {
desc = long
} else if short != "" {
desc = short
} else {
desc = "No description for this command"
}
}

out.WriteString("### " + nameStr + "\n\n")
if aliases != "" {
out.WriteString("**Aliases:** " + aliases + "\n\n")
}

out.WriteString(desc)
out.WriteString("\n\n")

out.WriteString("**Usage:**\n")
out.WriteString("```\n" + args + "\n```\n")

if switches != "" {
out.WriteString("```\n" + switches + "\n```\n")
}

out.WriteString("\n")
}

}

os.Stdout.Write(out.Bytes())

return
}
9 changes: 8 additions & 1 deletion cmd/yagpdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ var (

flagLogTimestamp bool

flagSysLog bool
flagSysLog bool
flagGenCmdDocs bool
)

func init() {
Expand All @@ -69,6 +70,7 @@ func init() {
flag.BoolVar(&flagDryRun, "dry", false, "Do a dryrun, initialize all plugins but don't actually start anything")
flag.BoolVar(&flagSysLog, "syslog", false, "Set to log to syslog (only linux)")
flag.BoolVar(&flagRunBWC, "backgroundworkers", false, "Run the various background workers, atleast one process needs this")
flag.BoolVar(&flagGenCmdDocs, "gencmddocs", false, "Generate command docs and exit")

flag.BoolVar(&flagLogTimestamp, "ts", false, "Set to include timestamps in log")
}
Expand Down Expand Up @@ -162,6 +164,11 @@ func main() {

commands.InitCommands()

if flagGenCmdDocs {
GenCommandsDocs()
return
}

if flagRunWeb || flagRunEverything {
go web.Run()
}
Expand Down
15 changes: 12 additions & 3 deletions cmd/yagpdb/static/js/spongebob.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,20 @@ function formSubmissionEvents(){


if(target.hasClass("btn-danger") || target.attr("data-open-confirm") || target.hasClass("delete-button")){
if(!confirm("Are you sure you want to do this?")){
var title = target.attr("title");
if(title !== undefined){
if(!confirm("Deleting " + title + ". Are you sure you want to do this?" )){
event.preventDefault(true);
event.stopPropagation();
return;
}
}
}else{
if(!confirm("Are you sure you want to do this?" )){
event.preventDefault(true);
event.stopPropagation();
return;
}
}
}

// Find the parent form using the parents or the form attribute
Expand Down Expand Up @@ -653,4 +662,4 @@ function toggleTheme(){
elem.classList.remove("sidebar-light")
document.cookie = "light_theme=false; max-age=3153600000; path=/"
}
}
}
2 changes: 1 addition & 1 deletion cmd/yagpdb/static/vendor/codemirror/mode/python/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ <h2>Configuration Options for Python mode:</h2>
<li>hangingIndent - int - If you want to write long arguments to a function starting on a new line, how much that line should be indented. Defaults to one normal indentation unit.</li>
</ul>
<h2>Advanced Configuration Options:</h2>
<p>Usefull for superset of python syntax like Enthought enaml, IPython magics and questionmark help</p>
<p>Useful for superset of python syntax like Enthought enaml, IPython magics and questionmark help</p>
<ul>
<li>singleOperators - RegEx - Regular Expression for single operator matching, default : <pre>^[\\+\\-\\*/%&amp;|\\^~&lt;&gt;!]</pre> including <pre>@</pre> on Python 3</li>
<li>singleDelimiters - RegEx - Regular Expression for single delimiter matching, default : <pre>^[\\(\\)\\[\\]\\{\\}@,:`=;\\.]</pre></li>
Expand Down
3 changes: 2 additions & 1 deletion cmd/yagpdb/templates/cp_nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@

{{$clientid := .ClientID}}
{{$host := .Host}}
{{$baseURL := .BaseURL}}

{{range $index, $element := .ManagedGuilds -}}{{if $element.Connected -}}
<li>
Expand All @@ -86,7 +87,7 @@

{{range $index, $element := .ManagedGuilds -}}{{if not $element.Connected -}}
<li>
<a href="https://discordapp.com/oauth2/authorize?client_id={{$clientid}}&scope=bot&permissions=535948311&guild_id={{$element.ID}}&response_type=code&redirect_uri={{urlquery (joinStr "" "https://" $host "/manage")}}"><i class="fas fa-plus"></i>{{$element.Name}}</a>
<a href="https://discordapp.com/oauth2/authorize?client_id={{$clientid}}&scope=bot&permissions=535948311&guild_id={{$element.ID}}&response_type=code&redirect_uri={{joinStr "" $baseURL "/manage"}}"><i class="fas fa-plus"></i>{{$element.Name}}</a>
</li>
{{end}}{{end}}

Expand Down
Loading

0 comments on commit 7eb684a

Please sign in to comment.