Skip to content

Commit e670e78

Browse files
committed
Add configuration option to allow all users to access the CTF after archiving
1 parent af7984a commit e670e78

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The only required variable is `DISCORD_TOKEN`, the rest will use the default val
1717
| `LOGGING_FORMAT` | `%(asctime)s:%(levelname)s:%(name)s: %(message)s` | Logging format, see [here](https://docs.python.org/3/library/logging.html#formatter-objects) |
1818
| `LOGGING_FILE` | | If enabled, will send logging to this file |
1919
| `LOGGING_DISCORD_LEVEL` | `ERROR` | The minimum level for logging into the logging channel (`CHANNEL_LOGGING_ID`) |
20+
| `ARCHIVE_ACCESS_TO_ALL_USERS` | `false` | Should all the users in the Discord Server gain access to the CTF channels when the CTF is archived? Set to `true` if so. |
2021
| `COMMAND_PREFIX` | `!` | Prefix for all the bot commands (i.e. `!done`) |
2122
| `MAINTAINERS` | | Comma-separated list with profile IDs of the bot maintainers, these users have permission to export and delete CTFs |
2223
| `GUILD_IDS` | | Comma-separated list with guild IDs of where the bot should run. Used for executing CTF channel cleanup manually |

bot/config.py

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ def parse_variable(variable, default=None, valid=None):
55
value = os.getenv(variable, None)
66
if default and valid and variable not in valid:
77
return default
8+
elif isinstance(default, bool):
9+
return True if value.lower() in ["true", "1", "t", "y", "yes"] else False
810
elif isinstance(default, int):
911
return int(value) if value and value.isdigit() else default
1012
else:
@@ -48,6 +50,8 @@ def parse_int_list(variable):
4850
"logging_file": parse_variable("LOGGING_FILE"),
4951
# The minimum level for logging into the logging channel (`CHANNEL_LOGGING_ID`)
5052
"logging_discord_level": parse_variable("LOGGING_DISCORD_LEVEL", "ERROR"),
53+
# Should all the users in the Discord Server gain access to the CTF channels when the CTF is archived? Set to `true` if so.
54+
"archive_access_to_all_users": parse_variable("ARCHIVE_ACCESS_TO_ALL_USERS", False),
5155
# Prefix for all the bot commands
5256
"prefix": parse_variable("COMMAND_PREFIX", "!"),
5357
# Profile ids of the maintainers of your installation. These will be messaged when running `!report "issue"` or `!request "feature"`

bot/ctf_model.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,10 @@ async def archive(self):
333333

334334
# Archive all challenge channels
335335
main_chan = guild.get_channel(cid)
336-
# await main_chan.set_permissions(guild.default_role, overwrite=basic_read_send)
336+
if config["archive_access_to_all_users"]:
337+
await main_chan.set_permissions(
338+
guild.default_role, overwrite=basic_read_send
339+
)
337340
category_archives[-1]["channels"] -= 1
338341

339342
for i, d in enumerate(category_archives):
@@ -566,7 +569,10 @@ async def _archive(self, catg_archive):
566569
channel = guild.get_channel(cid)
567570
if channel is not None:
568571
await channel.edit(category=catg_archive)
569-
# await channel.set_permissions(guild.default_role, overwrite=basic_read_send)
572+
if config["archive_access_to_all_users"]:
573+
await channel.set_permissions(
574+
guild.default_role, overwrite=basic_read_send
575+
)
570576
self.refresh()
571577
else:
572578
raise ValueError(f"Couldn't find channel {cid}")

docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ services:
1111
- "LOGGING_FORMAT=${LOGGING_FORMAT:-%(asctime)s:%(levelname)s:%(name)s: %(message)s}"
1212
- "LOGGING_FILE=${LOGGING_FILE}"
1313
- "LOGGING_DISCORD_LEVEL=${LOGGING_DISCORD_LEVEL:-ERROR}"
14+
- "ARCHIVE_ACCESS_TO_ALL_USERS=${ARCHIVE_ACCESS_TO_ALL_USERS:-false}"
1415
- "COMMAND_PREFIX=${COMMAND_PREFIX:-!}"
1516
- "MAINTAINERS=${MAINTAINERS}"
1617
- "GUILD_IDS=${GUILD_IDS}"

0 commit comments

Comments
 (0)