Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
24aff1be72 | ||
|
|
b28beaba0c | ||
|
|
4f8aaff94a | ||
|
|
a21e884bee | ||
|
|
faf64a8bf9 | ||
|
|
2abe574977 | ||
|
|
04c32955c7 | ||
|
|
1f70318d26 | ||
|
|
47ed519376 | ||
|
|
22912c7367 | ||
|
|
6b15540d4e | ||
|
|
e526d27f4a | ||
|
|
68c06a7356 | ||
|
|
c8277cce42 | ||
|
|
3069e24e8d | ||
|
|
472f23cc2b | ||
|
|
6d920e615d |
@@ -26,8 +26,8 @@ jobs:
|
||||
GOPATH: /home/runner/work/Geeksbot/
|
||||
run: |
|
||||
go get -u github.com/go-bindata/go-bindata/...
|
||||
/home/runner/work/Geeksbot/bin/go-bindata -pkg migrations -prefix $GITHUB_WORKSPACE/internal/database/migrations/ -o $GITHUB_WORKSPACE/internal/database/migrations/bindata.go $GITHUB_WORKSPACE/internal/database/migrations/
|
||||
head $GITHUB_WORKSPACE/internal/database/migrations/bindata.go
|
||||
/home/runner/work/Geeksbot/bin/go-bindata -pkg migrations -prefix $GITHUB_WORKSPACE/pkg/database/migrations/ -o $GITHUB_WORKSPACE/pkg/database/migrations/bindata.go $GITHUB_WORKSPACE/pkg/database/migrations/
|
||||
head $GITHUB_WORKSPACE/pkg/database/migrations/bindata.go
|
||||
|
||||
- name: Build container image
|
||||
env:
|
||||
@@ -43,7 +43,9 @@ jobs:
|
||||
run: doctl registry login --expiry-seconds 600
|
||||
|
||||
- name: Push image to DigitalOcean Container Registry
|
||||
run: docker push registry.digitalocean.com/djpianalto/geeksbot
|
||||
run: docker push registry.digitalocean.com/djpianalto/geeksbot:$IMAGE_TAG
|
||||
env:
|
||||
IMAGE_TAG: ${{ steps.get_version.outputs.version-without-v }}
|
||||
|
||||
- name: Update deployment file
|
||||
run: TAG=${{ steps.get_version.outputs.version-without-v }} && sed -i 's|<IMAGE>|registry.digitalocean.com/djpianalto/geeksbot:'${TAG}'|' $GITHUB_WORKSPACE/deployment.yml
|
||||
|
||||
@@ -8,9 +8,9 @@ import (
|
||||
|
||||
"github.com/bwmarrin/discordgo"
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"github.com/dustinpianalto/geeksbot/internal/database"
|
||||
"github.com/dustinpianalto/geeksbot/internal/exts"
|
||||
"github.com/dustinpianalto/geeksbot/internal/services"
|
||||
"github.com/dustinpianalto/geeksbot/pkg/database"
|
||||
"github.com/dustinpianalto/geeksbot/pkg/services"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package discord_utils
|
||||
|
||||
import (
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"github.com/dustinpianalto/geeksbot"
|
||||
"github.com/dustinpianalto/geeksbot/pkg/services"
|
||||
)
|
||||
|
||||
func IsGuildMod(ctx disgoman.Context, user geeksbot.User) bool {
|
||||
discordCloser, err := ctx.Session.GuildMember(ctx.Guild.ID, user.ID)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
guildRoles, err := services.GuildService.GuildRoles(geeksbot.Guild{ID: ctx.Guild.ID})
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
for _, role := range guildRoles {
|
||||
if role.RoleType == "moderator" {
|
||||
for _, rID := range discordCloser.Roles {
|
||||
if rID == role.ID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func IsGuildAdmin(ctx disgoman.Context, user geeksbot.User) bool {
|
||||
discordCloser, err := ctx.Session.GuildMember(ctx.Guild.ID, user.ID)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
guildRoles, err := services.GuildService.GuildRoles(geeksbot.Guild{ID: ctx.Guild.ID})
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
for _, role := range guildRoles {
|
||||
if role.RoleType == "admin" {
|
||||
for _, rID := range discordCloser.Roles {
|
||||
if rID == role.ID {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"github.com/dustinpianalto/geeksbot"
|
||||
"github.com/dustinpianalto/geeksbot/internal/discord_utils"
|
||||
"github.com/dustinpianalto/geeksbot/internal/services"
|
||||
"github.com/dustinpianalto/geeksbot/internal/utils"
|
||||
"github.com/dustinpianalto/geeksbot/pkg/services"
|
||||
)
|
||||
|
||||
var AddPrefixCommand = &disgoman.Command{
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"github.com/dustinpianalto/geeksbot"
|
||||
"github.com/dustinpianalto/geeksbot/internal/discord_utils"
|
||||
"github.com/dustinpianalto/geeksbot/internal/services"
|
||||
"github.com/dustinpianalto/geeksbot/internal/utils"
|
||||
"github.com/dustinpianalto/geeksbot/pkg/services"
|
||||
)
|
||||
|
||||
var AddModeratorRoleCommand = &disgoman.Command{
|
||||
@@ -278,7 +278,7 @@ func removeSelfAssignableRoleCommandFunc(ctx disgoman.Context, args []string) {
|
||||
|
||||
var SelfAssignRoleCommand = &disgoman.Command{
|
||||
Name: "giverole",
|
||||
Aliases: []string{"iwant", "givetome"},
|
||||
Aliases: []string{"iwant", "givetome", "addrole"},
|
||||
Description: "Assigns a person the passed in role if it is self assignable",
|
||||
OwnerOnly: false,
|
||||
Hidden: false,
|
||||
@@ -298,7 +298,7 @@ func selfAssignRoleCommandFunc(ctx disgoman.Context, args []string) {
|
||||
roleID = id
|
||||
} else {
|
||||
for _, role := range ctx.Guild.Roles {
|
||||
if id == role.Name {
|
||||
if strings.ToLower(id) == strings.ToLower(role.Name) {
|
||||
roleID = role.ID
|
||||
}
|
||||
}
|
||||
@@ -357,7 +357,7 @@ func unAssignRoleCommandFunc(ctx disgoman.Context, args []string) {
|
||||
roleID = id
|
||||
} else {
|
||||
for _, role := range ctx.Guild.Roles {
|
||||
if id == role.Name {
|
||||
if strings.ToLower(id) == strings.ToLower(role.Name) {
|
||||
roleID = role.ID
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,4 +32,6 @@ func AddCommandHandlers(g *disgoman.CommandManager) {
|
||||
_ = g.AddCommand(guild.SelfAssignRoleCommand)
|
||||
_ = g.AddCommand(guild.UnAssignRoleCommand)
|
||||
_ = g.AddCommand(requests.RequestCommand)
|
||||
_ = g.AddCommand(requests.CloseCommand)
|
||||
_ = g.AddCommand(requests.ListCommand)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ import (
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"github.com/dustinpianalto/geeksbot"
|
||||
"github.com/dustinpianalto/geeksbot/internal/discord_utils"
|
||||
"github.com/dustinpianalto/geeksbot/internal/services"
|
||||
"github.com/dustinpianalto/geeksbot/internal/utils"
|
||||
"github.com/dustinpianalto/geeksbot/pkg/services"
|
||||
)
|
||||
|
||||
var RequestCommand = &disgoman.Command{
|
||||
@@ -101,3 +102,152 @@ func requestCommandFunc(ctx disgoman.Context, args []string) {
|
||||
discord_utils.SendErrorMessage(ctx, "There was an error sending the message. The request was created.", err)
|
||||
}
|
||||
}
|
||||
|
||||
var CloseCommand = &disgoman.Command{
|
||||
Name: "close",
|
||||
Aliases: nil,
|
||||
Description: "Close a request and mark it as completed.",
|
||||
OwnerOnly: false,
|
||||
Hidden: false,
|
||||
RequiredPermissions: 0,
|
||||
Invoke: closeCommandFunc,
|
||||
}
|
||||
|
||||
func closeCommandFunc(ctx disgoman.Context, args []string) {
|
||||
var ids []int64
|
||||
var reason string
|
||||
_, err := strconv.ParseInt(args[len(args)-1], 10, 64)
|
||||
if err != nil {
|
||||
reason = args[len(args)-1]
|
||||
args = args[0 : len(args)-1]
|
||||
}
|
||||
for _, a := range args {
|
||||
a = strings.Trim(a, ",")
|
||||
id, err := strconv.ParseInt(a, 10, 64)
|
||||
if err != nil {
|
||||
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("%s is not a valid request id", a), err)
|
||||
continue
|
||||
}
|
||||
ids = append(ids, id)
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
discord_utils.SendErrorMessage(ctx, "No requests to close", nil)
|
||||
return
|
||||
}
|
||||
guild, err := services.GuildService.GetOrCreateGuild(ctx.Guild.ID)
|
||||
if err != nil {
|
||||
discord_utils.SendErrorMessage(ctx, "Error getting Guild from the database", err)
|
||||
return
|
||||
}
|
||||
closer, err := services.UserService.GetOrCreateUser(ctx.Message.Author.ID)
|
||||
if err != nil {
|
||||
discord_utils.SendErrorMessage(ctx, "Error closing the request. Could not get user.", err)
|
||||
return
|
||||
}
|
||||
int64ID, _ := strconv.ParseInt(ctx.Message.ID, 10, 64)
|
||||
s := discord_utils.ParseSnowflake(int64ID)
|
||||
for _, id := range ids {
|
||||
request, err := services.RequestService.Request(id)
|
||||
if err != nil || request.Guild.ID != guild.ID {
|
||||
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("%d is not a request in this guild.", id), err)
|
||||
continue
|
||||
}
|
||||
if request.Author != closer && !closer.IsStaff && !closer.IsAdmin {
|
||||
if !discord_utils.IsGuildMod(ctx, closer) || !discord_utils.IsGuildAdmin(ctx, closer) {
|
||||
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("You are not authorized to close %d", id), nil)
|
||||
continue
|
||||
}
|
||||
}
|
||||
if request.Completed {
|
||||
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("%d is already closed", id), err)
|
||||
continue
|
||||
}
|
||||
request.Completed = true
|
||||
request.CompletedAt.Valid = true
|
||||
request.CompletedAt.Time = s.CreationTime
|
||||
request.CompletedBy = &closer
|
||||
if reason != "" {
|
||||
request.CompletedMessage.Valid = true
|
||||
request.CompletedMessage.String = reason
|
||||
}
|
||||
request, err = services.RequestService.UpdateRequest(request)
|
||||
if err != nil {
|
||||
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("Error closing %d", id), err)
|
||||
continue
|
||||
}
|
||||
_, err = ctx.Send(fmt.Sprintf("%d has been closed", request.ID))
|
||||
if err != nil {
|
||||
discord_utils.SendErrorMessage(ctx, "There was an error sending the message. The request was closed.", err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var ListCommand = &disgoman.Command{
|
||||
Name: "list",
|
||||
Aliases: []string{"request_list", "requests_list"},
|
||||
Description: "List your open requests or all open requests if the caller is a moderator",
|
||||
OwnerOnly: false,
|
||||
Hidden: false,
|
||||
RequiredPermissions: 0,
|
||||
Invoke: listCommandFunc,
|
||||
}
|
||||
|
||||
func listCommandFunc(ctx disgoman.Context, args []string) {
|
||||
user, err := services.UserService.GetOrCreateUser(ctx.Message.Author.ID)
|
||||
if err != nil {
|
||||
discord_utils.SendErrorMessage(ctx, "Error closing the request. Could not get user.", err)
|
||||
return
|
||||
}
|
||||
guild, err := services.GuildService.GetOrCreateGuild(ctx.Guild.ID)
|
||||
if err != nil {
|
||||
discord_utils.SendErrorMessage(ctx, "Error getting Guild from the database", err)
|
||||
return
|
||||
}
|
||||
|
||||
var requests []geeksbot.Request
|
||||
if discord_utils.IsGuildMod(ctx, user) || discord_utils.IsGuildAdmin(ctx, user) {
|
||||
requests, err = services.RequestService.GuildRequests(guild, false)
|
||||
} else {
|
||||
requests, err = services.RequestService.UserRequests(user, false)
|
||||
}
|
||||
|
||||
for _, request := range requests {
|
||||
var authorName string
|
||||
author, err := ctx.Session.GuildMember(guild.ID, request.Author.ID)
|
||||
if err != nil {
|
||||
authorName = "Unknown"
|
||||
} else {
|
||||
if author.Nick == "" {
|
||||
authorName = author.User.Username
|
||||
} else {
|
||||
authorName = author.Nick
|
||||
}
|
||||
}
|
||||
|
||||
var channelName string
|
||||
channel, err := ctx.Session.Channel(request.Channel.ID)
|
||||
if err != nil {
|
||||
channelName = "Unknown"
|
||||
} else {
|
||||
channelName = channel.Name
|
||||
}
|
||||
|
||||
_, _ = ctx.Send(fmt.Sprintf("```md\n"+
|
||||
"< Request ID Requested By >\n"+
|
||||
"< %-11d %23s >\n"+
|
||||
"%s\n\n"+
|
||||
"Comments: Not Implemented Yet\n"+
|
||||
"Requested At: %s\n"+
|
||||
"In: %s\n"+
|
||||
"```",
|
||||
request.ID,
|
||||
authorName,
|
||||
request.Content,
|
||||
request.RequestedAt.Format("2006-01-02 15:04:05 MST"),
|
||||
channelName,
|
||||
))
|
||||
}
|
||||
|
||||
_, _ = ctx.Send(fmt.Sprintf("```There %s currently %d open %s```", utils.PluralizeString("is", len(requests)), len(requests), utils.PluralizeString("request", len(requests))))
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"github.com/dustinpianalto/geeksbot"
|
||||
"github.com/dustinpianalto/geeksbot/internal/discord_utils"
|
||||
"github.com/dustinpianalto/geeksbot/internal/services"
|
||||
"github.com/dustinpianalto/geeksbot/pkg/services"
|
||||
)
|
||||
|
||||
var PingCommand = &disgoman.Command{
|
||||
|
||||
@@ -17,5 +17,8 @@ func PluralizeString(s string, i int) string {
|
||||
if i == 1 {
|
||||
return s
|
||||
}
|
||||
if s == "is" {
|
||||
return "are"
|
||||
}
|
||||
return s + "s"
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/dustinpianalto/geeksbot/internal/database/migrations"
|
||||
"github.com/dustinpianalto/geeksbot/pkg/database/migrations"
|
||||
"github.com/golang-migrate/migrate/v4"
|
||||
"github.com/golang-migrate/migrate/v4/database/postgres"
|
||||
bindata "github.com/golang-migrate/migrate/v4/source/go_bindata"
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/dustinpianalto/geeksbot"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
type messageService struct {
|
||||
@@ -21,7 +22,7 @@ func (s messageService) Message(id string) (geeksbot.Message, error) {
|
||||
WHERE m.id = $1`
|
||||
row := s.db.QueryRow(queryString, id)
|
||||
err := row.Scan(&m.ID, &m.CreatedAt, &m.ModifiedAt, &m.Content,
|
||||
&m.PreviousContent, &channel_id, &author_id)
|
||||
pq.Array(&m.PreviousContent), &channel_id, &author_id)
|
||||
if err != nil {
|
||||
return geeksbot.Message{}, err
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
BEGIN;
|
||||
ALTER TABLE messages
|
||||
ALTER COLUMN previous_content DROP NOT NULL;
|
||||
ALTER TABLE messages
|
||||
ALTER COLUMN previous_content DROP DEFAULT;
|
||||
COMMIT;
|
||||
@@ -0,0 +1,6 @@
|
||||
BEGIN;
|
||||
ALTER TABLE messages
|
||||
ALTER COLUMN previous_content SET NOT NULL;
|
||||
ALTER TABLE messages
|
||||
ALTER COLUMN previous_content SET DEFAULT array[]::varchar[];
|
||||
COMMIT;
|
||||
@@ -19,7 +19,7 @@ func (s requestService) Request(id int64) (geeksbot.Request, error) {
|
||||
var uID sql.NullString
|
||||
var mID string
|
||||
queryString := `SELECT id, author_id, channel_id, guild_id, content, requested_at, completed,
|
||||
completed_at, completed_by, message_id, completed_message
|
||||
completed_at, completed_by, message_id, completed_message FROM requests
|
||||
WHERE id = $1`
|
||||
row := s.db.QueryRow(queryString, id)
|
||||
err := row.Scan(&r.ID, &aID, &cID, &gID, &r.Content, &r.RequestedAt, &r.Completed,
|
||||
@@ -168,7 +168,7 @@ func (s requestService) Comment(id int64) (geeksbot.Comment, error) {
|
||||
var c geeksbot.Comment
|
||||
var aID string
|
||||
var rID int64
|
||||
queryString := "SELECT id, author_id, request_id, comment_at, content WHERE id = $1"
|
||||
queryString := "SELECT id, author_id, request_id, comment_at, content FROM comments WHERE id = $1"
|
||||
row := s.db.QueryRow(queryString, id)
|
||||
err := row.Scan(&c.ID, &aID, &rID, &c.CommentAt, &c.Content)
|
||||
if err != nil {
|
||||
@@ -2,7 +2,7 @@ package services
|
||||
|
||||
import (
|
||||
"github.com/dustinpianalto/geeksbot"
|
||||
"github.com/dustinpianalto/geeksbot/internal/database"
|
||||
"github.com/dustinpianalto/geeksbot/pkg/database"
|
||||
)
|
||||
|
||||
var (
|
||||
Reference in New Issue
Block a user