Skip to content

Commit

Permalink
Removing empty lines on splicedAboveTelegramMax messages (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
why-not-try-calmer authored Mar 5, 2023
1 parent 4d68c76 commit 2c2be95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
8 changes: 5 additions & 3 deletions .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
name: Delete old workflow runs
on:
schedule:
- cron: "0 4 1 * *"
workflow_dispatch:
inputs:
days:
description: 'Number of days.'
description: "Number of days."
required: true
default: 1
minimum_runs:
description: 'The minimum runs to keep for each workflow.'
description: "The minimum runs to keep for each workflow."
required: true
default: 0

Expand All @@ -21,4 +23,4 @@ jobs:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: ${{ github.event.inputs.days }}
keep_minimum_runs: ${{ github.event.inputs.minimum_runs }}
keep_minimum_runs: ${{ github.event.inputs.minimum_runs }}
11 changes: 10 additions & 1 deletion src/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,16 @@ sliceOnN t n =
then (l_acc, l_v)
else (unlined, mempty)

removeAllEmptyLines :: T.Text -> T.Text
removeAllEmptyLines = fst . T.foldl' step tuple_acc
where
tuple_acc = (mempty, 0) :: (T.Text, Int)
step (acc, counter) val
| val == '\n' && counter == 0 = (acc `T.append` T.singleton val, 1)
| val == '\n' && counter == 1 = (acc, 0)
| otherwise = (acc `T.append` T.singleton val, counter)

sliceIfAboveTelegramMax :: T.Text -> [T.Text]
sliceIfAboveTelegramMax msg
| T.length msg <= 4096 = pure msg
| otherwise = sliceOnN msg 4096
| otherwise = removeAllEmptyLines <$> sliceOnN msg 4096

0 comments on commit 2c2be95

Please sign in to comment.