mirror of
https://github.com/mgerb/go-discord-bot
synced 2026-01-11 09:32:50 +00:00
use permissions from database - updated bot-scripts
This commit is contained in:
27
server/scripts/main.go
Normal file
27
server/scripts/main.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
if len(os.Args) == 1 {
|
||||
fmt.Print("Error - Invalid Args\n\nPossible Args:\nrestore-message\nupdate-db\n\n")
|
||||
return
|
||||
}
|
||||
|
||||
arg := os.Args[1]
|
||||
|
||||
switch arg {
|
||||
case "update-db":
|
||||
updateDB()
|
||||
case "restore-messages":
|
||||
if len(os.Args) < 3 {
|
||||
fmt.Println("Please provide a channel id")
|
||||
return
|
||||
}
|
||||
restoreMessages(os.Args[2])
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,9 @@
|
||||
package main
|
||||
|
||||
/**
|
||||
This script will fetch all messages for the provided channel and store them in the database.
|
||||
*/
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
@@ -10,13 +14,15 @@ import (
|
||||
"github.com/mgerb/go-discord-bot/server/db"
|
||||
)
|
||||
|
||||
const everyoneChannel = "101198129352691712"
|
||||
// var everyoneChannel = "101198129352691712"
|
||||
var everyoneChannel string
|
||||
|
||||
// this is a script to go through chat history and log old message into database
|
||||
func main() {
|
||||
func restoreMessages(channelID string) {
|
||||
config.Init()
|
||||
db.Init()
|
||||
session := bot.Start(config.Config.Token)
|
||||
everyoneChannel = channelID
|
||||
fetchMessages(session, "")
|
||||
}
|
||||
|
||||
25
server/scripts/update-db.go
Normal file
25
server/scripts/update-db.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mgerb/go-discord-bot/server/db"
|
||||
)
|
||||
|
||||
// keep change script embedded in go files for ease of use
|
||||
const changeScript = `
|
||||
|
||||
-- script to update all users default permission to a value of 1 (user)
|
||||
|
||||
UPDATE users SET permissions = 1 WHERE permissions IS NULL OR permissions = 0;
|
||||
|
||||
`
|
||||
|
||||
func updateDB() {
|
||||
db.Init()
|
||||
conn := db.GetConn()
|
||||
err := conn.Exec(changeScript).Error
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user