Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Remilia Scarlet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Reviath
Remilia Scarlet
Commits
a03d85e6
Commit
a03d85e6
authored
May 20, 2021
by
Reviath
Browse files
Options
Downloads
Patches
Plain Diff
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
May 20, 2021
Stage: build
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
web/public/guild.html
+11
-1
11 additions, 1 deletion
web/public/guild.html
web/web.go
+195
-0
195 additions, 0 deletions
web/web.go
with
206 additions
and
1 deletion
web/public/guild.html
+
11
−
1
View file @
a03d85e6
...
...
@@ -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>
...
...
This diff is collapsed.
Click to expand it.
web/web.go
+
195
−
0
View file @
a03d85e6
...
...
@@ -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
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment