Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c504f7b165 | ||
|
|
34564140f5 | ||
|
|
e3ccc56dba |
@@ -12,7 +12,7 @@ type userService struct {
|
||||
|
||||
func (s userService) User(id string) (geeksbot.User, error) {
|
||||
var user geeksbot.User
|
||||
queryString := "SELECT id, steam_id, active, staff, admin WHERE id = $1"
|
||||
queryString := "SELECT id, steam_id, active, staff, admin FROM users WHERE id = $1"
|
||||
row := s.db.QueryRow(queryString, id)
|
||||
err := row.Scan(&user.ID, &user.SteamID, &user.IsActive, &user.IsStaff, &user.IsAdmin)
|
||||
return user, err
|
||||
|
||||
@@ -3,6 +3,7 @@ package exts
|
||||
import (
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"github.com/dustinpianalto/geeksbot/internal/exts/guild"
|
||||
"github.com/dustinpianalto/geeksbot/internal/exts/requests"
|
||||
"github.com/dustinpianalto/geeksbot/internal/exts/utils"
|
||||
)
|
||||
|
||||
@@ -23,4 +24,5 @@ func AddCommandHandlers(g *disgoman.CommandManager) {
|
||||
_ = g.AddCommand(utils.PingCommand)
|
||||
_ = g.AddCommand(guild.AddPrefixCommand)
|
||||
_ = g.AddCommand(guild.RemovePrefixCommand)
|
||||
_ = g.AddCommand(requests.RequestCommand)
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package requests
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/dustinpianalto/disgoman"
|
||||
"github.com/dustinpianalto/geeksbot"
|
||||
@@ -29,12 +31,12 @@ func requestCommandFunc(ctx disgoman.Context, args []string) {
|
||||
requestMsg := strings.Join(args, " ")
|
||||
author, err := services.UserService.GetOrCreateUser(ctx.Message.Author.ID)
|
||||
if err != nil {
|
||||
discord_utils.SendErrorMessage(ctx, "Error creating the request", err)
|
||||
discord_utils.SendErrorMessage(ctx, "Error creating the request. Could not get user.", err)
|
||||
return
|
||||
}
|
||||
channel, err := services.ChannelService.GetOrCreateChannel(ctx.Message.ChannelID, ctx.Guild.ID)
|
||||
if err != nil {
|
||||
discord_utils.SendErrorMessage(ctx, "Error creating the request", err)
|
||||
discord_utils.SendErrorMessage(ctx, "Error creating the request. Could not get channel.", err)
|
||||
return
|
||||
}
|
||||
int64ID, _ := strconv.ParseInt(ctx.Message.ID, 10, 64)
|
||||
@@ -60,4 +62,42 @@ func requestCommandFunc(ctx disgoman.Context, args []string) {
|
||||
discord_utils.SendErrorMessage(ctx, "Error creating the request", err)
|
||||
return
|
||||
}
|
||||
channels, err := services.ChannelService.GuildChannels(guild)
|
||||
if err == nil {
|
||||
var mentionRolesString string
|
||||
roles, err := services.GuildService.GuildRoles(guild)
|
||||
if err == nil {
|
||||
for _, r := range roles {
|
||||
if r.RoleType == "admin" || r.RoleType == "moderator" {
|
||||
mentionRolesString += fmt.Sprintf("<@&%s> ", r.ID)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, c := range channels {
|
||||
if c.Admin {
|
||||
_, _ = ctx.Session.ChannelMessageSend(c.ID,
|
||||
fmt.Sprintf("%s\n"+
|
||||
"New Request ID %d "+
|
||||
"%s has requested assistance: \n"+
|
||||
"```\n%s\n```\n"+
|
||||
"Requested At: %s\n"+
|
||||
"In: %s",
|
||||
mentionRolesString,
|
||||
request.ID,
|
||||
ctx.Message.Author.Mention,
|
||||
request.Content,
|
||||
request.RequestedAt.UTC().Format(time.UnixDate),
|
||||
ctx.Channel.Mention(),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
_, err = ctx.Send(fmt.Sprintf("%s The admin have recieved your request.\n "+
|
||||
"If you would like to close or add a comment to this request please reference ID `%v`",
|
||||
ctx.Message.Author.Mention, request.ID,
|
||||
))
|
||||
if err != nil {
|
||||
discord_utils.SendErrorMessage(ctx, "There was an error sending the message. The request was created.", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user