Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New/Better Slash Commands #162

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions eod/base/take.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package base

import (
"fmt"

"github.com/Nv7-Github/sevcord/v2"
"github.com/bwmarrin/discordgo"
"github.com/lib/pq"
)

func (b *Base) Take(c sevcord.Ctx, opts []any) {
c.Acknowledge()

user := opts[0].(*discordgo.User).ID
q, ok := b.CalcQuery(c, opts[1].(string))
if !ok {
return
}

// remove from inv
_, err := b.db.Exec(`UPDATE inventories SET inv=inv-$1 WHERE guild=$2 AND "user"=$3`, pq.Array(q.Elements), c.Guild(), user)
if err != nil {
b.Error(c, err)
return
}

// Respond
c.Respond(sevcord.NewMessage(fmt.Sprintf("Succesfully removed elements from <@%s>!", user)))
}
func (b *Base) Set(c sevcord.Ctx, opts []any) {
c.Acknowledge()

user := opts[0].(*discordgo.User).ID
q, ok := b.CalcQuery(c, opts[1].(string))
if !ok {
return
}

// set to inv
_, err := b.db.Exec(`UPDATE inventories SET inv=$1 WHERE guild=$2 AND "user"=$3`, pq.Array(q.Elements), c.Guild(), user)
if err != nil {
b.Error(c, err)
return
}

// Respond
c.Respond(sevcord.NewMessage(fmt.Sprintf("Succesfully set elements to <@%s>!", user)))
}
9 changes: 9 additions & 0 deletions eod/categories/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ func (c *Categories) CatEditCmd(ctx sevcord.Ctx, cat string, elems []int, kind t
// Respond
ctx.Respond(sevcord.NewMessage(fmt.Sprintf(format, text, name)))
}
func (c *Categories) AddCatQuery(ctx sevcord.Ctx, opts []any) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I implemented this before and people made categories with every element, which takes like hundreds of megabytes of space in the DB, which is why I deleted it. Encourage people to use queries instead of adding stuff from queries to categories

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering how big even is the DB anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about if it was a mod only thing or had some sort of limits?


q, success := c.base.CalcQuery(ctx, opts[1].(string))
if !success {
return
}
c.CatEditCmd(ctx, opts[0].(string), q.Elements, types.PollKindCategorize, "Suggested to add **%s** to **%s** 🗃️", false)

}

func (c *Categories) AddCat(ctx sevcord.Ctx, opts []any) {
c.CatEditCmd(ctx, opts[0].(string), []int{int(opts[1].(int64))}, types.PollKindCategorize, "Suggested to add **%s** to **%s** 🗃️", false)
Expand Down
43 changes: 34 additions & 9 deletions eod/categories/infoedit.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@ func (c *Categories) ImageCmd(ctx sevcord.Ctx, cat string, image string) {
return
}

//Distinguish between adding new image and changing existing image
var addtext string
if old != "" {
addtext = "to change the"
} else {
addtext = "a new"
}
// Respond
ctx.Respond(sevcord.NewMessage(fmt.Sprintf("Suggested an image for category **%s** 📷", name)))
ctx.Respond(sevcord.NewMessage(fmt.Sprintf("Suggested %s image for category **%s** 📷", addtext, name)))
}

func (c *Categories) MsgSignCmd(ctx sevcord.Ctx, cat string, mark string) {
Expand Down Expand Up @@ -69,9 +76,15 @@ func (c *Categories) MsgSignCmd(ctx sevcord.Ctx, cat string, mark string) {
ctx.Respond(res.Response())
return
}

//Distinguish between new and old
var addtext string
if old != types.DefaultMark {
addtext = "to change the"
} else {
addtext = "a new"
}
// Respond
ctx.Respond(sevcord.NewMessage(fmt.Sprintf("Suggested a note for **%s** 🖋️", name)))
ctx.Respond(sevcord.NewMessage(fmt.Sprintf("Suggested %s note for **%s** 🖋️", addtext, name)))
}

func (c *Categories) SignCmd(ctx sevcord.Ctx, opts []any) {
Expand Down Expand Up @@ -99,10 +112,16 @@ func (c *Categories) SignCmd(ctx sevcord.Ctx, opts []any) {
ctx.Respond(res.Response())
return
}
var addtext string
if old != types.DefaultMark {
addtext = "to change the"
} else {
addtext = "a new"
}

// Respond
ctx.Respond(sevcord.NewMessage(fmt.Sprintf("Suggested a note for category **%s** 🖋️", name)))
}).Input(sevcord.NewModalInput("New Comment", "None", sevcord.ModalInputStyleParagraph, 2400)))
ctx.Respond(sevcord.NewMessage(fmt.Sprintf("Suggested %s note for category **%s** 🖋️", addtext, name)))
}).Input(sevcord.NewModalInput("New Comment", types.DefaultMark, sevcord.ModalInputStyleParagraph, 2400)))
}

func (c *Categories) ColorCmd(ctx sevcord.Ctx, opts []any) {
Expand All @@ -120,10 +139,11 @@ func (c *Categories) ColorCmd(ctx sevcord.Ctx, opts []any) {
return
}

// Check element
// Check category
var name string
var old int
err = c.db.QueryRow("SELECT name, color FROM categories WHERE LOWER(name)=$1 AND guild=$2", strings.ToLower(opts[0].(string)), ctx.Guild()).Scan(&name, &old)
var colorer string
err = c.db.QueryRow("SELECT name, color,colorer FROM categories WHERE LOWER(name)=$1 AND guild=$2", strings.ToLower(opts[0].(string)), ctx.Guild()).Scan(&name, &old)
if err != nil {
c.base.Error(ctx, err, "Category **"+opts[0].(string)+"** doesn't exist!")
return
Expand All @@ -142,7 +162,12 @@ func (c *Categories) ColorCmd(ctx sevcord.Ctx, opts []any) {
ctx.Respond(res.Response())
return
}

var addtext string
if colorer != "" {
addtext = "to change the"
} else {
addtext = "a new"
}
// Respond
ctx.Respond(sevcord.NewMessage(fmt.Sprintf("Suggested a color for category **%s** 🎨", name)))
ctx.Respond(sevcord.NewMessage(fmt.Sprintf("Suggested %s color for category **%s** 🎨", addtext, name)))
}
14 changes: 14 additions & 0 deletions eod/elements/autocomplete.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,17 @@ func (e *Elements) Autocomplete(c sevcord.Ctx, val any) []sevcord.Choice {
}
return choices
}

func (e *Elements) AutocompleteName(ctx sevcord.Ctx, val any) []sevcord.Choice {
var res []types.Element
err := e.db.Select(&res, "SELECT name FROM elements WHERE guild=$1 AND name ILIKE $2 || '%' ORDER BY similarity(name, $2) DESC, name LIMIT 25", ctx.Guild(), val.(string))
if err != nil {
log.Println("autocomplete error", err)
return nil
}
choices := make([]sevcord.Choice, len(res))
for i, v := range res {
choices[i] = sevcord.NewChoice(v.Name, v.Name)
}
return choices
}
45 changes: 35 additions & 10 deletions eod/elements/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ func (e *Elements) ImageCmd(c sevcord.Ctx, id int, image string) {
c.Respond(res.Response())
return
}

// Distinguish between adding new image and changing existing image
var addtext string
if old != "" {
addtext = "to change the"
} else {
addtext = "a new"
}
// Respond
c.Respond(sevcord.NewMessage(fmt.Sprintf("Suggested an image for **%s** 📷", elem)))
c.Respond(sevcord.NewMessage(fmt.Sprintf("Suggested %s image for **%s** 📷", addtext, elem)))
}

func (e *Elements) SignCmd(c sevcord.Ctx, opts []any) {
Expand Down Expand Up @@ -65,10 +71,16 @@ func (e *Elements) SignCmd(c sevcord.Ctx, opts []any) {
c.Respond(res.Response())
return
}

//distinguish between new and changing
var addtext string
if old != types.DefaultMark {
addtext = "to change the"
} else {
addtext = "a new"
}
// Respond
c.Respond(sevcord.NewMessage(fmt.Sprintf("Suggested a note for **%s** 🖋️", name)))
}).Input(sevcord.NewModalInput("New Comment", "None", sevcord.ModalInputStyleParagraph, 2400)))
c.Respond(sevcord.NewMessage(fmt.Sprintf("Suggested %s note for **%s** 🖋️", addtext, name)))
}).Input(sevcord.NewModalInput("New Comment", types.DefaultMark, sevcord.ModalInputStyleParagraph, 2400)))
}

func (e *Elements) MsgSignCmd(c sevcord.Ctx, elem string, mark string) {
Expand Down Expand Up @@ -101,9 +113,15 @@ func (e *Elements) MsgSignCmd(c sevcord.Ctx, elem string, mark string) {
c.Respond(res.Response())
return
}

// distinguish between new and changing
var addtext string
if old != types.DefaultMark {
addtext = "to change the"
} else {
addtext = "a new"
}
// Respond
c.Respond(sevcord.NewMessage(fmt.Sprintf("Suggested a note for **%s** 🖋️", name)))
c.Respond(sevcord.NewMessage(fmt.Sprintf("Suggested %s note for **%s** 🖋️", addtext, name)))
}

func (e *Elements) ColorCmd(c sevcord.Ctx, opts []any) {
Expand All @@ -124,7 +142,8 @@ func (e *Elements) ColorCmd(c sevcord.Ctx, opts []any) {
// Check element
var name string
var old int
err = e.db.QueryRow("SELECT name, color FROM elements WHERE id=$1 AND guild=$2", opts[0].(int64), c.Guild()).Scan(&name, &old)
var colorer string
err = e.db.QueryRow("SELECT name, color,colorer FROM elements WHERE id=$1 AND guild=$2", opts[0].(int64), c.Guild()).Scan(&name, &old, &colorer)
if err != nil {
e.base.Error(c, err)
return
Expand All @@ -143,7 +162,13 @@ func (e *Elements) ColorCmd(c sevcord.Ctx, opts []any) {
c.Respond(res.Response())
return
}

// distinguish between new and changing
var addtext string
if colorer != "" {
addtext = "to change the"
} else {
addtext = "a new"
}
// Respond
c.Respond(sevcord.NewMessage(fmt.Sprintf("Suggested a color for **%s** 🎨", name)))
c.Respond(sevcord.NewMessage(fmt.Sprintf("Suggested %s color for **%s** 🎨", addtext, name)))
}
2 changes: 1 addition & 1 deletion eod/elements/editcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (e *Elements) editCmd(c sevcord.Ctx, opts []any, field string, name ...stri
return
}
c.Respond(sevcord.NewMessage("Successfully edited element " + nameV + "! ✅"))
e.editNewsMessage(c, fmt.Sprintf("Edited Element %s - **%s** (By <@%s>)", util.Capitalize(nameV), nameE, c.Author().User.ID))
e.editNewsMessage(c, fmt.Sprintf("Edited Element %s - **%s** (By <@%s>) - Element **#%d** ", util.Capitalize(nameV), nameE, c.Author().User.ID, opts[0].(int64)))
}

func (e *Elements) EditElementNameCmd(c sevcord.Ctx, opts []any) {
Expand Down
16 changes: 16 additions & 0 deletions eod/elements/hint.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,19 @@ func (e *Elements) Hint(c sevcord.Ctx, opts []any) {
}
e.HintHandler(c, fmt.Sprintf("%s|%d|%s", c.Author().User.ID, el, query))
}
func (e *Elements) HintName(c sevcord.Ctx, opts []any) {
c.Acknowledge()
el := -1
if opts[0] != nil {
err := e.db.QueryRow("SELECT id FROM elements WHERE LOWER(name)=$1 AND guild=$2", strings.ToLower(strings.TrimSpace(opts[0].(string))), c.Guild()).Scan(&el)
if err != nil {
e.base.Error(c, err, "Element **"+opts[0].(string)+"** doesn't exist!")
}

}
query := ""
if opts[1] != nil {
query = opts[1].(string)
}
e.HintHandler(c, fmt.Sprintf("%s|%d|%s", c.Author().User.ID, el, query))
}
Loading