fucking hate chatgpt
This commit is contained in:
parent
304923a482
commit
d9c23c6a51
BIN
dist/com.mattermost.gameStatusUpdate-0.2.11.tar.gz
vendored
BIN
dist/com.mattermost.gameStatusUpdate-0.2.11.tar.gz
vendored
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
server/dist/plugin-darwin-amd64
vendored
BIN
server/dist/plugin-darwin-amd64
vendored
Binary file not shown.
BIN
server/dist/plugin-darwin-arm64
vendored
BIN
server/dist/plugin-darwin-arm64
vendored
Binary file not shown.
BIN
server/dist/plugin-linux-amd64
vendored
BIN
server/dist/plugin-linux-amd64
vendored
Binary file not shown.
BIN
server/dist/plugin-linux-arm64
vendored
BIN
server/dist/plugin-linux-arm64
vendored
Binary file not shown.
BIN
server/dist/plugin-windows-amd64.exe
vendored
BIN
server/dist/plugin-windows-amd64.exe
vendored
Binary file not shown.
|
@ -33,8 +33,9 @@ var knownGames = map[string]bool{
|
||||||
func (p *Plugin) ReceiveProcessList(w http.ResponseWriter, r *http.Request) {
|
func (p *Plugin) ReceiveProcessList(w http.ResponseWriter, r *http.Request) {
|
||||||
var payload struct {
|
var payload struct {
|
||||||
ProcessList string `json:"processList"`
|
ProcessList string `json:"processList"`
|
||||||
UserID string `json:"userID"` // Assuming you're sending userID from the desktop app
|
UserID string `json:"userID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
|
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
|
||||||
p.API.LogError("Failed to decode process list", "error", err.Error())
|
p.API.LogError("Failed to decode process list", "error", err.Error())
|
||||||
http.Error(w, "Invalid request payload", http.StatusBadRequest)
|
http.Error(w, "Invalid request payload", http.StatusBadRequest)
|
||||||
|
@ -57,26 +58,6 @@ func (p *Plugin) ReceiveProcessList(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetActiveGame scans processes to determine the active game based on known game names
|
|
||||||
func (p *Plugin) GetActiveGame() (string, error) {
|
|
||||||
cmd := exec.Command("ps", "-e")
|
|
||||||
output, err := cmd.Output()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
lines := strings.Split(string(output), "\n")
|
|
||||||
for _, line := range lines {
|
|
||||||
for gameName := range knownGames {
|
|
||||||
if strings.Contains(line, gameName) {
|
|
||||||
return gameName, nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// SetUserGameStatus updates the user's custom status to reflect the game they are playing
|
// SetUserGameStatus updates the user's custom status to reflect the game they are playing
|
||||||
func (p *Plugin) SetUserGameStatus(userID, game string) error {
|
func (p *Plugin) SetUserGameStatus(userID, game string) error {
|
||||||
status := fmt.Sprintf("playing: %s", game)
|
status := fmt.Sprintf("playing: %s", game)
|
||||||
|
@ -85,6 +66,11 @@ func (p *Plugin) SetUserGameStatus(userID, game string) error {
|
||||||
return appErr
|
return appErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Avoid unnecessary updates
|
||||||
|
if user.Props["custom_status"] == status {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
customStatus := model.CustomStatus{
|
customStatus := model.CustomStatus{
|
||||||
Emoji: "video_game",
|
Emoji: "video_game",
|
||||||
Text: status,
|
Text: status,
|
||||||
|
@ -123,6 +109,10 @@ func (p *Plugin) MonitorGameStatus(userID string) {
|
||||||
if err := p.SetUserGameStatus(userID, game); err != nil {
|
if err := p.SetUserGameStatus(userID, game); err != nil {
|
||||||
p.API.LogError("Failed to set user game status", "error", err.Error())
|
p.API.LogError("Failed to set user game status", "error", err.Error())
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if err := p.SetUserGameStatus(userID, ""); err != nil {
|
||||||
|
p.API.LogError("Failed to clear user game status", "error", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(30 * time.Second)
|
time.Sleep(30 * time.Second)
|
||||||
|
@ -130,6 +120,26 @@ func (p *Plugin) MonitorGameStatus(userID string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetActiveGame scans processes to determine the active game based on known game names
|
||||||
|
func (p *Plugin) GetActiveGame() (string, error) {
|
||||||
|
cmd := exec.Command("tasklist") // Use tasklist for Windows
|
||||||
|
output, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
lines := strings.Split(string(output), "\n")
|
||||||
|
for _, line := range lines {
|
||||||
|
for gameName := range knownGames {
|
||||||
|
if strings.Contains(line, gameName) {
|
||||||
|
return gameName, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
// OnActivate is called when the plugin is activated
|
// OnActivate is called when the plugin is activated
|
||||||
func (p *Plugin) OnActivate() error {
|
func (p *Plugin) OnActivate() error {
|
||||||
config := p.getConfiguration()
|
config := p.getConfiguration()
|
||||||
|
@ -150,17 +160,21 @@ func (p *Plugin) OnActivate() error {
|
||||||
|
|
||||||
// Register the HTTP handler for receiving process lists
|
// Register the HTTP handler for receiving process lists
|
||||||
http.HandleFunc("/plugins/com.mattermost.gamestatusupdate/processlist", p.ReceiveProcessList)
|
http.HandleFunc("/plugins/com.mattermost.gamestatusupdate/processlist", p.ReceiveProcessList)
|
||||||
|
|
||||||
|
// Retrieve the current user ID
|
||||||
|
session, err := p.API.GetSession("current") // Use "current" to get the session for the logged-in user
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to get session: %w", err) // Handle the error appropriately
|
||||||
|
}
|
||||||
|
userID := session.UserId
|
||||||
|
|
||||||
|
// Start monitoring game status for the current user
|
||||||
|
go p.MonitorGameStatus(userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnDeactivate is called when the plugin is deactivated
|
|
||||||
func (p *Plugin) OnDeactivate() error {
|
|
||||||
close(p.stopChannel)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// HandleWebSocketEvent handles incoming WebSocket events.
|
// HandleWebSocketEvent handles incoming WebSocket events.
|
||||||
func (p *Plugin) HandleWebSocketEvent(event model.WebSocketEvent) {
|
func (p *Plugin) HandleWebSocketEvent(event model.WebSocketEvent) {
|
||||||
// Check if the event is of type user_status
|
// Check if the event is of type user_status
|
||||||
|
@ -185,20 +199,18 @@ func (p *Plugin) HandleWebSocketEvent(event model.WebSocketEvent) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Continue with your logic to update the user's game status...
|
// Update the user's game status based on active game
|
||||||
game, err := p.GetActiveGame()
|
game, err := p.GetActiveGame()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
p.API.LogError("Failed to get active game", "error", err.Error())
|
p.API.LogError("Failed to get active game", "error", err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the user's game status
|
|
||||||
if game != "" {
|
if game != "" {
|
||||||
if err := p.SetUserGameStatus(data.UserID, game); err != nil {
|
if err := p.SetUserGameStatus(data.UserID, game); err != nil {
|
||||||
p.API.LogError("Failed to update user game status", "error", err.Error())
|
p.API.LogError("Failed to update user game status", "error", err.Error())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Clear the user's game status if no game is detected
|
|
||||||
if err := p.SetUserGameStatus(data.UserID, ""); err != nil {
|
if err := p.SetUserGameStatus(data.UserID, ""); err != nil {
|
||||||
p.API.LogError("Failed to clear user game status", "error", err.Error())
|
p.API.LogError("Failed to clear user game status", "error", err.Error())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue