rework services and add test command

This commit is contained in:
Dustin Pianalto
2021-01-23 03:53:34 -09:00
parent ccfecd0965
commit 28691e72fb
5 changed files with 68 additions and 32 deletions
+3 -2
View File
@@ -1,11 +1,11 @@
package exts
import (
"github.com/dustinpianalto/geeksbot"
"github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/geeksbot/internal/exts/utils"
)
func AddCommandHandlers(g *geeksbot.Geeksbot) {
func AddCommandHandlers(g *disgoman.CommandManager) {
// Arguments:
// name - command name - string
// desc - command description - string
@@ -15,6 +15,7 @@ func AddCommandHandlers(g *geeksbot.Geeksbot) {
// type - command type, sets where the command is available
// run - function to run - func(anpan.Context, []string) / CommandRunFunc
_ = g.AddCommand(utils.UserCommand)
_ = g.AddCommand(utils.AddUserCommand)
_ = g.AddCommand(utils.SayCommand)
_ = g.AddCommand(utils.GitCommand)
_ = g.AddCommand(utils.InviteCommand)
+33
View File
@@ -9,7 +9,9 @@ import (
"github.com/bwmarrin/discordgo"
"github.com/dustinpianalto/disgoman"
"github.com/dustinpianalto/geeksbot"
"github.com/dustinpianalto/geeksbot/internal/discord_utils"
"github.com/dustinpianalto/geeksbot/internal/services"
)
var PingCommand = &disgoman.Command{
@@ -246,3 +248,34 @@ func userCommandFunc(ctx disgoman.Context, args []string) {
}
}
}
var AddUserCommand = &disgoman.Command{
Name: "user",
Aliases: nil,
Description: "Get user info",
OwnerOnly: false,
Hidden: false,
RequiredPermissions: 0,
Invoke: addUserCommandFunc,
}
func addUserCommandFunc(ctx disgoman.Context, args []string) {
if ctx.Message.Author.ID == ctx.CommandManager.Owners[0] {
user := geeksbot.User{
ID: ctx.Message.Author.ID,
IsActive: true,
IsStaff: true,
IsAdmin: true,
}
user, err := services.UserService.CreateUser(user)
if err != nil {
ctx.CommandManager.ErrorChannel <- disgoman.CommandError{
Context: ctx,
Message: "Error with adding user",
Error: err,
}
return
}
ctx.Session.MessageReactionAdd(ctx.Channel.ID, ctx.Message.ID, "✅")
}
}
+26
View File
@@ -0,0 +1,26 @@
package services
import (
"github.com/dustinpianalto/geeksbot"
"github.com/dustinpianalto/geeksbot/internal/database"
)
var (
GuildService geeksbot.GuildService
UserService geeksbot.UserService
ChannelService geeksbot.ChannelService
MessageService geeksbot.MessageService
PatreonService geeksbot.PatreonService
RequestService geeksbot.RequestService
ServerService geeksbot.ServerService
)
func InitializeServices() {
GuildService = database.GuildService
UserService = database.UserService
ChannelService = database.ChannelService
MessageService = database.MessageService
PatreonService = database.PatreonService
RequestService = database.RequestService
ServerService = database.ServerService
}