Skip to content

Commit

Permalink
Version 2.0!
Browse files Browse the repository at this point in the history
Upgrade to version 2.0 for new features, bug fixes, and improved stability. In this version we have automated some important processes.

- Added
	- New navigation bar added to the GUI.
	- Now you can see the status of the framework from the logs viewer.
	- New MSEL Viewer! You can now load a MSEL in JSON format to check every inject's detail.
	- Automatic Environment creation, starting from this version you can automatically create the exercise's environment.

- Updated
	- Updated documentation to match all the functions, features, classes and odules of version 2.0.

- Fixed
	- The communication between the SSE client and server was poorly performed, which generated an infinite loop every 3 seconds.
  • Loading branch information
lanfranB4 committed May 5, 2023
1 parent 3d513f5 commit be2fc20
Show file tree
Hide file tree
Showing 31 changed files with 2,155 additions and 343 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
# Change Log
All notable changes to this project will be documented in this file.

## [2.0] - 2023-05-05

Upgrade to version 2.0 for new features, bug fixes, and improved stability. In this version we have automated some important processes.

### Added
- New navigation bar added to the GUI.
- Now you can see the status of the framework from the logs viewer.
- New MSEL Viewer! You can now load a MSEL in JSON format to check every inject's detail.
- Automatic Environment creation, starting from this version you can automatically create the exercise's environment.

### Updated
- Updated documentation to match all the functions, features, classes and odules of version 2.0.

### Fixed
- The communication between the SSE client and server was poorly performed, which generated an infinite loop every 3 seconds.

## [1.2] - 2023-04-05

Official release of v1.2 - New features, bug fixes, and stability improvements included!
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ To do this, you can follow this simple step-by-step guide, or if you're already

```bash
# Python 3.6+ required
python -m venv .venv # We will create a python virtual enviroment
python -m venv .venv # We will create a python virtual environment
source .venv/bin/activate # Let's get inside it

pip install -U pip # Upgrade pip
Expand Down
9 changes: 4 additions & 5 deletions T3SF/T3SF.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, bot = None, app = None, platform = None):
self.ch_names_list = []
self.players_list = []
self.platform = platform.lower()
self.guild_id = None

try:
if os.path.isfile(os.getcwd() + f"/inboxes_{self.platform}.json"):
Expand Down Expand Up @@ -103,17 +104,16 @@ def IncidentsFetcher(self, MSEL:str):
if player not in self.players_list:
self.players_list.append(player)
T3SF_Logger.emit(message="We have the inboxes right now", message_type="DEBUG")
return True
T3SF_Logger.emit(message="Incidents ready", message_type="DEBUG")
return self.players_list
else:
raise RuntimeError("Please set a method to retrieve the TTXs with the argument `MSEL` inside the `start` function.")

T3SF_Logger.emit(message="Incidents ready", message_type="DEBUG")

async def start(MSEL:str, platform, gui=False):
if gui == True:
T3SF_Logger.emit(message="Starting GUI", message_type="DEBUG")
gui_module = importlib.import_module("T3SF.gui.core")
gui_module.GUI(platform_run=platform)
gui_module.GUI(platform_run=platform, MSEL=MSEL)

if platform.lower() == "slack":
bot_module = importlib.import_module("T3SF.slack.bot")
Expand Down Expand Up @@ -372,7 +372,6 @@ async def SendMessage(self,
self.response = await Slack.SendMessage(self=self.slack, channel = channel, title=title, description=description, color=color, image=image, author=author, buttons=buttons, text_input=text_input, checkboxes=checkboxes)
return self.response


async def EditMessage(self,
color=None,
style:str="simple",
Expand Down
144 changes: 139 additions & 5 deletions T3SF/discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
intents.message_content = True
bot_discord = commands.Bot(command_prefix='!', intents=intents)

# Defining global variables and events
T3SF_instance = None
start_incidents_gui = asyncio.Event()
create_env = asyncio.Event()
config_MSEL = None

class create_bot():
def __init__(self, MSEL):
global config_MSEL
Expand Down Expand Up @@ -70,10 +71,10 @@ async def start_bot():
T3SF_instance = T3SF.T3SF(platform="discord", bot=bot_discord)
task1 = asyncio.create_task(bot_discord.start(TOKEN))
task2 = asyncio.create_task(async_handler_exercise())
task3 = asyncio.create_task(create_environment_task())

# wait for the coroutines to finish
await asyncio.gather(task1, task2)

await asyncio.gather(task1, task2, task3)

async def async_handler_exercise():
global T3SF_instance
Expand All @@ -84,9 +85,142 @@ async def async_handler_exercise():
pass
else:
T3SF_instance = T3SF.T3SF(platform="discord", bot=bot_discord)
T3SF_instance.guild_id = server_id
asyncio.create_task(T3SF_instance.ProcessIncidents(MSEL = config_MSEL, function_type="start", ctx=None))

start_incidents_gui.clear()

async def run_async_incidents():
start_incidents_gui.set()
async def run_async_incidents(server):
global server_id
server_id = server
start_incidents_gui.set()

async def create_environment(server):
global server_id
server_id = server
create_env.set()

async def create_environment_task():
global T3SF_instance
while True:
try:
await asyncio.wait_for(create_env.wait(), timeout=0.1)
except asyncio.TimeoutError:
pass
else:
create_env.clear()

T3SF_instance = T3SF.T3SF(platform="discord", bot=bot_discord)
areas_msel = T3SF_instance.IncidentsFetcher(MSEL = config_MSEL)

# Set the GUILD To the user's input server
guild = bot_discord.get_guild(int(server_id))

inbox_name = "inbox"
extra_chnls = ['chat','decision-log']
players_list_local = areas_msel

await create_gm_channels(guild=guild)

for player in players_list_local:

player_normalized = player.lower().replace(" ", "-")

role = await create_role_if_not_exists(guild=guild, name=player_normalized)

if role:
category_name = "Group - " + player
category = await create_category_if_not_exists(guild=guild, name=category_name, private=True, role=role)

if category:
await create_channel_if_not_exists(category=category, name=inbox_name)
T3SF.T3SF_Logger.emit(message=f'Player [{player}] - Channel {inbox_name} created', message_type="DEBUG")

for channel in extra_chnls:
await create_channel_if_not_exists(category=category, name=channel)
T3SF.T3SF_Logger.emit(message=f'Player [{player}] - Channel {channel} created', message_type="DEBUG")

await create_voice_if_not_exists(category=category, name="office")
T3SF.T3SF_Logger.emit(message=f'Player [{player}] - Voice Channel created', message_type="DEBUG")

T3SF.T3SF_Logger.emit(message=f"Player's Channels created!", message_type="INFO")

async def create_role_if_not_exists(guild, name):
try:
role = discord.utils.get(guild.roles, name=name)

if role is None:
general = discord.Permissions(view_channel=True)
text = discord.Permissions.text()
voice = discord.Permissions.voice()
role = await guild.create_role(name=name, permissions=general | text | voice, colour=discord.Colour.red())
return role
else:
return role

except Exception as e:
print(e)
raise

async def create_category_if_not_exists(guild, name, private=False, role=None):
try:
category = discord.utils.get(guild.categories, name=name)

if category is None:
category = await guild.create_category(name)

if private:
await category.set_permissions(guild.default_role, read_messages=False)
await category.set_permissions(role, read_messages=True)

return category
else:
return category

except Exception as e:
print(e)
raise

async def create_channel_if_not_exists(category, name):
try:
channel = discord.utils.get(category.channels, name=name)
if channel is None:
channel = await category.create_text_channel(name)
return channel
else:
return channel
except Exception as e:
print(e)
raise

async def create_voice_if_not_exists(category, name):
try:
channel = discord.utils.get(category.channels, name=name)
if channel is None:
channel = await category.create_voice_channel(name)
return channel
else:
return channel
except Exception as e:
print(e)
raise

async def create_gm_channels(guild):

role = discord.utils.get(guild.roles, name="Game Master")

if role is None:
all_perms = discord.Permissions.all()
role = await guild.create_role(name="Game Master", permissions=all_perms, colour=discord.Colour.green())

category = await create_category_if_not_exists(guild=guild, name="Control Room", private=True, role=role)
channels = ['chat','logs']

for channel in channels:
await create_channel_if_not_exists(category=category, name=channel)

await create_voice_if_not_exists(category=category, name="Game Masters")

T3SF.T3SF_Logger.emit(message=f'Game Master channels created.', message_type="INFO")

return True
5 changes: 4 additions & 1 deletion T3SF/discord/discord.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ async def InboxesAuto(self, T3SF_instance):

if T3SF_instance.fetch_inboxes == True:
if T3SF_instance._ctx == None:
channels = self.bot.get_all_channels()
# Exercise started from the GUI
guild = self.bot.get_guild(int(T3SF_instance.guild_id))
channels = guild.text_channels

for channel in channels:
if "chat" in channel.name:
Expand All @@ -35,6 +37,7 @@ async def InboxesAuto(self, T3SF_instance):
channels = T3SF_instance._ctx.message.guild.channels
categories = T3SF_instance._ctx.message.guild.categories
started_from_gui = False

except Exception:
channels = T3SF_instance._ctx.guild.channels
categories = T3SF_instance._ctx.guild.categories
Expand Down
Loading

0 comments on commit be2fc20

Please sign in to comment.