Compare commits

...
7 Commits
Author SHA1 Message Date
Dustin Pianalto cb7c487b42 fix create channel sql query
CI / build (push) Has been cancelled
2021-01-25 02:05:13 -09:00
Dustin Pianalto e1ea9cab1f fix create channel sql query
CI / build (push) Has been cancelled
2021-01-25 01:59:57 -09:00
Dustin Pianalto a6dc6f5e56 fix get user sql query
CI / build (push) Has been cancelled
2021-01-25 01:52:14 -09:00
Dustin Pianalto 203d1bbf69 fix get user sql query
CI / build (push) Has been cancelled
2021-01-25 01:43:31 -09:00
Dustin Pianalto c504f7b165 fix get user sql query
CI / build (push) Has been cancelled
2021-01-25 01:38:22 -09:00
Dustin Pianalto 34564140f5 add request command
CI / build (push) Has been cancelled
2021-01-25 01:33:46 -09:00
Dustin Pianalto e3ccc56dba add request command
CI / build (push) Has been cancelled
2021-01-25 01:21:49 -09:00
4 changed files with 49 additions and 6 deletions
+4 -3
View File
@@ -29,7 +29,7 @@ func (s channelService) Channel(id string) (geeksbot.Channel, error) {
}
func (s channelService) CreateChannel(c geeksbot.Channel) (geeksbot.Channel, error) {
queryString := "INSERT INTO channels (id, guild_id, admin, default_channel, new_patron VALUES ($1, $2, $3, $4, $5))"
queryString := "INSERT INTO channels (id, guild_id, admin, default_channel, new_patron) VALUES ($1, $2, $3, $4, $5)"
_, err := s.db.Exec(queryString, c.ID, c.Guild.ID, c.Admin, c.Default, c.NewPatron)
return c, err
}
@@ -69,8 +69,9 @@ func (s channelService) GuildChannels(g geeksbot.Guild) ([]geeksbot.Channel, err
func (s channelService) GetOrCreateChannel(id string, guild_id string) (geeksbot.Channel, error) {
channel, err := s.Channel(id)
if err == sql.ErrNoRows {
guild, err := GuildService.GetOrCreateGuild(guild_id)
if err.Error() == sql.ErrNoRows.Error() {
var guild geeksbot.Guild
guild, err = GuildService.GetOrCreateGuild(guild_id)
if err != nil {
return geeksbot.Channel{}, err
}
+1 -1
View File
@@ -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
+2
View File
@@ -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)
}
+42 -2
View File
@@ -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)
}
}