This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
90 lines (76 loc) · 1.89 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package cmd
import (
"fmt"
"github.com/arrow2nd/twnyan/util"
"github.com/gookit/color"
)
// parseTweetCmdArgs ツイートのコマンドをパースする
func parseTweetCmdArgs(args []string) (string, []string) {
status, media := "にゃーん", []string{}
if len(args) > 0 {
if util.ChkRegexp("\\.\\w{3,4}$", args[0]) {
status = ""
media = args[0:]
} else {
status = args[0]
media = args[1:]
}
}
return status, media
}
// reactToTweet ツイートにリアクションする
func reactToTweet(args []string, cmdName string, function func(string)) {
if len(args) <= 0 {
showWrongMsg(cmdName)
return
}
for _, v := range args {
id, err := tweets.GetDataFromTweetNum(v, "TweetID")
if err != nil {
color.Error.Tips(err.Error())
return
}
function(id)
}
}
// reactToUser ユーザーにリアクションする
func reactToUser(args []string, cmdName string, function func(string)) {
if len(args) <= 0 {
showWrongMsg(cmdName)
return
}
screenName := args[0]
// ツイート番号が指定された場合
if util.IsNumber(args[0]) {
var err error
screenName, err = tweets.GetDataFromTweetNum(args[0], "ScreenName")
if err != nil {
color.Error.Tips(err.Error())
return
}
}
function(screenName)
}
// createCompleter 入力補完用リストを作成
func createCompleter(list []string) []string {
if list == nil {
return nil
}
r := make([]string, len(list))
for i, v := range list {
if util.ChkRegexp("\\s", v) {
r[i] = fmt.Sprintf("\"%s\"", v)
} else {
r[i] = v
}
}
return r
}
// CreateLongHelp 詳しいヘルプ文を作成
func createLongHelp(help, alias, use, exp string) string {
return fmt.Sprintf("%s\n\nAlias:\n %s\n\nUse:\n %s\n\nExample:\n %s", help, alias, use, exp)
}
// showWrongMsg 引数ミスのメッセージを表示
func showWrongMsg(cmdName string) {
color.Error.Tips("Wrong argument, try '%s help'", cmdName)
}