Add commands and event handlers
This commit is contained in:
parent
9e33d58a14
commit
be81d2280a
7
djpianalto.com/goff/events/member_events.go
Normal file
7
djpianalto.com/goff/events/member_events.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package events
|
||||||
|
|
||||||
|
import "github.com/bwmarrin/discordgo"
|
||||||
|
|
||||||
|
func OnMemberAdd(s *discordgo.Session, event *discordgo.GuildMemberAdd) {
|
||||||
|
|
||||||
|
}
|
||||||
77
djpianalto.com/goff/exts/P_interpreter.go
Normal file
77
djpianalto.com/goff/exts/P_interpreter.go
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
package exts
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"github.com/dustinpianalto/disgoman"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func pCommand(ctx disgoman.Context, args []string) error {
|
||||||
|
input := strings.Join(args, "")
|
||||||
|
const LENGTH = 1999
|
||||||
|
var mem [LENGTH]byte
|
||||||
|
pointer := 0
|
||||||
|
l := 0
|
||||||
|
for i := 0; i < len(input); i++ {
|
||||||
|
if input[i] == 'L' {
|
||||||
|
if pointer == 0 {
|
||||||
|
pointer = LENGTH - 1
|
||||||
|
} else {
|
||||||
|
pointer--
|
||||||
|
}
|
||||||
|
} else if input[i] == 'R' {
|
||||||
|
if pointer == LENGTH-1 {
|
||||||
|
pointer = 0
|
||||||
|
} else {
|
||||||
|
pointer++
|
||||||
|
}
|
||||||
|
} else if input[i] == '+' {
|
||||||
|
mem[pointer]++
|
||||||
|
} else if input[i] == '-' {
|
||||||
|
mem[pointer]--
|
||||||
|
} else if input[i] == '(' {
|
||||||
|
if mem[pointer] == 0 {
|
||||||
|
i++
|
||||||
|
for l > 0 || input[i] != ')' {
|
||||||
|
if input[i] == '(' {
|
||||||
|
l++
|
||||||
|
}
|
||||||
|
if input[i] == ')' {
|
||||||
|
l--
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if input[i] == ')' {
|
||||||
|
if mem[pointer] != 0 {
|
||||||
|
i--
|
||||||
|
for l > 0 || input[i] != '(' {
|
||||||
|
if input[i] == ')' {
|
||||||
|
l++
|
||||||
|
}
|
||||||
|
if input[i] == '(' {
|
||||||
|
l--
|
||||||
|
}
|
||||||
|
i--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx.Send(fmt.Sprintf("Invalid Character: %v", input[i]))
|
||||||
|
return errors.New("invalid character")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var out []byte
|
||||||
|
for _, i := range mem {
|
||||||
|
if i != 0 {
|
||||||
|
out = append(out, i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println(out)
|
||||||
|
_, err := ctx.Send(string(out))
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
49
djpianalto.com/goff/exts/guild.go
Normal file
49
djpianalto.com/goff/exts/guild.go
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
package exts
|
||||||
|
|
||||||
|
import (
|
||||||
|
"djpianalto.com/goff/djpianalto.com/goff/utils"
|
||||||
|
"github.com/dustinpianalto/disgoman"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Guild management commands
|
||||||
|
|
||||||
|
func loggingChannel(ctx disgoman.Context, args []string) error {
|
||||||
|
var idString string
|
||||||
|
if len(args) > 0 {
|
||||||
|
idString = args[0]
|
||||||
|
if strings.HasPrefix(idString, "<#") && strings.HasSuffix(idString, ">") {
|
||||||
|
idString = idString[2 : len(idString)-1]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
idString = "0"
|
||||||
|
}
|
||||||
|
id, err := strconv.ParseInt(idString, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
_, _ = ctx.Send("An invalid ID was passed.")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if id == 0 {
|
||||||
|
_, err = utils.Database.Exec("UPDATE guilds SET logging_channel=NULL WHERE id=$1;", ctx.Guild.ID)
|
||||||
|
if err != nil {
|
||||||
|
_, _ = ctx.Send("Error Updating Database")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
channel, err := ctx.Session.State.Channel(idString)
|
||||||
|
if err != nil {
|
||||||
|
_, _ = ctx.Send("Can't find that channel.")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if channel.GuildID != ctx.Guild.ID {
|
||||||
|
_, _ = ctx.Send("The channel passed is not in this guild.")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = utils.Database.Exec("UPDATE guilds SET logging_channel=$1 WHERE id=$2;", id, ctx.Guild.ID)
|
||||||
|
if err != nil {
|
||||||
|
_, _ = ctx.Send("Error Updating Database")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, _ = ctx.Send("Logging Channel Updated.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@ -1,8 +1,10 @@
|
|||||||
package exts
|
package exts
|
||||||
|
|
||||||
import "github.com/MikeModder/anpan"
|
import (
|
||||||
|
"github.com/dustinpianalto/disgoman"
|
||||||
|
)
|
||||||
|
|
||||||
func AddCommandHandlers(h *anpan.CommandHandler) {
|
func AddCommandHandlers(h *disgoman.CommandManager) {
|
||||||
// Arguments:
|
// Arguments:
|
||||||
// name - command name - string
|
// name - command name - string
|
||||||
// desc - command description - string
|
// desc - command description - string
|
||||||
@ -11,8 +13,85 @@ func AddCommandHandlers(h *anpan.CommandHandler) {
|
|||||||
// perms - permissisions required - anpan.Permission (int)
|
// perms - permissisions required - anpan.Permission (int)
|
||||||
// type - command type, sets where the command is available
|
// type - command type, sets where the command is available
|
||||||
// run - function to run - func(anpan.Context, []string) / CommandRunFunc
|
// run - function to run - func(anpan.Context, []string) / CommandRunFunc
|
||||||
h.AddCommand("ping", "Check the bot's ping", false, false, 0, anpan.CommandTypeEverywhere, pingCommand)
|
h.AddCommand(&disgoman.Command{
|
||||||
h.AddCommand("say", "Repeat a message", false, false, 0, anpan.CommandTypeEverywhere, sayCommand)
|
Name: "ping",
|
||||||
h.AddCommand("user", "Show info about a user", false, false, 0, anpan.CommandTypeEverywhere, userCommand)
|
Aliases: nil,
|
||||||
h.AddCommand("git", "Show my github link", false, false, 0, anpan.CommandTypeEverywhere, gitCommand)
|
Description: "Check the bot's ping",
|
||||||
|
OwnerOnly: false,
|
||||||
|
Hidden: false,
|
||||||
|
RequiredPermissions: 0,
|
||||||
|
Invoke: pingCommand,
|
||||||
|
})
|
||||||
|
h.AddCommand(&disgoman.Command{
|
||||||
|
Name: "say",
|
||||||
|
Aliases: nil,
|
||||||
|
Description: "Repeat a message",
|
||||||
|
OwnerOnly: false,
|
||||||
|
Hidden: false,
|
||||||
|
RequiredPermissions: 0,
|
||||||
|
Invoke: sayCommand,
|
||||||
|
})
|
||||||
|
h.AddCommand(&disgoman.Command{
|
||||||
|
Name: "user",
|
||||||
|
Aliases: nil,
|
||||||
|
Description: "Get user info",
|
||||||
|
OwnerOnly: false,
|
||||||
|
Hidden: false,
|
||||||
|
RequiredPermissions: 0,
|
||||||
|
Invoke: userCommand,
|
||||||
|
})
|
||||||
|
h.AddCommand(&disgoman.Command{
|
||||||
|
Name: "git",
|
||||||
|
Aliases: nil,
|
||||||
|
Description: "Show my github link",
|
||||||
|
OwnerOnly: false,
|
||||||
|
Hidden: false,
|
||||||
|
RequiredPermissions: 0,
|
||||||
|
Invoke: gitCommand,
|
||||||
|
})
|
||||||
|
h.AddCommand(&disgoman.Command{
|
||||||
|
Name: "tag",
|
||||||
|
Aliases: nil,
|
||||||
|
Description: "Get a tag",
|
||||||
|
OwnerOnly: false,
|
||||||
|
Hidden: false,
|
||||||
|
RequiredPermissions: 0,
|
||||||
|
Invoke: tagCommand,
|
||||||
|
})
|
||||||
|
h.AddCommand(&disgoman.Command{
|
||||||
|
Name: "addtag",
|
||||||
|
Aliases: nil,
|
||||||
|
Description: "Add a tag",
|
||||||
|
OwnerOnly: false,
|
||||||
|
Hidden: false,
|
||||||
|
RequiredPermissions: 0,
|
||||||
|
Invoke: addTagCommand,
|
||||||
|
})
|
||||||
|
h.AddCommand(&disgoman.Command{
|
||||||
|
Name: "invite",
|
||||||
|
Aliases: nil,
|
||||||
|
Description: "Get the invite link for this bot or others",
|
||||||
|
OwnerOnly: false,
|
||||||
|
Hidden: false,
|
||||||
|
RequiredPermissions: 0,
|
||||||
|
Invoke: inviteCommand,
|
||||||
|
})
|
||||||
|
h.AddCommand(&disgoman.Command{
|
||||||
|
Name: "P",
|
||||||
|
Aliases: nil,
|
||||||
|
Description: "Interpret a P\" program and return the results",
|
||||||
|
OwnerOnly: false,
|
||||||
|
Hidden: false,
|
||||||
|
RequiredPermissions: 0,
|
||||||
|
Invoke: pCommand,
|
||||||
|
})
|
||||||
|
h.AddCommand(&disgoman.Command{
|
||||||
|
Name: "set-logging-channel",
|
||||||
|
Aliases: []string{"slc"},
|
||||||
|
Description: "Set the channel logging messages will be sent to.",
|
||||||
|
OwnerOnly: false,
|
||||||
|
Hidden: false,
|
||||||
|
RequiredPermissions: disgoman.PermissionManageServer,
|
||||||
|
Invoke: loggingChannel,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
88
djpianalto.com/goff/exts/tags.go
Normal file
88
djpianalto.com/goff/exts/tags.go
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
package exts
|
||||||
|
|
||||||
|
import (
|
||||||
|
"djpianalto.com/goff/djpianalto.com/goff/utils"
|
||||||
|
"fmt"
|
||||||
|
"github.com/dustinpianalto/disgoman"
|
||||||
|
"github.com/kballard/go-shellquote"
|
||||||
|
"log"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func addTagCommand(ctx disgoman.Context, args []string) error {
|
||||||
|
if len(args) >= 1 {
|
||||||
|
args, err := shellquote.Split(strings.Join(args, " "))
|
||||||
|
if err != nil {
|
||||||
|
ctx.Send(err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
queryString := `SELECT tags.id, tags.tag, tags.content from tags
|
||||||
|
WHERE tags.guild_id = $1
|
||||||
|
AND tags.tag = $2;`
|
||||||
|
row := utils.Database.QueryRow(queryString, ctx.Guild.ID, args[0])
|
||||||
|
var dest string
|
||||||
|
if err := row.Scan(&dest); err != nil {
|
||||||
|
tag := args[0]
|
||||||
|
if tag == "" {
|
||||||
|
ctx.Send("That is not a valid tag name")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if len(args) <= 1 {
|
||||||
|
ctx.Send("I got a name but no value.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
value := args[1]
|
||||||
|
if value == "" {
|
||||||
|
ctx.Send("You have to include a content for the tag")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
queryString = `INSERT INTO tags (tag, content, creator, guild_id) VALUES ($1, $2, $3, $4);`
|
||||||
|
_, err := utils.Database.Exec(queryString, tag, value, ctx.Message.Author.ID, ctx.Guild.ID)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Send(err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ctx.Send(fmt.Sprintf("Tag %v added successfully.", tag))
|
||||||
|
return nil
|
||||||
|
} else {
|
||||||
|
ctx.Send("That tag already exists.")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx.Send("You need to tell me what tag you want to add...")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func tagCommand(ctx disgoman.Context, args []string) error {
|
||||||
|
if len(args) >= 1 {
|
||||||
|
tagString := strings.Join(args, " ")
|
||||||
|
queryString := `SELECT tags.id, tags.tag, tags.content from tags
|
||||||
|
WHERE tags.guild_id = $1;`
|
||||||
|
rows, err := utils.Database.Query(queryString, ctx.Guild.ID)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Send(err.Error())
|
||||||
|
return err
|
||||||
|
} else {
|
||||||
|
for rows.Next() {
|
||||||
|
var (
|
||||||
|
id int
|
||||||
|
tag string
|
||||||
|
content string
|
||||||
|
)
|
||||||
|
if err := rows.Scan(&id, &tag, &content); err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
if tagString == tag {
|
||||||
|
ctx.Send(content)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ctx.Send(fmt.Sprintf("Tag %v not found", args[0]))
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ctx.Send("I need a tag to check fetch...")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -3,23 +3,39 @@ package exts
|
|||||||
import (
|
import (
|
||||||
"djpianalto.com/goff/djpianalto.com/goff/utils"
|
"djpianalto.com/goff/djpianalto.com/goff/utils"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/MikeModder/anpan"
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
|
"github.com/dustinpianalto/disgoman"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func pingCommand(ctx anpan.Context, _ []string) error {
|
func pingCommand(ctx disgoman.Context, _ []string) error {
|
||||||
timeBefore := time.Now()
|
timeBefore := time.Now()
|
||||||
msg, _ := ctx.Reply("Pong!")
|
msg, _ := ctx.Send("Pong!")
|
||||||
took := time.Now().Sub(timeBefore)
|
took := time.Now().Sub(timeBefore)
|
||||||
_, err := ctx.Session.ChannelMessageEdit(ctx.Message.ChannelID, msg.ID, fmt.Sprintf("Pong!\nPing Took **%s**", took.String()))
|
_, err := ctx.Session.ChannelMessageEdit(ctx.Message.ChannelID, msg.ID, fmt.Sprintf("Pong!\nPing Took **%s**", took.String()))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func gitCommand(ctx anpan.Context, _ []string) error {
|
func inviteCommand(ctx disgoman.Context, args []string) error {
|
||||||
|
var ids []string
|
||||||
|
if len(args) == 0 {
|
||||||
|
ids = []string{ctx.Session.State.User.ID}
|
||||||
|
} else {
|
||||||
|
for _, id := range args {
|
||||||
|
ids = append(ids, id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, id := range ids {
|
||||||
|
url := fmt.Sprintf("<https://discordapp.com/oauth2/authorize?client_id=%v&scope=bot>", id)
|
||||||
|
ctx.Send(url)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func gitCommand(ctx disgoman.Context, _ []string) error {
|
||||||
embed := &discordgo.MessageEmbed{
|
embed := &discordgo.MessageEmbed{
|
||||||
Title: "Hi there, My code is on Github",
|
Title: "Hi there, My code is on Github",
|
||||||
Color: 0,
|
Color: 0,
|
||||||
@ -29,7 +45,7 @@ func gitCommand(ctx anpan.Context, _ []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func sayCommand(ctx anpan.Context, args []string) error {
|
func sayCommand(ctx disgoman.Context, args []string) error {
|
||||||
resp := strings.Join(args, " ")
|
resp := strings.Join(args, " ")
|
||||||
resp = strings.ReplaceAll(resp, "@everyone", "@\ufff0everyone")
|
resp = strings.ReplaceAll(resp, "@everyone", "@\ufff0everyone")
|
||||||
resp = strings.ReplaceAll(resp, "@here", "@\ufff0here")
|
resp = strings.ReplaceAll(resp, "@here", "@\ufff0here")
|
||||||
@ -37,7 +53,7 @@ func sayCommand(ctx anpan.Context, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func userCommand(ctx anpan.Context, args []string) error {
|
func userCommand(ctx disgoman.Context, args []string) error {
|
||||||
var member *discordgo.Member
|
var member *discordgo.Member
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
member, _ = ctx.Session.GuildMember(ctx.Guild.ID, ctx.Message.Author.ID)
|
member, _ = ctx.Session.GuildMember(ctx.Guild.ID, ctx.Message.Author.ID)
|
||||||
|
|||||||
@ -2,8 +2,10 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"djpianalto.com/goff/djpianalto.com/goff/exts"
|
"djpianalto.com/goff/djpianalto.com/goff/exts"
|
||||||
|
"djpianalto.com/goff/djpianalto.com/goff/utils"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/MikeModder/anpan"
|
"github.com/dustinpianalto/disgoman"
|
||||||
|
//"github.com/MikeModder/anpan"
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@ -26,10 +28,15 @@ func main() {
|
|||||||
fmt.Println("There was an error when creating the Discord Session, ", err)
|
fmt.Println("There was an error when creating the Discord Session, ", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
dg.State.MaxMessageCount = 100
|
||||||
|
|
||||||
prefixes := []string{
|
utils.ConnectDatabase(os.Getenv("DATABASE_URL"))
|
||||||
"Go.",
|
utils.InitializeDatabase()
|
||||||
}
|
//utils.LoadTestData()
|
||||||
|
|
||||||
|
//prefixes := []string{
|
||||||
|
// "Go.",
|
||||||
|
//}
|
||||||
owners := []string{
|
owners := []string{
|
||||||
"351794468870946827",
|
"351794468870946827",
|
||||||
}
|
}
|
||||||
@ -39,17 +46,25 @@ func main() {
|
|||||||
// owner ids - []string
|
// owner ids - []string
|
||||||
// ignore bots - bool
|
// ignore bots - bool
|
||||||
// check perms - bool
|
// check perms - bool
|
||||||
handler := anpan.NewCommandHandler(prefixes, owners, true, true)
|
handler := disgoman.CommandManager{
|
||||||
|
Prefixes: getPrefixes,
|
||||||
|
Owners: owners,
|
||||||
|
StatusManager: disgoman.GetDefaultStatusManager(),
|
||||||
|
OnErrorFunc: nil,
|
||||||
|
Commands: make(map[string]*disgoman.Command),
|
||||||
|
IgnoreBots: true,
|
||||||
|
CheckPermissions: false,
|
||||||
|
}
|
||||||
|
|
||||||
// Add Command Handlers
|
// Add Command Handlers
|
||||||
exts.AddCommandHandlers(&handler)
|
exts.AddCommandHandlers(&handler)
|
||||||
|
|
||||||
if _, ok := handler.Commands["help"]; !ok {
|
//if _, ok := handler.Commands["help"]; !ok {
|
||||||
handler.AddDefaultHelpCommand()
|
// handler.AddDefaultHelpCommand()
|
||||||
}
|
//}
|
||||||
|
|
||||||
dg.AddHandler(handler.OnMessage)
|
dg.AddHandler(handler.OnMessage)
|
||||||
dg.AddHandler(handler.StatusHandler.OnReady)
|
dg.AddHandler(handler.StatusManager.OnReady)
|
||||||
|
|
||||||
err = dg.Open()
|
err = dg.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -68,3 +83,7 @@ func main() {
|
|||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getPrefixes(guild_id string) []string {
|
||||||
|
return []string{"Go.", "go."}
|
||||||
|
}
|
||||||
|
|||||||
115
djpianalto.com/goff/utils/database.go
Normal file
115
djpianalto.com/goff/utils/database.go
Normal file
@ -0,0 +1,115 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
_ "github.com/lib/pq"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Database *sql.DB
|
||||||
|
)
|
||||||
|
|
||||||
|
func ConnectDatabase(dbConnString string) {
|
||||||
|
db, err := sql.Open("postgres", dbConnString)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("Can't connect to the database. %v", err))
|
||||||
|
} else {
|
||||||
|
fmt.Println("Database Connected.")
|
||||||
|
}
|
||||||
|
Database = db
|
||||||
|
}
|
||||||
|
|
||||||
|
func InitializeDatabase() {
|
||||||
|
_, err := Database.Query("CREATE TABLE IF NOT EXISTS users(" +
|
||||||
|
"id bigint primary key," +
|
||||||
|
"banned bool not null default false," +
|
||||||
|
"logging bool not null default true," +
|
||||||
|
"steam_id bigint default NULL," +
|
||||||
|
"is_active bool not null default true," +
|
||||||
|
"is_staff bool not null default false," +
|
||||||
|
"is_admin bool not null default false" +
|
||||||
|
")")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
_, err = Database.Query("CREATE TABLE IF NOT EXISTS guilds(" +
|
||||||
|
"id bigint primary key," +
|
||||||
|
"welcome_message varchar(1000)," +
|
||||||
|
"goodbye_message varchar(1000)," +
|
||||||
|
"logging_channel bigint" +
|
||||||
|
")")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
_, err = Database.Query("CREATE TABLE IF NOT EXISTS prefixes(" +
|
||||||
|
"id serial primary key," +
|
||||||
|
"prefix varchar(10) not null unique default 'Go.'" +
|
||||||
|
")")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
_, err = Database.Query("CREATE TABLE IF NOT EXISTS tags(" +
|
||||||
|
"id serial primary key," +
|
||||||
|
"tag varchar(100) not null unique," +
|
||||||
|
"content varchar(1000) not null," +
|
||||||
|
"creator bigint not null references users(id)," +
|
||||||
|
"creation_time timestamp not null default NOW()," +
|
||||||
|
"guild_id bigint not null" +
|
||||||
|
")")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
_, err = Database.Query("CREATE TABLE IF NOT EXISTS x_users_guilds(" +
|
||||||
|
"guild_id bigint not null references guilds(id)," +
|
||||||
|
"user_id bigint not null references users(id)" +
|
||||||
|
")")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
_, err = Database.Query("CREATE TABLE IF NOT EXISTS x_guilds_prefixes(" +
|
||||||
|
"guild_id bigint not null references guilds(id)," +
|
||||||
|
"prefix_id int not null references prefixes(id)" +
|
||||||
|
")")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func LoadTestData() {
|
||||||
|
_, err := Database.Query("INSERT INTO users (id, banned, logging, steam_id, is_active, is_staff, is_admin) values " +
|
||||||
|
"(351794468870946827, false, true, 76561198024193239, true, true, true)," +
|
||||||
|
"(692908139506434065, false, true, NULL, true, false, false)," +
|
||||||
|
"(396588996706304010, false, true, NULL, true, true, false)")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
_, err = Database.Query("INSERT INTO guilds (id, welcome_message, goodbye_message) VALUES " +
|
||||||
|
"(265828729970753537, 'Hey there is someone new here.', 'Well fine then... Just leave without saying goodbye')")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
_, err = Database.Query("INSERT INTO prefixes (prefix) VALUES ('Go.'), ('go.'), ('go,')")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
_, err = Database.Query("INSERT INTO x_users_guilds (guild_id, user_id) VALUES " +
|
||||||
|
"(265828729970753537, 351794468870946827)," +
|
||||||
|
"(265828729970753537, 692908139506434065)," +
|
||||||
|
"(265828729970753537, 396588996706304010)")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
_, err = Database.Query("INSERT INTO x_guilds_prefixes (guild_id, prefix_id) VALUES " +
|
||||||
|
"(265828729970753537, 1)," +
|
||||||
|
"(265828729970753537, 2)," +
|
||||||
|
"(265828729970753537, 3)")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
_, err = Database.Query("INSERT INTO tags (tag, content, creator, guild_id) VALUES " +
|
||||||
|
"('test', 'This is a test of the tag system', 351794468870946827, 265828729970753537)")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -18,7 +18,7 @@ services:
|
|||||||
depends_on:
|
depends_on:
|
||||||
- goff-db
|
- goff-db
|
||||||
environment:
|
environment:
|
||||||
- DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}
|
- DATABASE_URL=postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}?sslmode=disable
|
||||||
links:
|
links:
|
||||||
- goff-db:goff.db
|
- goff-db:goff.db
|
||||||
|
|
||||||
|
|||||||
3
go.mod
3
go.mod
@ -5,4 +5,7 @@ go 1.14
|
|||||||
require (
|
require (
|
||||||
github.com/MikeModder/anpan v0.0.0-20190831213521-34b01a6cec0a
|
github.com/MikeModder/anpan v0.0.0-20190831213521-34b01a6cec0a
|
||||||
github.com/bwmarrin/discordgo v0.20.2
|
github.com/bwmarrin/discordgo v0.20.2
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407073246-017a13d2f100
|
||||||
|
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
|
||||||
|
github.com/lib/pq v1.3.0
|
||||||
)
|
)
|
||||||
|
|||||||
48
go.sum
48
go.sum
@ -3,7 +3,55 @@ github.com/MikeModder/anpan v0.0.0-20190831213521-34b01a6cec0a/go.mod h1:jTKPbf4
|
|||||||
github.com/bwmarrin/discordgo v0.19.0/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q=
|
github.com/bwmarrin/discordgo v0.19.0/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q=
|
||||||
github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20=
|
github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20=
|
||||||
github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q=
|
github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200406015308-c28f5942098e h1:Cud22nvHaHIIbxFJB30SJU40TRmRUz+lnyQTPlwYuEY=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200406015308-c28f5942098e/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200406030359-7057f2019b27 h1:YZQZTn6nZ/Wx9aSITYp5Q+U4B/bWd3yoAcoXIEpYXwc=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200406030359-7057f2019b27/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200406032705-2668bb8cf59a h1:ze1sxGaOGtgN38ZBo9QN6ofblhcQ6IwKkalZfLmOoRw=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200406032705-2668bb8cf59a/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200406033206-5160db811495 h1:jDaoNl1IOgbJqdiEKLyUyZ43ltvHJVcA2FKA6AotKOo=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200406033206-5160db811495/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407055106-ecbe2e958fae h1:QLZN50c1NZRlTb6/anzsbE0EQmKyw6lC/Yst3ULnHRg=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407055106-ecbe2e958fae/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407055401-5bb2c4a0ba95 h1:39jJNE+n5tcqf+22NgpGPrwALStT32p/C3LGT47ABqE=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407055401-5bb2c4a0ba95/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407055648-0f8e3058d525 h1:qEaVihOa38TRnNJNOnlPr2H6pppu1pxocFEguia1wiY=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407055648-0f8e3058d525/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407060739-ad28895b43d2 h1:cMOXryJnVe503twxiAyaYGEP4N17Y12aJt51va/KdZY=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407060739-ad28895b43d2/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407060953-d7da539153b4 h1:sXlPb9fP5H6ID41n81Lx3YruAkvRrw7a7/Wo5yGVGSk=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407060953-d7da539153b4/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407064546-2ee91528e807 h1:XRD/g7evUVpYwzD1BvfWUTCMPeSOpP1vK+DRPWXBbL0=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407064546-2ee91528e807/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407064911-9febf5ddd547 h1:u89NoPsVMYUpoMdlmQi0hfAHine/BySTIrjd6T1sWtU=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407064911-9febf5ddd547/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407065137-0e81c7e6a1b1 h1:qwfuMmgHSq7COUTH/zY1E9qB/WCKFXq4H9o83qdLIZY=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407065137-0e81c7e6a1b1/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407065639-48f8ee997f8e h1:DsW5nPC7KZBn1OeWbGN4b4Mhjfq1otpFCs+AlnLcnOw=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407065639-48f8ee997f8e/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407065901-ca3fe5bd6961 h1:elaeIybXmc4chT26RkP3lXwlBV4yEvzLUjbnecb1+Ks=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407065901-ca3fe5bd6961/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407070232-0f51576a3509 h1:iajsyEA4RN5rQkyA7dMb/tjAuDfOE8pQWvL7BlWOogs=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407070232-0f51576a3509/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407070618-70034903f0b4 h1:XI1CCq5CCydSgYCdbIgrm+EGxBOs/TiqgTWBBTwqcoA=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407070618-70034903f0b4/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407070839-97678e757cbb h1:36S9x0MED3OQ0aWA7+XQ6yZAc+7XNWCDgGKKdevgyzI=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407070839-97678e757cbb/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407071612-ebd0d77d3229 h1:FWt+RrclGz3NOO02N6UmjkDGh6FLD6kXIPk+naBOask=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407071612-ebd0d77d3229/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407071848-54e2a741c063 h1:IElz2z+bL0At5IERllxEay7LMHKTBt74VrnweG4iCts=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407071848-54e2a741c063/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407072206-a0a6b9b54d7e h1:vmNnRwhpB4vbjDGVcZwn9Tac+tvjDZYbwWNmHB3Jcmw=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407072206-a0a6b9b54d7e/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407072955-f98b62e6fb49 h1:KLZCNt6d4RY3y83YeEHc89KE96+Zhi02qkiZpM2WbOY=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407072955-f98b62e6fb49/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407073246-017a13d2f100 h1:yKyt6EakVkopZRdOYXa5AOQVRl2QgRRDaTPZerpgoCI=
|
||||||
|
github.com/dustinpianalto/disgoman v0.0.0-20200407073246-017a13d2f100/go.mod h1:v3FM6n+4dH9XlvO+IDx6MN3DUnGq6YVDBvy1A1k202g=
|
||||||
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
|
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
|
||||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||||
|
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
|
||||||
|
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
|
||||||
|
github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU=
|
||||||
|
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||||
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA=
|
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA=
|
||||||
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user