示例#1
0
// Add Plurk Implement
func addPlurk(cmd *cobra.Command, args []string) {
	if len(args) > 0 {
		lang, _ := cmd.Flags().GetString("lang")
		qualifier, _ := cmd.Flags().GetString("qualifier")

		timeline := Client.GetTimeline()
		res, err := timeline.PlurkAdd(strings.Join(args, " "), qualifier, make([]int, 0), false, lang, true)
		if err != nil {
			logger.FError(cmd.Out(), err.Error())
			return
		}
		logger.FInfo(cmd.Out(), "Success, Plurk ID: %d", res.PlurkID)
	} else {
		logger.FError(cmd.Out(), "No plurk content specified")
	}
}
示例#2
0
func addResponse(cmd *cobra.Command, args []string) {
	if len(args) > 1 {
		plurkID, err := strconv.Atoi(args[0:1][0])
		responseContent := args[1:]
		qualifier, _ := cmd.Flags().GetString("qualifier")

		if err != nil {
			logger.FError(cmd.Out(), "Convert plurk id error, reason: %s", err.Error())
			return
		}

		response := Client.GetResponses()
		res, err := response.ResponseAdd(plurkID, strings.Join(responseContent, " "), qualifier)

		if err != nil {
			logger.FError(cmd.Out(), err.Error())
		} else {
			logger.FInfo(cmd.Out(), "Respons success add to %d, and response id is %d", plurkID, res.Id)
		}
	} else {
		logger.FError(cmd.Out(), "No plurk id or response content specified")
	}
}
示例#3
0
		r := robot.New()
		if r != nil {
			r.Start()
		}
	},
}

var cmdCreateUser = &cobra.Command{
	Use:   "useradd",
	Short: "Create a user",
	Long:  `Create a user for admin plurk robot script, first argument is username, secondary is password`,
	Run: func(cmd *cobra.Command, args []string) {
		session, err := db.OpenSession("")

		if err != nil {
			logger.FError(cmd.Out(), err.Error())
			return
		}

		if len(args) < 2 {
			logger.FError(cmd.Out(), "You should specify username and password")
			return
		}

		user, err := db.CreateUser(session.DB(""), args[0], args[1])

		if err != nil {
			logger.FError(cmd.Out(), err.Error())
			return
		}