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", "description": "this plugin will update statuses to show what game is being played - fuck discord",
"homepage_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate", "homepage_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate",
"support_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate/issues", "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", "icon_path": "assets/starter-template-icon.svg",
"version": "0.2.6", "version": "0.2.7",
"min_server_version": "6.2.1", "min_server_version": "6.2.1",
"server": { "server": {
"executables": { "executables": {

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
{ {
"id": "com.mattermost.plugin-gameStatusUpdate", "id": "com.mattermost.plugin-gameStatusUpdate",
"name": "game status update", "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", "description": "this plugin will update statuses to show what game is being played - fuck discord",
"homepage_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate", "homepage_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate",
"support_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate/issues", "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 package main
import ( //import (
"github.com/mattermost/mattermost/server/public/plugin" // "github.com/mattermost/mattermost/server/public/plugin"
) //)
func main() { //func main() {
plugin.ClientMain(&Plugin{}) // 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", "description": "this plugin will update statuses to show what game is being played - fuck discord",
"homepage_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate", "homepage_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate",
"support_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate/issues", "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", "icon_path": "assets/starter-template-icon.svg",
"version": "0.2.6", "version": "0.2.7",
"min_server_version": "6.2.1", "min_server_version": "6.2.1",
"server": { "server": {
"executables": { "executables": {

View file

@ -3,6 +3,7 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/http"
"os/exec" "os/exec"
"strings" "strings"
"sync" "sync"
@ -36,9 +37,8 @@ var knownGames = map[string]bool{
// GetActiveGame scans processes to determine the active game based on known game names // GetActiveGame scans processes to determine the active game based on known game names
func (p *Plugin) GetActiveGame() (string, error) { func (p *Plugin) GetActiveGame() (string, error) {
// For Windows, use tasklist command to get the list of processes // For Linux, use the ps command to get the list of processes
cmd := exec.Command("tasklist") cmd := exec.Command("ps", "-e") // -e lists all processes
output, err := cmd.Output() output, err := cmd.Output()
if err != nil { if err != nil {
return "", err return "", err
@ -114,39 +114,36 @@ func (p *Plugin) MonitorGameStatus(userID string) {
} }
} }
// ExecuteCommand handles the `/setgame` command to manually set a game // handleProcessList handles the incoming process list from the desktop app
func (p *Plugin) ExecuteCommand(c *plugin.Context, command *model.CommandArgs) (*model.CommandResponse, *model.AppError) { func (p *Plugin) handleProcessList(w http.ResponseWriter, r *http.Request) {
split := strings.Fields(command.Command) var requestData struct {
ProcessList string `json:"processList"`
if len(split) == 0 { UserID string `json:"userID"` // Expecting the user ID in the request payload
return &model.CommandResponse{}, nil
} }
switch split[0] { if err := json.NewDecoder(r.Body).Decode(&requestData); err != nil {
case "/setgame": http.Error(w, "Invalid request payload", http.StatusBadRequest)
var game string return
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:], " ")
}
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 { 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 // OnActivate is called when the plugin is activated
@ -164,8 +161,16 @@ func (p *Plugin) OnActivate() error {
return err return err
} }
// Start background process monitoring for all users // Create a new HTTP ServeMux and register the endpoint
go p.MonitorGameStatus("user_id_here") // Replace with actual user ID(s) 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 return nil
} }
@ -176,6 +181,6 @@ func (p *Plugin) OnDeactivate() error {
return nil return nil
} }
//func main() { func main() {
// plugin.ClientMain(&Plugin{}) 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", "description": "this plugin will update statuses to show what game is being played - fuck discord",
"homepage_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate", "homepage_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate",
"support_url": "https://gitlab.peanutsmediaserver.com/aaron/gameStatusUpdate/issues", "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", "icon_path": "assets/starter-template-icon.svg",
"version": "0.2.6", "version": "0.2.7",
"min_server_version": "6.2.1", "min_server_version": "6.2.1",
"server": { "server": {
"executables": { "executables": {