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

You can set welcome channel, leave channel, log channel from web-panel.

parent efd59acc
No related branches found
No related tags found
No related merge requests found
Pipeline #701 passed
......@@ -10,6 +10,7 @@
</head>
<body class="bg-dark text-light">
<section align="center">
{{$guild := .guild}}
<h1>{{.guild.Name}} Settings </h1>
{{if eq .settings.RoleID "nil"}}
......@@ -21,7 +22,10 @@
{{end}}
<br> <br>
{{if eq .settings.LogID "nil"}}
<a> Set log channel </a>
<a> Set log channel: </a>
{{range .guild.Channels}}
<a href="/api/log/{{$guild.ID}}/{{.ID}}">{{.Name}}</a>
{{end}}
{{else}}
<a> Log channel id: {{.settings.LogID}} </a>
<br>
......@@ -38,6 +42,9 @@
<br> <br>
{{if eq .settings.LeaveChannelID "nil"}}
<a> Set leave channel </a>
{{range .guild.Channels}}
<a href="/api/leavechannel/{{$guild.ID}}/{{.ID}}">{{.Name}}</a>
{{end}}
{{else}}
<a> Leave channel id: {{.settings.LeaveChannelID}} </a>
<br>
......@@ -54,6 +61,9 @@
<br> <br>
{{if eq .settings.WelcomeChannelID "nil"}}
<a> Set welcome channel </a>
{{range .guild.Channels}}
<a href="/api/welcomechannel/{{$guild.ID}}/{{.ID}}">{{.Name}}</a>
{{end}}
{{else}}
<a> Welcome channel id: {{.settings.WelcomeChannelID}} </a>
<br>
......
......@@ -86,6 +86,201 @@ func Listen(session *discordgo.Session) {
c.Redirect(http.StatusTemporaryRedirect, "https://discord.gg/zVVWWDtSr2")
})
server.GET("/api/log/:guildid/:newchannel", 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
}
channel, err := session.State.Channel(c.Param("newchannel"))
if err != nil {
c.HTML(200, "error.html", gin.H{
"is404": "false",
"description": "Cannot find channel \"" + c.Param("newchannel") + "\"",
"error": "Invalid channel",
})
return
}
if channel.GuildID == guild.ID {
db := sql.Connect()
defer db.Close()
insert, _ := db.Query(fmt.Sprintf("INSERT INTO log (channelid, guildid) VALUES ('%s', '%s')", channel.ID, guild.ID))
defer insert.Close()
} else {
c.HTML(200, "error.html", gin.H{
"is404": "false",
"description": "This channel is not in this guild.",
"error": "Invalid channel",
})
return
}
c.Redirect(http.StatusTemporaryRedirect, "/guild/"+c.Param("guildid"))
}
}
})
server.GET("/api/leavechannel/:guildid/:newchannel", 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
}
channel, err := session.State.Channel(c.Param("newchannel"))
if err != nil {
c.HTML(200, "error.html", gin.H{
"is404": "false",
"description": "Cannot find channel \"" + c.Param("newchannel") + "\"",
"error": "Invalid channel",
})
return
}
if channel.GuildID == guild.ID {
db := sql.Connect()
defer db.Close()
insert, _ := db.Query(fmt.Sprintf("INSERT INTO leavechannel (channelid, guildid) VALUES ('%s', '%s')", channel.ID, guild.ID))
defer insert.Close()
} else {
c.HTML(200, "error.html", gin.H{
"is404": "false",
"description": "This channel is not in this guild.",
"error": "Invalid channel",
})
return
}
c.Redirect(http.StatusTemporaryRedirect, "/guild/"+c.Param("guildid"))
}
}
})
server.GET("/api/welcomechannel/:guildid/:newchannel", 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
}
channel, err := session.State.Channel(c.Param("newchannel"))
if err != nil {
c.HTML(200, "error.html", gin.H{
"is404": "false",
"description": "Cannot find channel \"" + c.Param("newchannel") + "\"",
"error": "Invalid channel",
})
return
}
if channel.GuildID == guild.ID {
db := sql.Connect()
defer db.Close()
insert, _ := db.Query(fmt.Sprintf("INSERT INTO welcomechannel (channelid, guildid) VALUES ('%s', '%s')", channel.ID, guild.ID))
defer insert.Close()
} else {
c.HTML(200, "error.html", gin.H{
"is404": "false",
"description": "This channel is not in this guild.",
"error": "Invalid channel",
})
return
}
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