Skip to content

Commit b37e21c

Browse files
author
LiquidLemon
committed
Limit amount of challenges listed in channels
1 parent 07d17b4 commit b37e21c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

bot.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
c.plugins.prefix = /^#{CONFIG.prefix || '!'}/
4040
c.plugins.options[CTFPlugin] = {
4141
lookahead: CONFIG.lookahead,
42-
42+
event_limit: CONFIG.event_limit,
4343
mark_highschool: CONFIG.mark_highschool,
4444
announce_periods: CONFIG.announcement_periods,
4545
help: help_message

plugins/ctf.rb

+8-4
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ def on_creds(msg)
6969
save_credentials
7070
end
7171

72-
def list_ctfs(ctfs, target)
72+
def list_ctfs(ctfs, target, limit = nil)
7373
msg = ''
74-
ctfs.each do |ctf|
74+
amount = limit.nil? ? ctfs.size : limit
75+
ctfs.take(amount).each do |ctf|
7576
msg << CTF.format(ctf, mark_hs: config[:mark_highschool])
7677
if @credentials.has_key?(ctf.title)
7778
creds = @credentials[ctf.title].reject(&:nil?).map { |x| "'#{x}'" }.join(':')
@@ -80,13 +81,16 @@ def list_ctfs(ctfs, target)
8081
msg << "\n"
8182
end
8283
target.notice(msg)
84+
if amount != ctfs.size
85+
target.notice("and #{ctfs.size - amount} more. To see all request over PM.")
86+
end
8387
end
8488

8589
def list_current_ctfs(target, notify_empty=true)
8690
current_ctfs = @fetcher.current_ctfs
8791
if !current_ctfs.empty?
8892
target.notice("Current CTF's:\n")
89-
list_ctfs(current_ctfs, msg)
93+
list_ctfs(current_ctfs, msg, target.is_a?(Cinch::Channel) ? CONFIG[:event_limit] : nil)
9094
else
9195
return unless notify_empty
9296
target.notice("There are no current CTF's\n")
@@ -97,7 +101,7 @@ def list_upcoming_ctfs(target, notify_empty=true)
97101
upcoming_ctfs = @fetcher.upcoming_ctfs
98102
if !upcoming_ctfs.empty?
99103
target.notice("Upcoming CTF's in the next #{config[:lookahead]}:\n")
100-
list_ctfs(upcoming_ctfs, target)
104+
list_ctfs(upcoming_ctfs, target, target.is_a?(Cinch::Channel) ? CONFIG[:event_limit] : nil)
101105
else
102106
return unless notify_empty
103107
target.notice("There are no upcoming CTF's in the next #{config[:lookahead]}\n")

0 commit comments

Comments
 (0)