Skip to content

Commit

Permalink
Cleanup code based on review, update LICENSE and README
Browse files Browse the repository at this point in the history
  • Loading branch information
b1naryth1ef committed Mar 19, 2016
1 parent b457bd4 commit 4530792
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2016 Hammer and Chisel

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
# Airhorn
Airhorn is an example bot implementing the [Discord API](https://discordapp.com/TODO).
# Airhorn Bot
Airhorn is an example implementation of the [Discord API](https://discordapp.com/developers/docs/intro"). Airhorn bot utilizes the [discordgo](https://github.com/bwmarrin/discordgo) library, a free and open source library.

## Usage
Airhorn Bot has too components, a bot client that handles the playing of loyal airhorns, and a web server that implements OAuth2 and stats. Once added to your server, airhorn bot can be summoned by running `!airhorn`.

### Building / Running
Airhorn bot can be compiled with the provided Makefile by simply running `make`. This produces two binaries, `airhornbot` and `airhornweb`. Airhorn bot requires a local redis-server to track statistics.

### Running the Bot
Run the bot like so:

```
./airhornbot -r "localhost:6379" -t "MY_BOT_ACCOUNT_TOKEN"
```

### Running the Web Server
Run the web server like so:

```
./airhornweb -r "localhost:6379" -i MY_APPLICATION_ID -s 'MY_APPLICATION_SECRET"
```

## Thanks
Thanks to the awesome (one might describe them as smart... loyal... appreciative...) [iopred](https://github.com/iopred) and [bwmarrin](https://github.com/bwmarrin/discordgo) for helping code review the initial release.
17 changes: 11 additions & 6 deletions bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"fmt"
"io"
"math/rand"
"os"
"os/exec"
"os/signal"
"strings"
"time"

Expand Down Expand Up @@ -196,7 +198,7 @@ func (s *Sound) Play(vc *discordgo.VoiceConnection) {
func getCurrentVoiceChannel(user *discordgo.User, guild *discordgo.Guild) *discordgo.Channel {
for _, vs := range guild.VoiceStates {
if vs.UserID == user.ID {
channel, _ := discord.Channel(vs.ChannelID)
channel, _ := discord.State.Channel(vs.ChannelID)
return channel
}
}
Expand Down Expand Up @@ -392,7 +394,7 @@ func onMessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
)

if parts[0] == "!airhorn" || parts[0] == "!anotha" || parts[0] == "!anoathaone" {
channel, _ := discord.Channel(m.ChannelID)
channel, _ := discord.State.Channel(m.ChannelID)
if channel == nil {
log.WithFields(log.Fields{
"channel": m.ChannelID,
Expand All @@ -401,7 +403,7 @@ func onMessageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
return
}

guild, _ := discord.Guild(channel.GuildID)
guild, _ := discord.State.Guild(channel.GuildID)
if guild == nil {
log.WithFields(log.Fields{
"guild": channel.GuildID,
Expand Down Expand Up @@ -484,8 +486,11 @@ func main() {
return
}

// We're running!
log.Info("AIRHORNBOT is ready to horn it up.")
for {
time.Sleep(time.Second * 1)
}

// Wait for a signal to quit
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, os.Kill)
<-c
}
7 changes: 7 additions & 0 deletions web.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@ func server() {
"port": port,
}).Info("Starting HTTP Server")

// If the requests log doesnt exist, make it
if _, err := os.Stat("requests.log"); os.IsNotExist(err) {
ioutil.WriteFile("requests.log", []byte{}, 0600)
}

// Open the log file in append mode
logFile, err := os.OpenFile("requests.log", os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
log.WithFields(log.Fields{
Expand All @@ -289,6 +295,7 @@ func server() {
}
defer logFile.Close()

// Actually start the server
loggedRouter := handlers.LoggingHandler(logFile, server)
http.ListenAndServe(":"+port, loggedRouter)
}
Expand Down

0 comments on commit 4530792

Please sign in to comment.