mirror of
https://github.com/valmojr/armatak.git
synced 2026-06-13 15:43:29 +00:00
After 6 straight hours testing a 40 lines code, first working dll that gets any argument from the ping command and send it to a webhook, i hate golang, actually the env variables are not working as this, you have to set it manually for it to work
This commit is contained in:
1
.env.example
Normal file
1
.env.example
Normal file
@@ -0,0 +1 @@
|
||||
DISCORD_WEBHOOK="https://discord.com/api/webhooks/x/y"
|
||||
@@ -1,42 +1,6 @@
|
||||
package main
|
||||
|
||||
type Mission struct {
|
||||
MissionName string `json:"missionName"`
|
||||
Worldname string `json:"worldname"`
|
||||
MissionAuthor string `json:"missionAuthor"`
|
||||
MissionType string `json:"missionType"`
|
||||
Victory string `json:"victory"`
|
||||
MissionStart string `json:"missionStart"`
|
||||
MissionEnd string `json:"missionEnd"`
|
||||
Date string `json:"date"`
|
||||
ScoreBlue string `json:"scoreBlue"`
|
||||
ScoreRed string `json:"scoreRed"`
|
||||
ScoreGreen string `json:"scoreGreen"`
|
||||
Players []Player `json:"players"`
|
||||
Kills []Kill `json:"kills"`
|
||||
FPS []float64 `json:"fps"`
|
||||
}
|
||||
|
||||
type Player struct {
|
||||
UID string `json:"uid"`
|
||||
Name string `json:"name"`
|
||||
Side string `json:"side"`
|
||||
Shots int `json:"shots"`
|
||||
Hits int `json:"hits"`
|
||||
Squad string `json:"squad"`
|
||||
Role string `json:"role"`
|
||||
Class string `json:"class"`
|
||||
}
|
||||
|
||||
type Kill struct {
|
||||
Time string `json:"time"`
|
||||
Victim string `json:"victim"`
|
||||
Killer string `json:"killer"`
|
||||
Weapon string `json:"weapon"`
|
||||
Distance string `json:"distance"`
|
||||
}
|
||||
|
||||
type DiscordPayload struct {
|
||||
type Payload struct {
|
||||
Content string `json:"content"`
|
||||
Username string `json:"username,omitempty"` // Optional field
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
module statsLoggerExtension
|
||||
module armatak
|
||||
|
||||
go 1.20
|
||||
|
||||
require github.com/indig0fox/a3go v0.2.1
|
||||
require github.com/indig0fox/a3go v0.3.2
|
||||
|
||||
require github.com/joho/godotenv v1.5.1
|
||||
|
||||
@@ -1,2 +1,6 @@
|
||||
github.com/indig0fox/a3go v0.2.1 h1:Ixr/182pGd5qPbFYgHINWt5YtyKaO7Yo/va/17nF/Vg=
|
||||
github.com/indig0fox/a3go v0.2.1/go.mod h1:8htVwBiIAVKpT1Jyb+5dm7GuLAAevTXgw7UKxSlOawY=
|
||||
github.com/indig0fox/a3go v0.3.2 h1:bNL90pffeOnS6Qtjoo5JHpdpZn1f0BZmRZR8nz/xcvQ=
|
||||
github.com/indig0fox/a3go v0.3.2/go.mod h1:8htVwBiIAVKpT1Jyb+5dm7GuLAAevTXgw7UKxSlOawY=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
|
||||
@@ -5,75 +5,98 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/indig0fox/a3go/a3interface"
|
||||
"github.com/indig0fox/a3go/assemblyfinder"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
// modulePath is the absolute path to the compiled DLL, which should be the addon folder
|
||||
var modulePath string = assemblyfinder.GetModulePath()
|
||||
|
||||
// modulePathDir is the containing folder
|
||||
var modulePathDir string = path.Dir(modulePath)
|
||||
|
||||
var EXTENSION_NAME = "STATS_LOGGER"
|
||||
var EXTENSION_NAME = "ARMATAK"
|
||||
|
||||
var mission Mission
|
||||
var a3ErrorChannel chan []string = make(chan []string)
|
||||
|
||||
var RVExtensionChannels = map[string]chan string{
|
||||
":timeNow:": make(chan string),
|
||||
func main() {
|
||||
fmt.Scanln()
|
||||
}
|
||||
|
||||
var RVExtensionArgsChannels = map[string]chan []string{
|
||||
":RESET:": make(chan []string),
|
||||
":MISSION:": make(chan []string),
|
||||
":WIN:": make(chan []string),
|
||||
":PLAYER:": make(chan []string),
|
||||
":KILL:": make(chan []string),
|
||||
":SHOT:": make(chan []string),
|
||||
":HIT:": make(chan []string),
|
||||
":EXPORT:": make(chan []string),
|
||||
":FPS:": make(chan []string),
|
||||
}
|
||||
|
||||
var a3ErrorChan = make(chan error)
|
||||
|
||||
func init() {
|
||||
a3interface.SetVersion("1.0.0")
|
||||
a3interface.RegisterRvExtensionArgsChannels(RVExtensionArgsChannels)
|
||||
godotenv.Load(".env")
|
||||
|
||||
webhookURL := "YOUR_WEBHOOK_URL"
|
||||
a3interface.SetVersion("0.0.0")
|
||||
a3interface.RegisterErrorChan(a3ErrorChannel)
|
||||
|
||||
// Create the payload with the message
|
||||
payload := DiscordPayload{
|
||||
Content: "Hello World!",
|
||||
a3interface.NewRegistration("ping").
|
||||
SetDefaultResponse("[Received PING Command, starting background process]").
|
||||
SetRunInBackground(true).
|
||||
SetFunction(PingCommand).
|
||||
SetArgsFunction(PingCommandArgs).
|
||||
Register()
|
||||
}
|
||||
|
||||
func PingCommand(
|
||||
ctx a3interface.ArmaExtensionContext,
|
||||
data string,
|
||||
) (string, error) {
|
||||
dataSlice := strings.Split(data, "|")
|
||||
dataSliceWithoutPrefix := dataSlice[1:]
|
||||
for i, v := range dataSliceWithoutPrefix {
|
||||
dataSliceWithoutPrefix[i] = a3interface.RemoveEscapeQuotes(v)
|
||||
}
|
||||
|
||||
s := fmt.Sprintf(ctx.SteamID + ` called the ping command to use the dll inside ` + ctx.ServerName + modulePathDir)
|
||||
|
||||
pingDiscord(s)
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func PingCommandArgs(
|
||||
ctx a3interface.ArmaExtensionContext,
|
||||
command string,
|
||||
args []string,
|
||||
) (string, error) {
|
||||
for i, v := range args {
|
||||
args[i] = a3interface.RemoveEscapeQuotes(v)
|
||||
}
|
||||
|
||||
pingDiscord(strings.Join(args, " || "))
|
||||
|
||||
return fmt.Sprintf(`["Called by %s", %q, %q]`,
|
||||
ctx.SteamID,
|
||||
command,
|
||||
args,
|
||||
), nil
|
||||
}
|
||||
|
||||
func pingDiscord(content string) {
|
||||
webhookURL := os.Getenv("DISCORD_WEBHOOK")
|
||||
|
||||
payload := Payload{
|
||||
Content: content,
|
||||
Username: "ARMATAK",
|
||||
}
|
||||
|
||||
// Convert the payload to JSON format
|
||||
jsonData, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
fmt.Println("Error marshalling payload:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Create a POST request to the Discord webhook URL
|
||||
req, err := http.Post(webhookURL, "application/json", bytes.NewReader(jsonData))
|
||||
if err != nil {
|
||||
fmt.Println("Error creating request:", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Close the request body
|
||||
defer req.Body.Close()
|
||||
|
||||
// Check the response status code
|
||||
if req.StatusCode != http.StatusOK {
|
||||
fmt.Println("Error sending request:", req.Status)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
fmt.Scanln()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user