new codesss

This commit is contained in:
aaron 2024-11-04 11:20:29 -08:00
parent c4f1b00f46
commit 3655c62c90
19 changed files with 56 additions and 50 deletions

View file

@ -4,9 +4,9 @@
"description": "this plugin will update statuses to show what game is being played - fuck discord",
"homepage_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate",
"support_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate/issues",
"release_notes_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdatereleases/tag/v0.2.5",
"release_notes_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdatereleases/tag/v0.2.6",
"icon_path": "assets/starter-template-icon.svg",
"version": "0.2.6",
"version": "0.2.7",
"min_server_version": "6.2.1",
"server": {
"executables": {

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
{
"id": "com.mattermost.plugin-gameStatusUpdate",
"name": "game status update",
"version": "0.2.6",
"version": "0.2.7",
"description": "this plugin will update statuses to show what game is being played - fuck discord",
"homepage_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate",
"support_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate/issues",

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,9 +1,10 @@
package main
import (
"github.com/mattermost/mattermost/server/public/plugin"
)
//import (
// "github.com/mattermost/mattermost/server/public/plugin"
//)
func main() {
plugin.ClientMain(&Plugin{})
}
//func main() {
// plugin.ClientMain(&Plugin{})
//}
//

View file

@ -18,9 +18,9 @@ const manifestStr = `
"description": "this plugin will update statuses to show what game is being played - fuck discord",
"homepage_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate",
"support_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate/issues",
"release_notes_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdatereleases/tag/v0.2.5",
"release_notes_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdatereleases/tag/v0.2.6",
"icon_path": "assets/starter-template-icon.svg",
"version": "0.2.6",
"version": "0.2.7",
"min_server_version": "6.2.1",
"server": {
"executables": {

View file

@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"net/http"
"os/exec"
"strings"
"sync"
@ -36,9 +37,8 @@ var knownGames = map[string]bool{
// GetActiveGame scans processes to determine the active game based on known game names
func (p *Plugin) GetActiveGame() (string, error) {
// For Windows, use tasklist command to get the list of processes
cmd := exec.Command("tasklist")
// For Linux, use the ps command to get the list of processes
cmd := exec.Command("ps", "-e") // -e lists all processes
output, err := cmd.Output()
if err != nil {
return "", err
@ -114,39 +114,36 @@ func (p *Plugin) MonitorGameStatus(userID string) {
}
}
// ExecuteCommand handles the `/setgame` command to manually set a game
func (p *Plugin) ExecuteCommand(c *plugin.Context, command *model.CommandArgs) (*model.CommandResponse, *model.AppError) {
split := strings.Fields(command.Command)
if len(split) == 0 {
return &model.CommandResponse{}, nil
// handleProcessList handles the incoming process list from the desktop app
func (p *Plugin) handleProcessList(w http.ResponseWriter, r *http.Request) {
var requestData struct {
ProcessList string `json:"processList"`
UserID string `json:"userID"` // Expecting the user ID in the request payload
}
switch split[0] {
case "/setgame":
var game string
var err error
if len(split) < 2 {
// Scan for active game if no specific game is mentioned
game, err = p.GetActiveGame()
if err != nil {
return nil, &model.AppError{Message: "Failed to scan processes", StatusCode: 500}
}
} else {
game = strings.Join(split[1:], " ")
}
if err := json.NewDecoder(r.Body).Decode(&requestData); err != nil {
http.Error(w, "Invalid request payload", http.StatusBadRequest)
return
}
err = p.SetUserGameStatus(command.UserId, game)
// Check for active game from the process list
game := ""
for knownGame := range knownGames {
if strings.Contains(requestData.ProcessList, knownGame) {
game = knownGame
break
}
}
if game != "" {
err := p.SetUserGameStatus(requestData.UserID, game) // Use the user ID from the request
if err != nil {
return nil, &model.AppError{Message: "Failed to set game status", StatusCode: 500}
http.Error(w, "Failed to update user status", http.StatusInternalServerError)
return
}
return &model.CommandResponse{
Text: fmt.Sprintf("your status has been updated to: %s", game),
}, nil
default:
return &model.CommandResponse{}, nil
}
w.WriteHeader(http.StatusOK)
}
// OnActivate is called when the plugin is activated
@ -164,8 +161,16 @@ func (p *Plugin) OnActivate() error {
return err
}
// Start background process monitoring for all users
go p.MonitorGameStatus("user_id_here") // Replace with actual user ID(s)
// Create a new HTTP ServeMux and register the endpoint
mux := http.NewServeMux()
mux.HandleFunc("/processlist", p.handleProcessList)
// Start the HTTP server
go func() {
if err := http.ListenAndServe(":8080", mux); err != nil {
p.API.LogError("Failed to start HTTP server", "error", err.Error())
}
}()
return nil
}
@ -176,6 +181,6 @@ func (p *Plugin) OnDeactivate() error {
return nil
}
//func main() {
// plugin.ClientMain(&Plugin{})
//}
func main() {
plugin.ClientMain(&Plugin{})
}

2
webapp/dist/main.js vendored

File diff suppressed because one or more lines are too long

View file

@ -7,9 +7,9 @@ const manifest = JSON.parse(`
"description": "this plugin will update statuses to show what game is being played - fuck discord",
"homepage_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate",
"support_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate/issues",
"release_notes_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdatereleases/tag/v0.2.5",
"release_notes_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdatereleases/tag/v0.2.6",
"icon_path": "assets/starter-template-icon.svg",
"version": "0.2.6",
"version": "0.2.7",
"min_server_version": "6.2.1",
"server": {
"executables": {