Skip to content

Commit

Permalink
Parameterised inactivyt period
Browse files Browse the repository at this point in the history
  • Loading branch information
jshiell committed Oct 4, 2018
1 parent 8f8ec19 commit 62367fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ You'll need the following pre-requisites.
* Ruby 2.5.1
* Bundler

Then run:

bin/slack-channel-archiver

On the first run it'll install dependencies, which may be a bit noisy.

You'll need an API token to run it. This can be specified in three ways, in order of priority:

1. Pass it as the first argument, e.g. `bin/slack-channel-archiver api-token`
1. Pass it as the second argument, e.g. `bin/slack-channel-archiver 90 api-token`
1. Set it as env var `SLACK_API_TOKEN`, e.g. `SLACK_API_TOKEN=api-token bin/slack-channel-archiver`
1. Set in `~/.slack-channel-archiver`, e.g. `api-token: an-api-token`

You can obtain a new API token by [creating a new Bot Integration](https://my.slack.com/services/new/bot) in Slack.
You can obtain a new API token by [creating a new Bot Integration](https://my.slack.com/services/new/bot) in Slack.

Usage:

bin/slack-channel-archiver [inactivity-period = 90 days] [api-token]

On the first run it'll install dependencies, which may be a bit noisy.
17 changes: 11 additions & 6 deletions lib/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,25 @@ def days_ago(time)
class Launcher

def initialize(args)
api_token = read_api_token(args)
if api_token.nil?
$stderr.puts("Usage: $0 [api-token]")
number_of_days = (args[0] || DEFAULT_NUMBER_OF_DAYS).to_i
api_token = read_api_token(args[1])
if number_of_days.nil? || api_token.nil?
$stderr.puts("Usage: $0 [number-of-days=#{DEFAULT_NUMBER_OF_DAYS}] [api-token]")
$stderr.puts("Alternately you may specify the API token in ~/.slack-channel-archiver as 'api-token', or via env car SLACK_API_TOKEN")
end

puts "Channels that have existed but have had no new messages for at least #{number_of_days} days will be archived"

slack_channel_archiver = SlackChannelArchiver.new(api_token)
slack_channel_archiver.archive_channels_unused_for_days(60)
slack_channel_archiver.archive_channels_unused_for_days(number_of_days)
end

private

def read_api_token(args)
api_token = args.first
DEFAULT_NUMBER_OF_DAYS = 90

def read_api_token(api_token_arg)
api_token = api_token_arg

api_token = ENV['SLACK_API_TOKEN'] if api_token.nil?

Expand Down

0 comments on commit 62367fe

Please sign in to comment.