Skip to content

Commit

Permalink
Tweaks to the verification and welcome procdures. Tweaks to the build…
Browse files Browse the repository at this point in the history
… script. Fixes #2
  • Loading branch information
AtomicNicos committed Sep 17, 2022
1 parent 7c66208 commit 8ccfa1b
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 85 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Released]

## `0.1.4` - 2022-09-17
### Fixes
- Issue #2: [Link to issue](https://github.com/digital-overdose/digital-overdose-bot/issues/2)

### Changed
- `purge-verification`: Cleanliness by editing counter messages instead of reposting them.
- `purge-verification`: Message in debug channel to indicate that the challenge was launched by the cron.
- `welcome`: Changes how the user string is determined.
- Powershell / CMD / sh build scripts to something more... clean.

## `0.1.3-hotfix` - 2022-09-16
### Fixes
- Issue #1: [Link to issue](https://github.com/digital-overdose/digital-overdose-bot/issues/1)

### Changed
- Restoring changes to the "Time Last Seen" calculation to take into account the most recent of the last messages, and not be overwritten.
- Slight changes to build scripts.

## [0.1.3] - 2022-09-15
### Added
- Cron feature.
Expand Down
88 changes: 51 additions & 37 deletions build-all-architectures.bat
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
@echo off
set VERSION=1.1.3-hotfix

:: set GOOS=darwin && set GOARCH=amd64 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
:: set GOOS=darwin && set GOARCH=arm64 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .

:: set GOOS=dragonfly && set GOARCH=amd64 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .

:: set GOOS=freebsd && set GOARCH=386 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
:: set GOOS=freebsd && set GOARCH=amd64 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
:: set GOOS=freebsd && set GOARCH=arm && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .

:: set GOOS=linux && set GOARCH=386 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
set GOOS=linux && set GOARCH=amd64 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
set GOOS=linux && set GOARCH=arm && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
set GOOS=linux && set GOARCH=arm64 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
:: set GOOS=linux && set GOARCH=ppc64 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
:: set GOOS=linux && set GOARCH=ppc64le && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
:: set GOOS=linux && set GOARCH=mips && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
:: set GOOS=linux && set GOARCH=mipsle && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
:: set GOOS=linux && set GOARCH=mips64 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
:: set GOOS=linux && set GOARCH=mips64le && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .

:: set GOOS=netbsd && set GOARCH=386 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
:: set GOOS=netbsd && set GOARCH=amd64 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
:: set GOOS=netbsd && set GOARCH=arm && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .

:: set GOOS=openbsd && set GOARCH=386 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
:: set GOOS=openbsd && set GOARCH=amd64 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
:: set GOOS=openbsd && set GOARCH=arm && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .

:: set GOOS=plan9 && set GOARCH=386 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .
:: set GOOS=plan9 && set GOARCH=amd64 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .

:: set GOOS=solaris && set GOARCH=amd64 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH% .

set GOOS=windows && set GOARCH=386 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH%.exe .
set GOOS=windows && set GOARCH=amd64 && go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH%.exe .
echo Building artifacts in /build
set VERSION=%1

:: call :build darwin amd64
:: call :build darwin arm64

:: call :build dragonfly amd64

:: call :build freebsd 386
:: call :build freebsd amd64
:: call :build freebsd arm

:: call :build linux 386
call :build linux amd64
call :build linux arm
call :build linux arm64
:: call :build linux ppc64
:: call :build linux ppc64le
:: call :build linux mips
:: call :build linux mipsle
:: call :build linux mips64
:: call :build linux mips64le

:: call :build netbsd 386
:: call :build netbsd amd64
:: call :build netbsd arm

:: call :build openbsd 386
:: call :build openbsd amd64
:: call :build openbsd arm

:: call :build plan9 386
:: call :build plan9 amd64

:: call :build solaris amd64

call :build windows 386
call :build windows amd64

echo Done!
exit /b

:build
set GOOS=%~1
set GOARCH=%~2
set EXT=
if "%GOOS%"=="windows" (
set EXT=.exe
)
go build -o build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH%%EXT% .
echo Built build/digital-overdose-bot-v%VERSION%-%GOOS%-%GOARCH%%EXT%
79 changes: 42 additions & 37 deletions build-all-architectures.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
VERSION=1.1.3-hotfix

#GOOS=darwin; GOARCH=amd64; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-amd64 .
#GOOS=darwin; GOARCH=arm64; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-arm64 .

#GOOS=dragonfly; GOARCH=amd64; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-amd64 .

#GOOS=freebsd; GOARCH=386; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-386 .
#GOOS=freebsd; GOARCH=amd64; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-amd64 .
#GOOS=freebsd; GOARCH=arm; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-arm .

#GOOS=linux; GOARCH=386; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-386 .
GOOS=linux; GOARCH=amd64; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-amd64 .
GOOS=linux; GOARCH=arm; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-arm .
GOOS=linux; GOARCH=arm64; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-arm64 .
#GOOS=linux; GOARCH=ppc64; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-ppc64 .
#GOOS=linux; GOARCH=ppc64le; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-ppc64le .
#GOOS=linux; GOARCH=mips; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-mips .
#GOOS=linux; GOARCH=mipsle; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-mipsle .
#GOOS=linux; GOARCH=mips64; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-mips64 .
#GOOS=linux; GOARCH=mips64le; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-mips64le .

#GOOS=netbsd; GOARCH=386; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-386 .
#GOOS=netbsd; GOARCH=amd64; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-amd64 .
#GOOS=netbsd; GOARCH=arm; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-arm .

#GOOS=openbsd; GOARCH=386; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-386 .
#GOOS=openbsd; GOARCH=amd64; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-amd64 .
#GOOS=openbsd; GOARCH=arm; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-arm .

#GOOS=plan9; GOARCH=386; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-386 .
#GOOS=plan9; GOARCH=amd64; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-amd64 .

#GOOS=solaris; GOARCH=amd64; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-amd64 .

GOOS=windows; GOARCH=386; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-386.exe .
GOOS=windows; GOARCH=amd64; go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH-amd64.exe .
echo "Building artifacts in /build"
VERSION=$1

build () {
GOOS=$1
GOARCH=$2
EXT=""
if [ "$2" = "windows" ]
then
EXT=".exe"
fi

go build -o build/digital-overdose-bot-v$VERSION-$GOOS-$GOARCH$EXT .
}

#build darwin amd64
#build darwin arm64
#build dragonfly amd64
#build freebsd 386
#build freebsd amd64
#build freebsd arm
#build linux 386
build linux amd64
build linux arm
build linux arm64
# build linux ppc64
# build linux ppc64le
# build linux mips
# build linux mipsle
# build linux mips64
# build linux mips64le
# build netbsd 386
# build netbsd amd64
# build netbsd arm
# build openbsd 386
# build openbsd amd64
# build openbsd arm
# build plan9 386
# build plan9 amd64
# build solaris amd64
build windows 386
build windows amd64
14 changes: 10 additions & 4 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,22 @@ var (
)

// Writes the message to the application log and the debug channel, if it is set.
func LogAndSend(message string, s *discordgo.Session, optional ...string) {
func LogAndSend(message string, s *discordgo.Session, nonDefaultChannelID ...string) string {
log.Print(message)

if len(optional) > 0 && len(optional[0]) > 0 {
_, _ = s.ChannelMessageSend(optional[0], message)
if len(nonDefaultChannelID) > 0 && len(nonDefaultChannelID[0]) > 0 {
msg, _ := s.ChannelMessageSend(nonDefaultChannelID[0], message)
return msg.ID
} else if len(nonDefaultChannelID) > 0 && len(nonDefaultChannelID[0]) == 0 {
return ""
} else if *DebugChannelID != "" {
_, _ = s.ChannelMessageSend(*DebugChannelID, message)
msg, _ := s.ChannelMessageSend(*DebugChannelID, message)
return msg.ID
} else if !DebugChannelWarning {
log.Print("DEBUG_CHANNEL_ID / --debug was not defined, skipping all debug message forwarding.")
}

return ""
}

// Attempts to load an environment file, and if it exists, overwrites any flags set through argv with it's contents.
Expand Down
17 changes: 13 additions & 4 deletions ext/commands/purge-verification.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func PurgeVerification(s *discordgo.Session, i *discordgo.InteractionCreate) {
if ok, _ := common.CheckHasPermissions(i, s, discordgo.PermissionManageRoles); !ok {
return
}
} else {
common.LogAndSend(":robot: :rotating-light: `/purge-verification` triggered by cron.", s)
}

var (
Expand Down Expand Up @@ -76,6 +78,7 @@ func PurgeVerification(s *discordgo.Session, i *discordgo.InteractionCreate) {

// Processes the last 1000 messages (in batches of 100) in reverse-chronological order.
// Adds them to the list of the members having messages (read: interacted).
counterMessageID := ""
for messagesProcessed < messageLimit {
messages, err := s.ChannelMessages(*common.VerificationChannelID, 100, lastMessageID, "", "")
if err != nil {
Expand All @@ -85,7 +88,14 @@ func PurgeVerification(s *discordgo.Session, i *discordgo.InteractionCreate) {
messagesProcessed += len(messages)
lastMessageID = messages[len(messages)-1].ID

common.LogAndSend(fmt.Sprintf("\tGot %v messages (%v/%v)!", len(messages), messagesProcessed, messageLimit), s)
if messagesProcessed == 100 {
counterMessageID = common.LogAndSend(fmt.Sprintf("\tGot %v messages (%v/%v)!", len(messages), messagesProcessed, messageLimit), s)
} else {
common.LogAndSend(fmt.Sprintf("\tGot %v messages (%v/%v)!", len(messages), messagesProcessed, messageLimit), s, "")
if *common.DebugChannelID != "" {
s.ChannelMessageEdit(*common.DebugChannelID, counterMessageID, fmt.Sprintf("\tGot %v messages (%v/%v)!", len(messages), messagesProcessed, messageLimit))
}
}

for _, msg := range messages {
if _, ok := timeLastMessaged[msg.Author.ID]; !ok {
Expand Down Expand Up @@ -118,20 +128,19 @@ func PurgeVerification(s *discordgo.Session, i *discordgo.InteractionCreate) {

// DMs and Kicks the candidates.
for _, candidate := range candidatesKick {
common.LogAndSend(fmt.Sprintf("[----] User %v will be kicked.", candidate.User.Username), s)
common.LogAndSend(fmt.Sprintf("[----] User %v will be kicked. Last interaction: <t:%v:f>", candidate.User.Username, timeLastSeen[candidate.User.ID].Unix()), s)

sendDMToUser(candidate, s)
kickUser(candidate, s)
}

// Generate the warn message for the warned candidates.
for _, candidate := range candidatesWarn {
common.LogAndSend(fmt.Sprintf("[----] User %v will be warned.", candidate.User.Username), s)
common.LogAndSend(fmt.Sprintf("[----] User %v will be warned. Last interaction: <t:%v:f>", candidate.User.Username, timeLastSeen[candidate.User.ID].Unix()), s)
}
warnUsers(candidatesWarn, timeLastSeen, s)

// Writes a report to the specified mod-action-logs channel.

sendModActionLogsMessage(candidatesKick, candidatesWarn, s)
common.LogAndSend("[✓] Done!", s)
}
Expand Down
15 changes: 12 additions & 3 deletions ext/commands/welcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ func WelcomeUser(s *discordgo.Session, i *discordgo.InteractionCreate) {
return
}

usr_str := fmt.Sprintf("'%v#%v' (ID: %v)", opt.UserValue(nil).Username, opt.UserValue(nil).Discriminator, opt.UserValue(nil).ID)
member, err := s.GuildMember(*common.GuildID, opt.UserValue(nil).ID)
if err != nil {
log.Printf("Failed to retrieve Member (ID: %v) from Guild %v", opt.UserValue(nil).ID, *common.GuildID)
}

usr_str := fmt.Sprintf("'%v#%v' (ID: %v)", member.User.Username, member.User.Discriminator, member.User.ID)

if *common.HumanRoleID != "" {
log.Printf("[+] Adding 'Human' role to %v", usr_str)
err := s.GuildMemberRoleAdd(*common.GuildID, opt.UserValue(nil).ID, *common.HumanRoleID)

if err != nil {
log.Printf("[x] Failed adding 'Human' role to %v", usr_str)
}
Expand All @@ -39,21 +45,24 @@ func WelcomeUser(s *discordgo.Session, i *discordgo.InteractionCreate) {
if *common.MemberRoleID != "" {
log.Printf("[+] Adding 'Member' role to %v", usr_str)
err := s.GuildMemberRoleAdd(*common.GuildID, opt.UserValue(nil).ID, *common.MemberRoleID)

if err != nil {
log.Printf("[x] Failed adding 'Member' role to %v", usr_str)
}
}

log.Printf("[+] Removing 'Verification' role from %v", usr_str)
err := s.GuildMemberRoleRemove(*common.GuildID, opt.UserValue(nil).ID, *common.VerificationRoleID)
err = s.GuildMemberRoleRemove(*common.GuildID, opt.UserValue(nil).ID, *common.VerificationRoleID)

if err != nil {
log.Printf("[x] Failed removing 'Verification' role from %v", usr_str)
}

if *common.MainChannelID != "" {
formatted_msg := fmt.Sprintf("Welcome <@%v>! Please remember the <#687239516800548894>, perhaps tell us something <#783109920240697414>, grab yourself some <#687232316061384779> and perhaps drop <#783110016076349450>!", opt.UserValue(nil).ID)

log.Printf("[+] Welcomed %v in main channel.", usr_str)
common.LogAndSend(fmt.Sprintf("[+] Welcomed %v in main channel.", usr_str), s)
//_, err := s.ChannelMessageSend(*common.DebugChannelID, formatted_msg)
_, err := s.ChannelMessageSend(*common.MainChannelID, formatted_msg)

if err != nil {
Expand Down

0 comments on commit 8ccfa1b

Please sign in to comment.