mirror of
https://github.com/idanoo/go-pager-discord
synced 2025-07-01 05:42:19 +00:00
progress
This commit is contained in:
parent
64c5003fad
commit
64199c37f5
4 changed files with 108 additions and 2 deletions
9
go.mod
9
go.mod
|
@ -3,3 +3,12 @@ module go-pager-discord
|
|||
go 1.20
|
||||
|
||||
require github.com/joho/godotenv v1.5.1
|
||||
|
||||
require (
|
||||
github.com/disgoorg/disgo v0.15.0 // indirect
|
||||
github.com/disgoorg/json v1.0.0 // indirect
|
||||
github.com/disgoorg/log v1.2.0 // indirect
|
||||
github.com/disgoorg/snowflake/v2 v2.0.1 // indirect
|
||||
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b // indirect
|
||||
golang.org/x/exp v0.0.0-20220325121720-054d8573a5d8 // indirect
|
||||
)
|
||||
|
|
12
go.sum
12
go.sum
|
@ -1,2 +1,14 @@
|
|||
github.com/disgoorg/disgo v0.15.0 h1:OTYlhyQ/frPtqY9dGRSaBpo7GJtTQj+8dah2ml+LPHM=
|
||||
github.com/disgoorg/disgo v0.15.0/go.mod h1:j7MCI6foUipYNozxwttr2hcaEQa3gNEbcwgLnyLUf6E=
|
||||
github.com/disgoorg/json v1.0.0 h1:kDhSM661fgIuNoZF3BO5/odaR5NSq80AWb937DH+Pdo=
|
||||
github.com/disgoorg/json v1.0.0/go.mod h1:BHDwdde0rpQFDVsRLKhma6Y7fTbQKub/zdGO5O9NqqA=
|
||||
github.com/disgoorg/log v1.2.0 h1:sqlXnu/ZKAlIlHV9IO+dbMto7/hCQ474vlIdMWk8QKo=
|
||||
github.com/disgoorg/log v1.2.0/go.mod h1:3x1KDG6DI1CE2pDwi3qlwT3wlXpeHW/5rVay+1qDqOo=
|
||||
github.com/disgoorg/snowflake/v2 v2.0.1 h1:CuUxGLwggUxEswZOmZ+mZ5i0xSumQdXW9tXW7uGqe+0=
|
||||
github.com/disgoorg/snowflake/v2 v2.0.1/go.mod h1:SPU9c2CNn5DSyb86QcKtdZgix9osEtKrHLW4rMhfLCs=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b h1:qYTY2tN72LhgDj2rtWG+LI6TXFl2ygFQQ4YezfVaGQE=
|
||||
github.com/sasha-s/go-csync v0.0.0-20210812194225-61421b77c44b/go.mod h1:/pA7k3zsXKdjjAiUhB5CjuKib9KJGCaLvZwtxGC8U0s=
|
||||
golang.org/x/exp v0.0.0-20220325121720-054d8573a5d8 h1:Xt4/LzbTwfocTk9ZLEu4onjeFucl88iW+v4j4PWbQuE=
|
||||
golang.org/x/exp v0.0.0-20220325121720-054d8573a5d8/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
|
||||
|
|
89
main.go
89
main.go
|
@ -1,10 +1,18 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/disgoorg/disgo/discord"
|
||||
"github.com/disgoorg/disgo/webhook"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
|
@ -14,6 +22,9 @@ var (
|
|||
RTL_DEVICE_ID string
|
||||
RTL_GAIN string
|
||||
|
||||
discordClient webhook.Client
|
||||
socketFile = "/var/run/pager.sock"
|
||||
|
||||
// Emojies to replace
|
||||
emojis = map[string][]string{
|
||||
":house:": []string{"house", "roof"},
|
||||
|
@ -71,17 +82,91 @@ func init() {
|
|||
func main() {
|
||||
log.Println("Booting go-pager-discord")
|
||||
|
||||
// Load discord client
|
||||
client, err := webhook.NewWithURL(DISCORD_WEBHOOK)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
discordClient = client
|
||||
|
||||
// Start running rtl_fm + multimon
|
||||
deviceID := ""
|
||||
if RTL_DEVICE_ID != "" {
|
||||
deviceID = fmt.Sprintf("-d %s", RTL_DEVICE_ID)
|
||||
}
|
||||
|
||||
// If the socket doesn't exist.. run command!
|
||||
if _, err := os.Stat(socketFile); !errors.Is(err, os.ErrNotExist) {
|
||||
|
||||
}
|
||||
|
||||
// Build command
|
||||
_ = fmt.Sprintf(
|
||||
"rtl_fm -M fm -d %s -f %sM -g %s -s 22050 -- | multimon-ng -t raw -a POCSAG512 -a POCSAG1200 -a FLEX -a POCSAG2400 /dev/stdin",
|
||||
script := fmt.Sprintf(
|
||||
"rtl_fm -M fm -d %s -f %sM -g %s -s 22050 -- | multimon-ng -t raw -a POCSAG512 -a POCSAG1200 -a FLEX -a POCSAG2400 /var/run/pager.sock",
|
||||
deviceID,
|
||||
RTL_FREQ,
|
||||
RTL_GAIN,
|
||||
)
|
||||
cmd := exec.Command(script)
|
||||
cmd.Stdout = os.Stdout
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Wait for it to load
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
// Create a Unix domain socket and listen for incoming connections.
|
||||
socket, err := net.Listen("unix", "/tmp/echo.sock")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Cleanup the sockfile.
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-c
|
||||
os.Remove("/tmp/echo.sock")
|
||||
os.Exit(1)
|
||||
}()
|
||||
|
||||
for {
|
||||
// Accept an incoming connection.
|
||||
conn, err := socket.Accept()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Handle the connection in a separate goroutine.
|
||||
go func(conn net.Conn) {
|
||||
defer conn.Close()
|
||||
// Create a buffer for incoming data.
|
||||
buf := make([]byte, 4096)
|
||||
|
||||
// Read data from the connection.
|
||||
n, err := conn.Read(buf)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Echo the data back to the connection.
|
||||
_, err = conn.Write(buf[:n])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}(conn)
|
||||
}
|
||||
}
|
||||
|
||||
func sendMessage(msg string) {
|
||||
// Send to discord!
|
||||
_, err := discordClient.CreateMessage(discord.WebhookMessageCreate{
|
||||
Content: msg,
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
}
|
||||
}
|
||||
|
|
0
pager.service
Normal file
0
pager.service
Normal file
Loading…
Add table
Add a link
Reference in a new issue