Skip to content
Snippets Groups Projects
Commit 52590ad1 authored by Reviath's avatar Reviath
Browse files

You are now able to set auto role from web-panel.

parent a03d85e6
No related branches found
No related tags found
No related merge requests found
Pipeline #703 passed
......@@ -15,6 +15,9 @@
{{if eq .settings.RoleID "nil"}}
<a> Set auto role </a>
{{range .guild.Roles}}
<a href="/api/autorole/{{$guild.ID}}/{{.ID}}"> {{.Name}}</a>
{{end}}
{{else}}
<a> Autorole: {{.settings.RoleID}} </a>
<br>
......
......@@ -281,6 +281,65 @@ func Listen(session *discordgo.Session) {
}
})
server.GET("/api/autorole/:guildid/:roleid", func(c *gin.Context) {
val, _ := c.Cookie("key")
switch val {
case "":
c.Redirect(http.StatusTemporaryRedirect, "/login")
default:
guild, err := session.State.Guild(c.Param("guildid"))
if err != nil {
c.HTML(200, "error.html", gin.H{
"is404": "false",
"description": "Cannot find guild " + "\"" + c.Param("guildid") + "\"",
"error": "Invalid snowflake.",
})
} else {
var token = &oauth2.Token{}
jsoniter.UnmarshalFromString(fmt.Sprint(val), token)
res, err := conf.Client(context.TODO(), token).Get("https://discordapp.com/api/v8/users/@me")
if err != nil || res.StatusCode != 200 {
fmt.Println("An error occurred on api: " + err.Error())
return
}
var user discordgo.User
data, _ := ioutil.ReadAll(res.Body)
err = json.Unmarshal(data, &user)
if err != nil {
c.Redirect(http.StatusTemporaryRedirect, "/")
}
if !multiplexer.CheckAdministratorPermission(session, user.ID, guild.ID) {
c.HTML(200, "error.html", gin.H{
"is404": "false",
"description": "You don't have enough permission to access here!",
"error": "Unauthorized",
})
return
}
role, err := session.State.Role(guild.ID, c.Param("roleid"))
if err != nil {
c.HTML(200, "error.html", gin.H{
"is404": "false",
"description": "Cannot find role \"" + c.Param("roleid") + "\" on specified guild.",
"error": "Invalid role",
})
return
}
db := sql.Connect()
defer db.Close()
insert, _ := db.Query(fmt.Sprintf("INSERT INTO autorole (roleid, guildid) VALUES ('%s', '%s')", role.ID, guild.ID))
defer insert.Close()
c.Redirect(http.StatusTemporaryRedirect, "/guild/"+c.Param("guildid"))
}
}
})
server.GET("/resetlog/:guildid", func(c *gin.Context) {
val, _ := c.Cookie("key")
switch val {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment