Initial commit
This commit is contained in:
52
internal/moon/squash.go
Normal file
52
internal/moon/squash.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package moon
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/NicoNex/echotron/v3"
|
||||
)
|
||||
|
||||
// TODO: refactor to return bool, error
|
||||
|
||||
// squash bans given chat member.
|
||||
func squash(chatid, userid int64) {
|
||||
banUntilDate := time.Now().Unix() + 10
|
||||
|
||||
if timestamp := FindSquashedMember(chatid, userid); timestamp != 0 {
|
||||
Log.Infof("Skip banning user %d, already banned")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if res, err := Tg.BanChatMember(
|
||||
chatid,
|
||||
userid,
|
||||
&echotron.BanOptions{
|
||||
UntilDate: int(banUntilDate),
|
||||
},
|
||||
); err != nil {
|
||||
Log.Errorf(
|
||||
"Unable to ban user with id %d in chat %s: %s",
|
||||
userid,
|
||||
chatid,
|
||||
res.Description,
|
||||
)
|
||||
} else {
|
||||
if !res.Ok {
|
||||
Log.Errorf(
|
||||
"Unable to ban user with id %d in chat %s: %s",
|
||||
userid,
|
||||
chatid,
|
||||
res.Description,
|
||||
)
|
||||
} else {
|
||||
Log.Infof(
|
||||
"Banned user with id %d in chat %d.",
|
||||
userid,
|
||||
chatid,
|
||||
)
|
||||
|
||||
AddSquashedMember(chatid, userid)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user