parent
9e33d58a14
commit
be81d2280a
@ -0,0 +1,7 @@
|
|||||||
|
package events
|
||||||
|
|
||||||
|
import "github.com/bwmarrin/discordgo"
|
||||||
|
|
||||||
|
func OnMemberAdd(s *discordgo.Session, event *discordgo.GuildMemberAdd) {
|
||||||
|
|
||||||
|
}
|
||||||
@ -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
|
||||||
|
}
|
||||||
@ -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
|
||||||
|
}
|
||||||
@ -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
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in new issue