コード例 #1
0
ファイル: robot.go プロジェクト: elct9620/go-plurk-robot
// Create a new robot instance
func New() *Robot {
	session, err := db.OpenSession("")
	if err != nil {
		logger.Error("Initialize robot failed, because %s", err.Error())
		return nil
	}

	return &Robot{cron: cron.New(), Signal: make(chan os.Signal, 1), db: session.DB("")}
}
コード例 #2
0
ファイル: commands.go プロジェクト: elct9620/go-plurk-robot
	Long:  `Start a robot with task can automatic add plurk/response and other things`,
	Run: func(cmd *cobra.Command, args []string) {
		robot.SetupPlurk(AppKey, AppSecret, Token, TokenSecret)
		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())