New simple bootstrap layout and audio files readme

minor tweak to check files for ".dca" substring first.
This commit is contained in:
Daniel Aberger 2017-01-18 23:44:32 +01:00
parent 3ebdb69945
commit a1c79296a9
7 changed files with 79 additions and 28 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
run.bat
run.sh
audio/*.dca

3
audio/readme.txt Normal file
View File

@ -0,0 +1,3 @@
Place .dca audio files here.
Naming convention is as follows: command_soundname.dca
This will result in "!command soundname".

38
main.go
View File

@ -82,28 +82,30 @@ var COLLECTIONS []*SoundCollection
func createCollections() {
files, _ := ioutil.ReadDir("./audio")
for _, f := range files {
soundfile := strings.Split(strings.Replace(f.Name(), ".dca", "", -1), "_")
containsPrefix := false
containsSound := false
if strings.Contains(f.Name(), ".dca") {
soundfile := strings.Split(strings.Replace(f.Name(), ".dca", "", -1), "_")
containsPrefix := false
containsSound := false
if len(COLLECTIONS) == 0 {
addNewSoundCollection(soundfile[0], soundfile[1])
}
for _, c := range COLLECTIONS {
if c.Prefix == soundfile[0] {
containsPrefix = true
for _, sound := range c.Sounds {
if sound.Name == soundfile[1] {
containsSound = true
if len(COLLECTIONS) == 0 {
addNewSoundCollection(soundfile[0], soundfile[1])
}
for _, c := range COLLECTIONS {
if c.Prefix == soundfile[0] {
containsPrefix = true
for _, sound := range c.Sounds {
if sound.Name == soundfile[1] {
containsSound = true
}
}
if !containsSound {
c.Sounds = append(c.Sounds, createSound(soundfile[1], 1, 250))
}
}
if !containsSound {
c.Sounds = append(c.Sounds, createSound(soundfile[1], 1, 250))
}
}
}
if !containsPrefix {
addNewSoundCollection(soundfile[0], soundfile[1])
if !containsPrefix {
addNewSoundCollection(soundfile[0], soundfile[1])
}
}
}
}

View File

@ -1,4 +1,3 @@
{{ define "title"}}<title>Example</title>{{ end }}
{{ define "content" }}
<a href="/discordLogin">Login with Discord</a>
{{ end }}

3
templates/internal.html Normal file
View File

@ -0,0 +1,3 @@
{{ define "content" }}
<a href="/logout">Logout</a>
{{ end }}

View File

@ -1,17 +1,59 @@
{{ define "base" }}
<html>
<head>
<link rel="stylesheet" href="/static/css/style.css">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,600,700' rel='stylesheet' type='text/css'>
{{template "title" . }}
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<style>
body {
padding-top: 50px;
}
</style>
<title>Gidbig</title>
</head>
<body>
<header>
<h1>Example</h1>
</header>
<div id="page">
{{ template "content" . }}
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Gidbig</a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</nav>
<div class="container">
<div class="starter-template">
<h1>Gidbig</h1>
<p class="lead">{{ template "content" . }}</p>
</div>
</div>
<!-- /.container -->
</body>
</html>
{{ end }}

View File

@ -40,6 +40,7 @@ var (
// startWebServer
func startWebServer(port string, ci string, cs string, redirectURL string) {
tmpls["home.html"] = template.Must(template.ParseFiles(templateDir+"home.html", defaultLayout))
tmpls["internal.html"] = template.Must(template.ParseFiles(templateDir+"internal.html", defaultLayout))
store = sessions.NewCookieStore([]byte(cs))
discordOauthConfig.ClientID = ci
discordOauthConfig.ClientSecret = cs
@ -59,7 +60,7 @@ func startWebServer(port string, ci string, cs string, redirectURL string) {
func handleMain(w http.ResponseWriter, r *http.Request) {
session, _ := store.Get(r, "session-name")
if session.Values["discordUsername"] != nil {
fmt.Fprintf(w, "<html><body>you are logged in as %s. <a href=\"/logout\">logout</a></body></html>", session.Values["discordUsername"])
tmpls["internal.html"].ExecuteTemplate(w, "base", map[string]interface{}{})
return
}
tmpls["home.html"].ExecuteTemplate(w, "base", map[string]interface{}{})