Files
open-im-server/cmd/cmdutils/main.go
T

110 lines
2.6 KiB
Go
Raw Normal View History

2023-02-23 18:20:45 +08:00
package main
import (
2023-03-03 17:42:26 +08:00
"OpenIM/internal/tools"
2023-03-07 12:12:16 +08:00
"OpenIM/pkg/common/cmd"
2023-03-07 17:59:34 +08:00
"context"
2023-03-07 12:12:16 +08:00
"fmt"
"github.com/spf13/cobra"
"os"
2023-02-23 18:20:45 +08:00
)
2023-03-07 17:59:34 +08:00
var seqCmd = &cobra.Command{
Use: "seq",
Short: "seq operation",
RunE: func(cmdLines *cobra.Command, args []string) error {
msgTool, err := tools.InitMsgTool()
if err != nil {
return err
}
userID, _ := cmdLines.Flags().GetString("userID")
superGroupID, _ := cmdLines.Flags().GetString("superGroupID")
fixAll, _ := cmdLines.Flags().GetBool("fixAll")
ctx := context.Background()
switch {
case cmdLines.Parent() == getCmd:
switch {
case userID != "":
msgTool.ShowUserSeqs(ctx, userID)
case superGroupID != "":
msgTool.ShowSuperGroupSeqs(ctx, superGroupID)
}
case cmdLines.Parent() == fixCmd:
switch {
case userID != "":
_, _, err = msgTool.GetAndFixUserSeqs(ctx, userID)
case superGroupID != "":
err = msgTool.FixGroupSeq(ctx, userID)
case fixAll:
err = msgTool.FixAllSeq(ctx)
}
}
return err
2023-03-07 12:12:16 +08:00
},
}
2023-03-07 17:59:34 +08:00
var msgCmd = &cobra.Command{
Use: "msg",
Short: "msg operation",
RunE: func(cmdLines *cobra.Command, args []string) error {
msgTool, err := tools.InitMsgTool()
if err != nil {
return err
}
userID, _ := cmdLines.Flags().GetString("userID")
superGroupID, _ := cmdLines.Flags().GetString("superGroupID")
clearAll, _ := cmdLines.Flags().GetBool("clearAll")
ctx := context.Background()
switch {
case cmdLines.Parent() == getCmd:
switch {
case userID != "":
msgTool.ShowUserSeqs(ctx, userID)
case superGroupID != "":
msgTool.ShowSuperGroupSeqs(ctx, superGroupID)
}
case cmdLines.Parent() == clearCmd:
switch {
case userID != "":
msgTool.ClearUsersMsg(ctx, []string{userID})
case superGroupID != "":
msgTool.ClearSuperGroupMsg(ctx, []string{superGroupID})
case clearAll:
msgTool.AllUserClearMsgAndFixSeq()
}
}
return nil
},
2023-03-07 12:12:16 +08:00
}
2023-03-07 17:59:34 +08:00
var getCmd = &cobra.Command{
Use: "get",
Short: "get operation",
}
2023-03-07 12:12:16 +08:00
2023-03-07 17:59:34 +08:00
var fixCmd = &cobra.Command{
Use: "fix",
Short: "fix seq operation",
}
2023-03-07 12:12:16 +08:00
2023-03-07 17:59:34 +08:00
var clearCmd = &cobra.Command{
Use: "clear",
Short: "clear operation",
2023-03-07 12:12:16 +08:00
}
func main() {
2023-03-07 20:31:40 +08:00
rootCmd := cmd.NewMsgUtilsCmd()
rootCmd.Command.PersistentFlags().StringP("userID", "u", "", "openIM userID")
rootCmd.Command.PersistentFlags().StringP("groupID", "u", "", "openIM superGroupID")
2023-03-07 17:59:34 +08:00
seqCmd.Flags().BoolP("fixAll", "c", false, "openIM fix all seqs")
msgCmd.Flags().BoolP("clearAll", "c", false, "openIM clear all timeout msgs")
getCmd.AddCommand(seqCmd, msgCmd)
fixCmd.AddCommand(seqCmd)
clearCmd.AddCommand(msgCmd)
2023-03-07 20:31:40 +08:00
rootCmd.AddCommand(getCmd, fixCmd, clearCmd)
if err := rootCmd.Execute(); err != nil {
2023-03-07 12:12:16 +08:00
fmt.Println(err)
os.Exit(1)
}
}