Skip to content

Commit

Permalink
Check if docker env and send diff revision text
Browse files Browse the repository at this point in the history
  • Loading branch information
No767 committed Jan 3, 2024
1 parent 8414ae5 commit 5bf6879
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
10 changes: 8 additions & 2 deletions bot/cogs/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
import pygit2
from discord.ext import commands
from discord.utils import format_dt
from libs.utils import Embed, RoboContext, human_timedelta
from libs.utils import Embed, RoboContext, human_timedelta, is_docker

from rodhaj import Rodhaj


Expand Down Expand Up @@ -78,6 +79,11 @@ async def about(self, ctx: RoboContext) -> None:
cpu_usage = self.process.cpu_percent() / psutil.cpu_count()

revisions = self.get_last_commits()
revision_text = f"\n\nLatest Changes:\n {revisions}"
if is_docker():
revision_text = (
"\n\nSee [GitHub](https://github.com/transprogrammer/rodhaj)"
)
footer_text = (
"Developed by Noelle and the Transprogrammer dev team\n"
f"Made with discord.py v{discord.__version__} | Running Python {platform.python_version()}"
Expand All @@ -90,7 +96,7 @@ async def about(self, ctx: RoboContext) -> None:
"the transprogrammer community. By creating a shared inbox, "
"it allows for users and staff to seamlessly communicate safely, securely, and privately. "
"In order to start using Rodhaj, please DM Rodhaj to make a ticket. "
f"\n\nLatest Changes:\n {revisions}"
f"{revision_text}"
)
embed.set_footer(
text=footer_text,
Expand Down
1 change: 1 addition & 0 deletions bot/libs/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .checks import (
is_admin as is_admin,
is_docker as is_docker,
is_manager as is_manager,
is_mod as is_mod,
)
Expand Down
14 changes: 14 additions & 0 deletions bot/libs/utils/checks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import os
from typing import Callable, TypeVar

from discord import app_commands
Expand Down Expand Up @@ -50,3 +51,16 @@ def is_mod():

def is_admin():
return hybrid_permissions_check(administrator=True)


def is_docker() -> bool:
"""Checks if the current environment is running in Docker
Returns:
bool: Returns `True` if in fact it is an Docker environment,
`False` if not
"""
path = "/proc/self/cgroup"
return os.path.exists("/.dockerenv") or (
os.path.isfile(path) and any("docker" in line for line in open(path))
)

0 comments on commit 5bf6879

Please sign in to comment.