Skip to content

Commit

Permalink
cmd: migrate aura
Browse files Browse the repository at this point in the history
Signed-off-by: Xe Iaso <[email protected]>
  • Loading branch information
Xe committed Sep 7, 2024
1 parent 65c9fe6 commit 6ff7314
Show file tree
Hide file tree
Showing 18 changed files with 666 additions and 285 deletions.
16 changes: 16 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ aerial:

SAVE IMAGE --push ghcr.io/xe/x/aerial:latest

aura:
FROM +runtime

RUN apt-get update && apt-get install -y \
streamripper vim jq \
&& rm -rf /var/lib/apt/lists/*

COPY +everything/bin/aura /app/bin/aura
CMD ["/app/bin/aura"]

LABEL org.opencontainers.image.source="https://github.com/Xe/x"

SAVE IMAGE --push ghcr.io/xe/x/aura:latest

future-sight:
FROM +runtime

Expand Down Expand Up @@ -205,6 +219,8 @@ xedn:
SAVE IMAGE --push registry.fly.io/xedn:latest

all:
BUILD --platform=linux/amd64 +aerial
BUILD --platform=linux/amd64 +aura
BUILD --platform=linux/amd64 +azurda
BUILD --platform=linux/amd64 +future-sight
BUILD --platform=linux/amd64 +hdrwtch
Expand Down
87 changes: 0 additions & 87 deletions cmd/aerial/derpi/derpi.go

This file was deleted.

50 changes: 0 additions & 50 deletions cmd/aerial/hipster.go

This file was deleted.

11 changes: 0 additions & 11 deletions cmd/aerial/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ type aerial struct {
s *discordgo.Session
}

const (
djonHelp = ``
djoffHelp = ``
setupHelp = ``
)

func (a *aerial) Handle(s *discordgo.Session, m *discordgo.MessageCreate) {
err := a.cs.Run(s, m.Message)
if err != nil {
Expand All @@ -35,8 +29,6 @@ func (a *aerial) Handle(s *discordgo.Session, m *discordgo.MessageCreate) {
var (
token = os.Getenv("TOKEN")
youtubeSpamRoomID = os.Getenv("DISCORD_YOUTUBESPAM_ROOMID")
gClientID = os.Getenv("GOOGLE_CLIENT_ID")
gClientSecret = os.Getenv("GOOGLE_CLIENT_SECRET")

musicLinkRegex = regexp.MustCompile(`(.*)((http(s?):\/\/(www\.)?soundcloud.com\/.*)|(http(s?):\/\/(www\.)?youtube.com\/.*)|(http(s?):\/\/(www\.)?youtu.be\/.*))(.*)|(.*)http(s?):\/\/(www\.)?mixcloud.com\/.*`)
)
Expand All @@ -58,13 +50,10 @@ func main() {
a.cs.AddCmd("stats", "shows radio station statistics for Ponyville FM", bot.NoPermissions, stats)
a.cs.AddCmd("dj", "shows which DJ is up next on Ponyville FM", bot.NoPermissions, stats)
a.cs.AddCmd("schedule", "shows the future radio schedule for Ponyville FM", bot.NoPermissions, schedule)
a.cs.AddCmd("hipster", "hip me up fam", bot.NoPermissions, hipster)
a.cs.AddCmd("source", "source code information", bot.NoPermissions, source.Source)
a.cs.AddCmd("time", "shows the current bot time", bot.NoPermissions, curTime)
a.cs.AddCmd("streams", "shows the different Ponyville FM stream links", bot.NoPermissions, streams)
a.cs.AddCmd("servers", "shows the different Ponyville FM stream links", bot.NoPermissions, streams)
a.cs.AddCmd("derpi", "grabs a random **__safe__** image from Derpibooru with the given search results", bot.NoPermissions, derpi)
a.cs.AddCmd("weather", "how's the weather right now?", bot.NoPermissions, weather)

dg.AddHandler(a.Handle)
dg.AddHandler(pesterLink)
Expand Down
81 changes: 3 additions & 78 deletions cmd/aerial/pvfm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,16 @@ package main
import (
"fmt"
"log"
"math/rand"
"strconv"
"strings"
"time"

"github.com/bwmarrin/discordgo"
derpiSearch "within.website/x/cmd/aerial/derpi"
"within.website/x/internal/pvfm"
pvfmschedule "within.website/x/internal/pvfm/schedule"
"within.website/x/internal/pvfm/station"
)

func init() {
rand.Seed(time.Now().Unix())
}

// randomRange gives a random whole integer between the given integers [min, max)
func randomRange(min, max int) int {
return rand.Intn(max-min) + min
}

func pesterLink(s *discordgo.Session, m *discordgo.MessageCreate) {
if musicLinkRegex.Match([]byte(m.Content)) {
i, err := pvfm.GetStats()
Expand Down Expand Up @@ -169,6 +158,8 @@ PonyvilleFM Europe OGG Stream:
http://dj.bronyradio.com:8000/pvfm1.ogg
PonyvilleFM Europe Stream:
http://dj.bronyradio.com:8000/stream.mp3
PonyvilleFM 2 Stream:
http://luna.ponyvillefm.com/listen/pvfm2/radio.mp3
PonyvilleFM Free MP3 24/7 Pony Stream:
http://dj.bronyradio.com:8000/pvfmfree.mp3
PonyvilleFM Free OGG 24/7 Pony Stream:
Expand All @@ -185,76 +176,10 @@ func streams(s *discordgo.Session, m *discordgo.Message, parv []string) error {
// PVFM
outputEmbed.AddField(":musical_note: PVFM Servers", pvfmList)
// Luna Radio
outputEmbed.AddField(":musical_note: Luna Radio Servers", "Luna Radio MP3 128Kbps Stream:\n<http://radio.ponyvillelive.com:8002/stream.mp3>\nLuna Radio Mobile MP3 64Kbps Stream:\n<http://radio.ponyvillelive.com:8002/mobile?;stream.mp3>\n")
outputEmbed.AddField(":musical_note: Luna Radio Servers", "Luna Radio MP3 128Kbps Stream:\n<http://luna.ponyvillefm.com/listen/lunaradio/radio.mp3>\n")
// Recordings
outputEmbed.AddField(":cd: DJ Recordings", "Archive\n<https://pvfm.within.lgbt/var/93252527679639552/>\nLegacy Archive\n<https://pvfm.within.lgbt/BronyRadio/>")

s.ChannelMessageSendEmbed(m.ChannelID, outputEmbed.MessageEmbed)

// no errors yay!!!!
return nil
}

func derpi(s *discordgo.Session, m *discordgo.Message, parv []string) error {
if m.ChannelID == "292755043684450304" {

searchResults, err := derpiSearch.SearchDerpi(m.Content[7:len(m.Content)]) // Safe tag will be added in derpi/derpi.go
if err != nil {
s.ChannelMessageSend(m.ChannelID, "An error occured.")
return err
}
if len(searchResults.Search) < 1 {
s.ChannelMessageSend(m.ChannelID, "Error: No results")
return nil
}
derpiImage := searchResults.Search[randomRange(0, len(searchResults.Search))]

tags := strings.Split(derpiImage.Tags, ", ") // because this isn't an array for some reason

// Check for artist tag
artist := ""
for _, tag := range tags {
if strings.Contains(tag, "artist:") {
artist = tag[7:]
}
}

outputEmbed := NewEmbed().
SetTitle("Derpibooru Image").
SetURL("https://derpibooru.org/" + derpiImage.ID).
SetDescription(derpiImage.Description).
SetImage("http:" + derpiImage.Image).
SetFooter("Image score: " + strconv.Itoa(derpiImage.Score) + " | Uploaded: " + derpiImage.CreatedAt.String())

// Credit the artist!
if artist == "" {
outputEmbed.SetAuthor("No artist")
} else {
outputEmbed.SetAuthor("Artist: " + artist)
}

s.ChannelMessageSendEmbed(m.ChannelID, outputEmbed.MessageEmbed)
} else {
s.ChannelMessageSend(m.ChannelID, "Please use this command in <#292755043684450304> only.")
}
return nil
}

func weather(s *discordgo.Session, m *discordgo.Message, parv []string) error {
responses := []string{
"Cloudy with a chance of meatballs.",
"It's currently pouring down even more than Pinkie.",
"It's the most overcast I've ever seen. In other words, same as always.",
"Do you have a better conversation starter than that?",
"There's at least 5 or 6 weather right now, my dude.",
"It's soggy enough for Rainbow Dash to get fired, if she didn't have a literal deity keeping her in charge.",
"Surprisingly, the weather is pretty alright.",
"You'd be happy to know that it's hot enough to make a phoenix sweat.",
"The weather right now is like you took London and stuck it in a dishwasher.",
"The Crystal Empire is warmer than this weather.",
}

s.ChannelMessageSend(m.ChannelID, responses[randomRange(0, len(responses))])

return nil
}
15 changes: 15 additions & 0 deletions cmd/aura/aura.templ
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

templ index() {
<p><img src="/static/aura.webp"/></p>
<h2>Archive</h2>
<ul>
<li><a href="/sleepypony/">Early DJ Sleepypony sets</a></li>
<li><a href="/BronyRadio/">Early BronyRadio sets</a></li>
<li><a href="/var/93252527679639552/">Current PonyvilleFM sets</a></li>
</ul>
}

templ notFound() {
<p>The URL you requested could not be found. Please check your URL and hang up to try your call again.</p>
}
Binary file added cmd/aura/aura.webp
Binary file not shown.
Loading

0 comments on commit 6ff7314

Please sign in to comment.