Skip to content

Commit

Permalink
Merge pull request #39 from CSUSTers/dev
Browse files Browse the repository at this point in the history
hot fix some issue
  • Loading branch information
icceey authored Feb 1, 2021
2 parents 67aa490 + 2b4b3ac commit bfbd593
Show file tree
Hide file tree
Showing 13 changed files with 30 additions and 59 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker_push_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
build-args: |
TAG=${{ steps.version.outputs.tag }}
BRANCH=release
RELEASE=release
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ FROM golang:alpine AS buildenv

RUN apk add make git tzdata

ARG BRANCH
ARG TAG
ARG RELEASE

ENV BRANCH=$BRANCH
ENV TAG=$TAG

WORKDIR /go/src/app
COPY . .
RUN make deploy
Expand Down
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
.PHONY: get build test fmt deploy run clean

PROJECT := csust-got
VERSION ?= $(if $(TAG),$(TAG),$(shell git rev-parse --short HEAD))
BRANCH ?= $(shell git branch --show-current)
ifeq ($(VERSION),)
VERSION := $(if $(TAG),$(TAG),$(shell git rev-parse --short HEAD))
endif

ifeq ($(BRANCH),)
BRANCH := $(shell git branch --show-current)
endif

BUILDTIME := $(shell TZ="Asia/Shanghai" date '+%Y/%m/%d-%H:%M:%S')

FLAGPKG = $(PROJECT)/base
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ docker-compose up -d
Clone the newest version.

```bash
git pull
docker-compose up -d --build
docker-compose pull
docker-compose up -d
```

## Configuration
Expand All @@ -60,7 +60,7 @@ bing - <Key Words> 巨硬搜索...
bilibili - <Key Words> 在B站搜索...
github - <Key Words> 在github搜索...
links - 这里有一些链接(加友链at管理)
ban_myself - 把自己ban掉rand[60,120]秒
ban_myself - 把自己ban掉rand[40,160]秒
ban - 我就是要滥权!【Admin】
ban_soft - 软禁!使某人失去快乐~【Admin】
fake_ban - [duration] 虚假(真实)的ban
Expand Down
31 changes: 0 additions & 31 deletions base/hello.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,37 +108,6 @@ func Forward(m *Message) {
}
}

// History is handle for command `history`
// func History(m *Message) {
// command, _ := entities.FromMessage(m)
// historyID := rand.Intn(m.ID) + 1
// if command.Argc() > 0 {
// id, ok := util.ParseNumberAndHandleError(m, command.Arg(0), util.NewRangeInt(0, m.ID))
// if ok {
// historyID = id
// } else {
// return
// }
// }
// msg := fmt.Sprintf("https://t.me/c/%v/%v", chatIDToStr(m.Chat.ID), historyID)
// util.SendReply(m.Chat, msg, m)
// }

// func chatIDToStr(chatID int64) string {
// chatNum := chatID
// if chatNum < 0 {
// chatNum *= -1
// }
// chatStr := strconv.FormatInt(chatNum, 10)
// if chatStr[0] == '1' {
// chatStr = chatStr[1:]
// }
// for chatStr[0] == '0' {
// chatStr = chatStr[1:]
// }
// return chatStr
// }

// FakeBanMyself is handle for command `fake_ban_myself`.
// Use it to just get a reply like command `ban_myself`.
func FakeBanMyself(m *Message) {
Expand Down
2 changes: 1 addition & 1 deletion base/yiban.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func Yiban(m *Message) {
}
tel = orm.GetYiban(m.Sender.ID)
if tel == "" {
util.SendMessage(m.Chat, "不知道你的易班手机号是什么呢~\n命令带上手机号参数可以进行一次性查询,bot不保存您的手机号")
util.SendMessage(m.Chat, "亦之的群友特供版自动打卡推送\n不知道你的易班手机号是什么呢~\n命令带上手机号参数可以进行一次性查询,bot不保存您的手机号")
util.SendMessage(m.Chat, "如果需要bot记住您手机号,请使用 /sub_yiban 命令带上手机号参数,后续查询 /yiban 不再需要填写参数,每日打卡结果bot会推送通知")
return
}
Expand Down
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ white_list:
enabled: true
restrict:
kill_duration: 300 # restrict duration for command `kill` [second]
fake_ban_cd: 1080 # restrict CD for command `kill` or `fake ban xxx` [minutes]
fake_ban_cd: 840 # restrict CD for command `kill` or `fake ban xxx` [minutes]
rate_limit:
max_token: 20 # token bucket size, must [int]
limit: 0.5 # how many tokens get every seconds [float64]
Expand Down
7 changes: 4 additions & 3 deletions entities/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ type BotCommand struct {
}

var (
spaces, _ = regexp.Compile(`\s+`)
spaces, _ = regexp.Compile(`\s+`)
cmdRegex, _ = regexp.Compile(`/[0-9a-zA-Z_]+`)
)

// FromMessage - get command in a message
func FromMessage(msg *Message) *BotCommand {
args := splitText(strings.TrimSpace(msg.Text))
if len(args) == 0 {
return &BotCommand{"", []string{}}
if len(args) == 0 || !cmdRegex.MatchString(args[0]) {
return nil
}
name := args[0]
if idx := strings.IndexRune(name, '@'); idx != -1 {
Expand Down
13 changes: 0 additions & 13 deletions log/bot.go

This file was deleted.

4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func main() {

bot.Handle("/fake_ban_myself", base.FakeBanMyself)
bot.Handle("/fake_ban", util.GroupCommand(restrict.FakeBan))
bot.Handle("/kill", util.GroupCommand(restrict.FakeBan))
bot.Handle("/kill", util.GroupCommand(restrict.Kill))
bot.Handle("/ban_myself", util.GroupCommand(restrict.BanMyself))
bot.Handle("/ban", util.GroupCommand(restrict.Ban))
bot.Handle("/ban_soft", util.GroupCommand(restrict.SoftBan))
Expand Down Expand Up @@ -172,7 +172,7 @@ func shutdownFilter(update *Update) bool {
}
if update.Message.Text != "" {
cmd := entities.FromMessage(update.Message)
if cmd.Name() == "boot" {
if cmd != nil && cmd.Name() == "boot" {
return true
}
}
Expand Down
2 changes: 1 addition & 1 deletion restrict/ban.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func BanCommand(m *Message, hard bool) {
cmd := entities.FromMessage(m)
banTime, err := time.ParseDuration(cmd.Arg(0))
if err != nil {
banTime = time.Duration(rand.Intn(60)+60) * time.Second
banTime = time.Duration(rand.Intn(120)+40) * time.Second
}
var banTarget *User = nil
if !util.CanRestrictMembers(m.Chat, m.Sender) {
Expand Down
2 changes: 1 addition & 1 deletion restrict/fake-ban.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func FakeBan(m *Message) {
cmd := entities.FromMessage(m)
banTime, err := time.ParseDuration(cmd.Arg(0))
if err != nil {
banTime = time.Duration(60+rand.Intn(60)) * time.Second
banTime = time.Duration(40+rand.Intn(120)) * time.Second
}
ExecFakeBan(m, banTime)
}
Expand Down
2 changes: 1 addition & 1 deletion restrict/rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func checkRate(m *Message, limiter *rate.Limiter) bool {
return limiter.AllowN(time.Now(), rateConfig.StickerCost)
}
cmd := entities.FromMessage(m)
if cmd.Name() != "" {
if cmd != nil {
return limiter.AllowN(time.Now(), rateConfig.CommandCost)
}
return limiter.AllowN(time.Now(), rateConfig.Cost)
Expand Down

0 comments on commit bfbd593

Please sign in to comment.