Compare commits

..
19 Commits
Author SHA1 Message Date
Dustin Pianalto 2abe574977 Update database schema to not allow null previous_content
CI / build (push) Has been cancelled
2021-02-22 21:56:18 -09:00
Dustin Pianalto 04c32955c7 Update database schema to not allow null previous_content
CI / build (push) Has been cancelled
2021-02-22 21:29:41 -09:00
Dustin Pianalto 1f70318d26 Update database schema to not allow null previous_content
CI / build (push) Has been cancelled
2021-02-22 21:24:55 -09:00
Dustin Pianalto 47ed519376 Update database schema to not allow null previous_content
CI / build (push) Has been cancelled
2021-02-22 21:16:28 -09:00
Dustin Pianalto 22912c7367 Fix broken SQL query
CI / build (push) Has been cancelled
2021-02-22 20:13:29 -09:00
Dustin Pianalto 6b15540d4e Add close and list commands
CI / build (push) Has been cancelled
2021-02-22 19:59:39 -09:00
Dustin Pianalto e526d27f4a update actions
CI / build (push) Has been cancelled
2021-02-22 19:51:04 -09:00
Dustin Pianalto 68c06a7356 Add request close and list commands
CI / build (push) Has been cancelled
2021-02-22 19:37:38 -09:00
Dustin Pianalto c8277cce42 Merge branch 'development' of github.com:dustinpianalto/Geeksbot into development 2021-02-22 14:05:09 -09:00
Dustin Pianalto 3069e24e8d Move db and services to pkg 2021-02-22 14:04:51 -09:00
Dustin Pianalto 472f23cc2b start close command 2021-02-07 11:27:33 -09:00
Dustin Pianalto 6d920e615d Add sar commands
CI / build (push) Has been cancelled
2021-01-30 22:52:25 -09:00
Dustin Pianalto 0b8b57a884 Add sar commands
CI / build (push) Has been cancelled
2021-01-30 22:42:14 -09:00
Dustin Pianalto 9382798997 Add sar commands
CI / build (push) Has been cancelled
2021-01-30 22:31:22 -09:00
Dustin Pianalto 24448c79f5 Add sar commands
CI / build (push) Has been cancelled
2021-01-30 22:17:01 -09:00
Dustin Pianalto 71aac148e0 remove mod/admin role command
CI / build (push) Has been cancelled
2021-01-26 00:08:20 -09:00
Dustin Pianalto 132bf94332 remove mod/admin role command
CI / build (push) Has been cancelled
2021-01-25 23:53:32 -09:00
Dustin Pianalto 964be05c48 remove mod/admin role command
CI / build (push) Has been cancelled
2021-01-25 23:49:58 -09:00
Dustin Pianalto 4895294969 fix role commands
CI / build (push) Has been cancelled
2021-01-25 23:09:21 -09:00
29 changed files with 555 additions and 15 deletions
+5 -3
View File
@@ -26,8 +26,8 @@ jobs:
GOPATH: /home/runner/work/Geeksbot/ GOPATH: /home/runner/work/Geeksbot/
run: | run: |
go get -u github.com/go-bindata/go-bindata/... 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/ /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/internal/database/migrations/bindata.go head $GITHUB_WORKSPACE/pkg/database/migrations/bindata.go
- name: Build container image - name: Build container image
env: env:
@@ -43,7 +43,9 @@ jobs:
run: doctl registry login --expiry-seconds 600 run: doctl registry login --expiry-seconds 600
- name: Push image to DigitalOcean Container Registry - 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 - 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 run: TAG=${{ steps.get_version.outputs.version-without-v }} && sed -i 's|<IMAGE>|registry.digitalocean.com/djpianalto/geeksbot:'${TAG}'|' $GITHUB_WORKSPACE/deployment.yml
+2 -2
View File
@@ -8,9 +8,9 @@ import (
"github.com/bwmarrin/discordgo" "github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/geeksbot/internal/database"
"github.com/dustinpianalto/geeksbot/internal/exts" "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() { func main() {
+49
View File
@@ -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
}
+1 -1
View File
@@ -6,8 +6,8 @@ import (
"github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/geeksbot" "github.com/dustinpianalto/geeksbot"
"github.com/dustinpianalto/geeksbot/internal/discord_utils" "github.com/dustinpianalto/geeksbot/internal/discord_utils"
"github.com/dustinpianalto/geeksbot/internal/services"
"github.com/dustinpianalto/geeksbot/internal/utils" "github.com/dustinpianalto/geeksbot/internal/utils"
"github.com/dustinpianalto/geeksbot/pkg/services"
) )
var AddPrefixCommand = &disgoman.Command{ var AddPrefixCommand = &disgoman.Command{
+304 -3
View File
@@ -2,12 +2,15 @@ package guild
import ( import (
"fmt" "fmt"
"strconv"
"strings" "strings"
"github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/geeksbot" "github.com/dustinpianalto/geeksbot"
"github.com/dustinpianalto/geeksbot/internal/discord_utils" "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{ var AddModeratorRoleCommand = &disgoman.Command{
@@ -37,6 +40,10 @@ func addModeratorRoleCommandFunc(ctx disgoman.Context, args []string) {
if _, ok := added[id]; ok { if _, ok := added[id]; ok {
continue continue
} }
if _, err = ctx.Session.State.Role(ctx.Guild.ID, id); err != nil {
_, _ = ctx.Send(fmt.Sprintf("%s does not reference a valid role for this guild.", id))
continue
}
_, err := services.GuildService.CreateOrUpdateRole(geeksbot.Role{ _, err := services.GuildService.CreateOrUpdateRole(geeksbot.Role{
ID: id, ID: id,
RoleType: "moderator", RoleType: "moderator",
@@ -50,7 +57,7 @@ func addModeratorRoleCommandFunc(ctx disgoman.Context, args []string) {
count++ count++
_, _ = ctx.Send(fmt.Sprintf("Added <@&%s> as a moderator role.", id)) _, _ = ctx.Send(fmt.Sprintf("Added <@&%s> as a moderator role.", id))
} }
_, _ = ctx.Send(fmt.Sprintf("Added %d moderator roles.", count)) _, _ = ctx.Send(fmt.Sprintf("Added %d moderator %s.", count, utils.PluralizeString("role", count)))
} else { } else {
_, _ = ctx.Send("Please include at least one role to make a moderator role.") _, _ = ctx.Send("Please include at least one role to make a moderator role.")
} }
@@ -83,6 +90,10 @@ func addAdminRoleCommandFunc(ctx disgoman.Context, args []string) {
if _, ok := added[id]; ok { if _, ok := added[id]; ok {
continue continue
} }
if _, err = ctx.Session.State.Role(ctx.Guild.ID, id); err != nil {
_, _ = ctx.Send(fmt.Sprintf("%s does not reference a valid role for this guild.", id))
continue
}
_, err := services.GuildService.CreateOrUpdateRole(geeksbot.Role{ _, err := services.GuildService.CreateOrUpdateRole(geeksbot.Role{
ID: id, ID: id,
RoleType: "admin", RoleType: "admin",
@@ -96,8 +107,298 @@ func addAdminRoleCommandFunc(ctx disgoman.Context, args []string) {
count++ count++
_, _ = ctx.Send(fmt.Sprintf("Added <@&%s> as an admin role.", id)) _, _ = ctx.Send(fmt.Sprintf("Added <@&%s> as an admin role.", id))
} }
_, _ = ctx.Send(fmt.Sprintf("Added %d admin roles.", count)) _, _ = ctx.Send(fmt.Sprintf("Added %d admin %s.", count, utils.PluralizeString("role", count)))
} else { } else {
_, _ = ctx.Send("Please include at least one role to make an admin role.") _, _ = ctx.Send("Please include at least one role to make an admin role.")
} }
} }
var RemoveModRoleCommand = &disgoman.Command{
Name: "removeMod",
Aliases: []string{"removeModeratorRole", "removeModRole", "removeAdmin", "removeAdminRole"},
Description: "Remove a role or several roles from the moderator or admin list",
OwnerOnly: false,
Hidden: false,
RequiredPermissions: disgoman.PermissionManageServer,
Invoke: removeModRoleCommandFunc,
}
func removeModRoleCommandFunc(ctx disgoman.Context, args []string) {
var count int
added := make(map[string]bool)
guild, err := services.GuildService.GetOrCreateGuild(ctx.Guild.ID)
if err != nil {
discord_utils.SendErrorMessage(ctx, "Something went wrong getting the guild", err)
return
}
roles := append(args, ctx.Message.MentionRoles...)
if len(roles) > 0 {
for _, id := range roles {
if strings.HasPrefix(id, "<@&") && strings.HasSuffix(id, ">") {
continue
}
if _, ok := added[id]; ok {
continue
}
if _, err = ctx.Session.State.Role(ctx.Guild.ID, id); err != nil {
if r, err := services.GuildService.Role(id); err != nil {
_, _ = ctx.Send(fmt.Sprintf("%s does not reference a valid role for this guild.", id))
continue
} else {
err = services.GuildService.DeleteRole(r)
if err != nil {
discord_utils.SendErrorMessage(ctx, "Something went wrong deleting the role", err)
}
_, _ = ctx.Send(fmt.Sprintf("Deleted <@&%s> as a no longer a valid role.", id))
continue
}
}
_, err := services.GuildService.CreateOrUpdateRole(geeksbot.Role{
ID: id,
RoleType: "normal",
Guild: guild,
})
if err != nil {
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("There was a problem updating <@&%s>", id), err)
continue
}
added[id] = true
count++
_, _ = ctx.Send(fmt.Sprintf("Set <@&%s> as a normal role.", id))
}
_, _ = ctx.Send(fmt.Sprintf("Set %d %s to normal.", count, utils.PluralizeString("role", count)))
} else {
_, _ = ctx.Send("Please include at least one role to remove from the moderator or admin lists.")
}
}
var MakeRoleSelfAssignableCommand = &disgoman.Command{
Name: "make-role-self-assignable",
Aliases: []string{"makesar", "addsar"},
Description: "Makes the passed in role self assignable by anyone",
OwnerOnly: false,
Hidden: false,
RequiredPermissions: disgoman.PermissionManageServer,
Invoke: makeRoleSelfAssignableCommandFunc,
}
func makeRoleSelfAssignableCommandFunc(ctx disgoman.Context, args []string) {
added := make(map[string]bool)
guild, err := services.GuildService.GetOrCreateGuild(ctx.Guild.ID)
if err != nil {
discord_utils.SendErrorMessage(ctx, "Something went wrong getting the guild", err)
return
}
roles := append(args, ctx.Message.MentionRoles...)
if len(roles) > 0 {
for _, id := range roles {
if strings.HasPrefix(id, "<@&") && strings.HasSuffix(id, ">") {
continue
}
if _, ok := added[id]; ok {
continue
}
var role *discordgo.Role
var err error
if role, err = ctx.Session.State.Role(ctx.Guild.ID, id); err != nil {
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("%s does not reference a valid role for this guild", id), err)
return
}
_, err = services.GuildService.CreateOrUpdateRole(geeksbot.Role{
ID: role.ID,
RoleType: "sar",
Guild: guild,
})
if err != nil {
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("There was a problem updating <@&%s>", role.ID), err)
return
}
_, _ = ctx.Send(fmt.Sprintf("%s is now self assignable", role.Name))
}
} else {
_, _ = ctx.Send("Please include at least one role to make self assignable")
}
}
var RemoveSelfAssignableCommand = &disgoman.Command{
Name: "remove-self-assignable-role",
Aliases: []string{"removesar"},
Description: "Makes a role that was previously self assignable not so",
OwnerOnly: false,
Hidden: false,
RequiredPermissions: disgoman.PermissionManageServer,
Invoke: removeSelfAssignableRoleCommandFunc,
}
func removeSelfAssignableRoleCommandFunc(ctx disgoman.Context, args []string) {
removed := make(map[string]bool)
guild, err := services.GuildService.GetOrCreateGuild(ctx.Guild.ID)
if err != nil {
discord_utils.SendErrorMessage(ctx, "Something went wrong getting the guild", err)
return
}
roles := append(args, ctx.Message.MentionRoles...)
if len(roles) > 0 {
for _, id := range roles {
if strings.HasPrefix(id, "<@&") && strings.HasSuffix(id, ">") {
continue
}
if _, ok := removed[id]; ok {
continue
}
var err error
var role *discordgo.Role
if role, err = ctx.Session.State.Role(ctx.Guild.ID, id); err != nil {
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("%s does not reference a valid role for this guild", id), err)
return
}
_, err = services.GuildService.CreateOrUpdateRole(geeksbot.Role{
ID: role.ID,
RoleType: "normal",
Guild: guild,
})
if err != nil {
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("There was a problem updating <@&%s>", role.ID), err)
return
}
_, _ = ctx.Send(fmt.Sprintf("%s's self assignability has been removed.", role.Name))
}
} else {
_, _ = ctx.Send("Please include at least one role to make self assignable")
}
}
var SelfAssignRoleCommand = &disgoman.Command{
Name: "giverole",
Aliases: []string{"iwant", "givetome", "addrole"},
Description: "Assigns a person the passed in role if it is self assignable",
OwnerOnly: false,
Hidden: false,
RequiredPermissions: 0,
Invoke: selfAssignRoleCommandFunc,
}
func selfAssignRoleCommandFunc(ctx disgoman.Context, args []string) {
added := make(map[string]bool)
roles := append(args, ctx.Message.MentionRoles...)
if len(roles) > 0 {
for _, id := range roles {
var roleID string
if strings.HasPrefix(id, "<@&") && strings.HasSuffix(id, ">") {
continue
} else if _, err := strconv.Atoi(id); err == nil {
roleID = id
} else {
for _, role := range ctx.Guild.Roles {
if strings.ToLower(id) == strings.ToLower(role.Name) {
roleID = role.ID
}
}
}
if _, ok := added[id]; ok {
continue
}
var role *discordgo.Role
var err error
if role, err = ctx.Session.State.Role(ctx.Guild.ID, roleID); err != nil {
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("%s does not reference a valid role for this guild", roleID), err)
return
}
if memberHasRole(ctx.Member, role.ID) {
_, _ = ctx.Send(fmt.Sprintf("You already have the %s role silly...", role.Name))
return
}
r, err := services.GuildService.Role(role.ID)
if err != nil || r.RoleType != "sar" {
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("You aren't allowed to assign yourself the %s role", role.Name), err)
return
}
err = ctx.Session.GuildMemberRoleAdd(ctx.Guild.ID, ctx.User.ID, role.ID)
if err != nil {
discord_utils.SendErrorMessage(ctx, "There was a problem adding that role to you.", err)
return
}
_, _ = ctx.Send(fmt.Sprintf("Congratulations! The %s role has been added to your... Ummm... Thing.", role.Name))
}
} else {
_, _ = ctx.Send("Please include at least one role to make self assignable")
}
}
var UnAssignRoleCommand = &disgoman.Command{
Name: "removerole",
Aliases: []string{"idon'twant"},
Description: "Removes a role from a person if the role is self assignable",
OwnerOnly: false,
Hidden: false,
RequiredPermissions: 0,
Invoke: unAssignRoleCommandFunc,
}
func unAssignRoleCommandFunc(ctx disgoman.Context, args []string) {
removed := make(map[string]bool)
roles := append(args, ctx.Message.MentionRoles...)
if len(roles) > 0 {
for _, id := range roles {
var roleID string
if strings.HasPrefix(id, "<@&") && strings.HasSuffix(id, ">") {
continue
} else if _, err := strconv.Atoi(id); err == nil {
roleID = id
} else {
for _, role := range ctx.Guild.Roles {
if strings.ToLower(id) == strings.ToLower(role.Name) {
roleID = role.ID
}
}
}
if _, ok := removed[id]; ok {
continue
}
var role *discordgo.Role
var err error
if role, err = ctx.Session.State.Role(ctx.Guild.ID, roleID); err != nil {
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("%s does not reference a valid role for this guild", roleID), err)
return
}
if !memberHasRole(ctx.Member, role.ID) {
_, _ = ctx.Send(fmt.Sprintf("I can't remove the %s role from you because you don't have it...", role.Name))
return
}
r, err := services.GuildService.Role(role.ID)
if err != nil || r.RoleType != "sar" {
discord_utils.SendErrorMessage(ctx, fmt.Sprintf("You aren't allowed to assign yourself the %s role", role.Name), err)
return
}
err = ctx.Session.GuildMemberRoleRemove(ctx.Guild.ID, ctx.User.ID, role.ID)
if err != nil {
discord_utils.SendErrorMessage(ctx, "There was a problem removing that role from your account", err)
return
}
_, _ = ctx.Send(fmt.Sprintf("Sad to see you go... but the %s role has been removed.", role.Name))
}
} else {
_, _ = ctx.Send("Please include at least one role to make self assignable")
}
}
func memberHasRole(m *discordgo.Member, id string) bool {
for _, r := range m.Roles {
if r == id {
return true
}
}
return false
}
+7
View File
@@ -26,5 +26,12 @@ func AddCommandHandlers(g *disgoman.CommandManager) {
_ = g.AddCommand(guild.RemovePrefixCommand) _ = g.AddCommand(guild.RemovePrefixCommand)
_ = g.AddCommand(guild.AddModeratorRoleCommand) _ = g.AddCommand(guild.AddModeratorRoleCommand)
_ = g.AddCommand(guild.AddAdminRoleCommand) _ = g.AddCommand(guild.AddAdminRoleCommand)
_ = g.AddCommand(guild.RemoveModRoleCommand)
_ = g.AddCommand(guild.MakeRoleSelfAssignableCommand)
_ = g.AddCommand(guild.RemoveSelfAssignableCommand)
_ = g.AddCommand(guild.SelfAssignRoleCommand)
_ = g.AddCommand(guild.UnAssignRoleCommand)
_ = g.AddCommand(requests.RequestCommand) _ = g.AddCommand(requests.RequestCommand)
_ = g.AddCommand(requests.CloseCommand)
_ = g.AddCommand(requests.ListCommand)
} }
+148 -1
View File
@@ -9,7 +9,7 @@ import (
"github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/geeksbot" "github.com/dustinpianalto/geeksbot"
"github.com/dustinpianalto/geeksbot/internal/discord_utils" "github.com/dustinpianalto/geeksbot/internal/discord_utils"
"github.com/dustinpianalto/geeksbot/internal/services" "github.com/dustinpianalto/geeksbot/pkg/services"
) )
var RequestCommand = &disgoman.Command{ 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) 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,
))
}
}
+1 -1
View File
@@ -11,7 +11,7 @@ import (
"github.com/dustinpianalto/disgoman" "github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/geeksbot" "github.com/dustinpianalto/geeksbot"
"github.com/dustinpianalto/geeksbot/internal/discord_utils" "github.com/dustinpianalto/geeksbot/internal/discord_utils"
"github.com/dustinpianalto/geeksbot/internal/services" "github.com/dustinpianalto/geeksbot/pkg/services"
) )
var PingCommand = &disgoman.Command{ var PingCommand = &disgoman.Command{
+7
View File
@@ -12,3 +12,10 @@ func RemoveDuplicateStrings(s []string) []string {
} }
return o return o
} }
func PluralizeString(s string, i int) string {
if i == 1 {
return s
}
return s + "s"
}
@@ -5,7 +5,7 @@ import (
"fmt" "fmt"
"log" "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"
"github.com/golang-migrate/migrate/v4/database/postgres" "github.com/golang-migrate/migrate/v4/database/postgres"
bindata "github.com/golang-migrate/migrate/v4/source/go_bindata" bindata "github.com/golang-migrate/migrate/v4/source/go_bindata"
@@ -0,0 +1,14 @@
BEGIN;
CREATE TYPE role_type_new AS ENUM (
'normal',
'moderator',
'admin',
'patreon',
);
UPDATE roles SET role_type = 'normal' WHERE role_type = 'sar';
ALTER TABLE roles
ALTER COLUMN roles TYPE role_type_new;
USING (roles::text::role_type_new)
DROP TYPE role_type;
ALTER TYPE role_type_new RENAME TO role_type;
COMMIT;
@@ -0,0 +1 @@
ALTER TYPE role_type ADD VALUE 'sar';
@@ -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 uID sql.NullString
var mID string var mID string
queryString := `SELECT id, author_id, channel_id, guild_id, content, requested_at, completed, 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` WHERE id = $1`
row := s.db.QueryRow(queryString, id) row := s.db.QueryRow(queryString, id)
err := row.Scan(&r.ID, &aID, &cID, &gID, &r.Content, &r.RequestedAt, &r.Completed, 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 c geeksbot.Comment
var aID string var aID string
var rID int64 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) row := s.db.QueryRow(queryString, id)
err := row.Scan(&c.ID, &aID, &rID, &c.CommentAt, &c.Content) err := row.Scan(&c.ID, &aID, &rID, &c.CommentAt, &c.Content)
if err != nil { if err != nil {
@@ -2,7 +2,7 @@ package services
import ( import (
"github.com/dustinpianalto/geeksbot" "github.com/dustinpianalto/geeksbot"
"github.com/dustinpianalto/geeksbot/internal/database" "github.com/dustinpianalto/geeksbot/pkg/database"
) )
var ( var (