Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e526d27f4a | ||
|
|
68c06a7356 | ||
|
|
c8277cce42 | ||
|
|
3069e24e8d | ||
|
|
472f23cc2b |
@@ -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{
|
||||
|
||||
@@ -9,7 +9,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 RequestCommand = &disgoman.Command{
|
||||
@@ -101,3 +101,150 @@ 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"+
|
||||
"< %11s %-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,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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"
|
||||
@@ -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